summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r--modules/luci-base/luasrc/i18n.lua28
-rw-r--r--modules/luci-base/luasrc/i18n.luadoc3
2 files changed, 24 insertions, 7 deletions
diff --git a/modules/luci-base/luasrc/i18n.lua b/modules/luci-base/luasrc/i18n.lua
index bcb16d5c04..968c387f12 100644
--- a/modules/luci-base/luasrc/i18n.lua
+++ b/modules/luci-base/luasrc/i18n.lua
@@ -23,15 +23,31 @@ function loadc(file, force)
end
function setlanguage(lang)
- context.lang = lang:gsub("_", "-")
- context.parent = (context.lang:match("^([a-z][a-z])_"))
- if not tparser.load_catalog(context.lang, i18ndir) then
- if context.parent then
- tparser.load_catalog(context.parent, i18ndir)
+ local code, subcode = lang:match("^([A-Za-z][A-Za-z])[%-_]([A-Za-z][A-Za-z])$")
+ if not (code and subcode) then
+ subcode = lang:match("^([A-Za-z][A-Za-z])$")
+ if not subcode then
+ return nil
+ end
+ end
+
+ context.parent = code and code:lower()
+ context.lang = context.parent and context.parent.."-"..subcode:lower() or subcode:lower()
+
+ if tparser.load_catalog(context.lang, i18ndir) and
+ tparser.change_catalog(context.lang)
+ then
+ return context.lang
+
+ elseif context.parent then
+ if tparser.load_catalog(context.parent, i18ndir) and
+ tparser.change_catalog(context.parent)
+ then
return context.parent
end
end
- return context.lang
+
+ return nil
end
function translate(key)
diff --git a/modules/luci-base/luasrc/i18n.luadoc b/modules/luci-base/luasrc/i18n.luadoc
index aa38841e17..13f10a1071 100644
--- a/modules/luci-base/luasrc/i18n.luadoc
+++ b/modules/luci-base/luasrc/i18n.luadoc
@@ -37,7 +37,8 @@ Set the context default translation language.
@class function
@name setlanguage
-@param lang Two-letter language code
+@param lang An IETF/BCP 47 language tag or ISO3166 country code, e.g. "en-US" or "de"
+@return The effective loaded language, e.g. "en" for "en-US" - or nil on failure
]]
---[[