diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-28 00:24:04 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-28 00:24:04 +0000 |
commit | 2bd86ec208521b48a79710d4be798a5ac25ebb4e (patch) | |
tree | 3d099cb3959e5602a4eb438934baca648764c4e8 /libs/web/luasrc | |
parent | f20034cd8251ec676d24365c6d1eb1bcfd440028 (diff) |
libs/web: if current language is a regional dialect, fall back to generic language, then english (e.g. pt_BR -> pt -> en)
Diffstat (limited to 'libs/web/luasrc')
-rw-r--r-- | libs/web/luasrc/i18n.lua | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/libs/web/luasrc/i18n.lua b/libs/web/luasrc/i18n.lua index 4db9c3343..082a60078 100644 --- a/libs/web/luasrc/i18n.lua +++ b/libs/web/luasrc/i18n.lua @@ -71,13 +71,15 @@ end -- @param force Force reload even if already loaded (optional) function loadc(file, force) load(file, default, force) + if context.parent then load(file, context.parent, force) end return load(file, context.lang, force) end --- Set the context default translation language. -- @param lang Two-letter language code function setlanguage(lang) - context.lang = lang:gsub("_", "-") + context.lang = lang:gsub("_", "-") + context.parent = (context.lang:match("^([a-z][a-z])_")) end --- Return the translated value for a specific translation key. @@ -86,6 +88,7 @@ end -- @return Translated string function translate(key, def) return (table[context.lang] and table[context.lang][key]) + or (table[context.parent] and table[context.parent][key]) or (table[default] and table[default][key]) or def end |