2.3 KiB
Localization
The web interface uses JSON language packs from lang/. Language files are discovered at Rust build time and embedded in the application binary.
English (lang/en.json) is required and is always the fallback language. Polish (lang/pl.json) is included by default.
Add a language
- Copy
lang/en.jsonto a file named with the new language code, for examplelang/de.json. - Update the
metaobject. - Translate values inside
translations. Do not rename translation keys. - Run
./scripts/dev.sh --checkor build the project again. - Start the rebuilt binary. The new language appears automatically in the language selector.
Example structure:
{
"meta": {
"code": "de",
"name": "German",
"native_name": "Deutsch",
"locale": "de-DE"
},
"translations": {
"controls.language": "Sprache",
"controls.theme": "Darstellung"
}
}
The filename and meta.code must match (de.json -> "code": "de"). File names may contain ASCII letters, digits, - and _ only.
Fallback behavior
A language pack does not have to duplicate every English key while it is being developed. If a key is missing from the selected language, the UI uses the value from en.json. If a key is also missing from English, the translation key itself is shown, which makes incomplete strings visible during development.
Build-time validation
build.rs checks that:
- at least one JSON language file exists,
en.jsonexists,- every language file contains valid JSON,
- every file has
meta.code,meta.name,meta.native_nameandmeta.locale, meta.codematches the filename,translationsis a JSON object.
A malformed language pack fails the Rust build instead of producing a broken selector at runtime.
Runtime endpoints
The embedded language catalog is available at:
GET /lang/index.json
Individual embedded packs are available at:
GET /lang/en.json
GET /lang/pl.json
GET /lang/<code>.json
These endpoints are intentionally public so that localization also works before API authentication is completed.
Browser preference
The selected language code is stored for one year in the gree_controller_language cookie. If the stored language is no longer present in a later build, the UI falls back to English.