Translations¶
system.getLocale() returns the radio's UI language ("en", "fr", "de", ...). The name of a widget, tool, task or source can be a function, so Ethos can show a translated name:
local NAMES = { en = "Battery", fr = "Batterie", de = "Akku" }
local function name()
return NAMES[system.getLocale()] or NAMES.en
end
system.registerWidget({ key = "batt", name = name, create = create, paint = paint })
A small translation helper¶
For more than a handful of strings, keep one file per language and load only the active one. Every unused language you load costs RAM.
scripts/mywidget/
├── main.lua
└── i18n/
├── en.lua return { title = "Battery", low = "Low battery", cells = "Cells" }
└── fr.lua return { title = "Batterie", low = "Batterie faible" }
local BASE = "SCRIPTS:/mywidget/" -- absolute: T() runs from callbacks
local strings, fallback
local function loadLang(lang)
local chunk = loadfile(BASE .. "i18n/" .. lang .. ".lua")
return chunk and chunk() or nil
end
local function T(key)
if not strings then
fallback = loadLang("en") or {}
strings = loadLang(system.getLocale()) or fallback
end
return strings[key] or fallback[key] or key
end
-- usage
lcd.drawText(0, 0, T("low"))
- Load lazily, on first use, and only the current language plus the English fallback.
- Missing keys fall back to English, then to the key itself, so a missing translation is visible but harmless.
- Translate text once when building forms or layouts. In
paint, use the strings you already looked up.
Audio in the pilot's language¶
Spoken numbers from system.playNumber already use the radio's voice language. For your own .wav files, see Audio.