Automatic language detection
This commit is contained in:
parent
d415e9ac42
commit
d0d1fe0a28
4 changed files with 15 additions and 2 deletions
|
@ -130,7 +130,18 @@ function dispatch(request)
|
||||||
ctx.path = request
|
ctx.path = request
|
||||||
ctx.urltoken = ctx.urltoken or {}
|
ctx.urltoken = ctx.urltoken or {}
|
||||||
|
|
||||||
require "luci.i18n".setlanguage(require "luci.config".main.lang)
|
local conf = require "luci.config"
|
||||||
|
local lang = conf.main.lang
|
||||||
|
if lang == "auto" then
|
||||||
|
local aclang = http.getenv("HTTP_ACCEPT_LANGUAGE") or ""
|
||||||
|
for lpat in aclang:gmatch("[%w]+") do
|
||||||
|
if conf.languages[lpat] then
|
||||||
|
lang = lpat
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
require "luci.i18n".setlanguage(lang)
|
||||||
|
|
||||||
local c = ctx.tree
|
local c = ctx.tree
|
||||||
local stat
|
local stat
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
config core main
|
config core main
|
||||||
option lang en
|
option lang auto
|
||||||
option mediaurlbase /luci-static/openwrt.org
|
option mediaurlbase /luci-static/openwrt.org
|
||||||
option resourcebase /luci-static/resources
|
option resourcebase /luci-static/resources
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ end
|
||||||
c = m:section(NamedSection, "main", "core", translate("general"))
|
c = m:section(NamedSection, "main", "core", translate("general"))
|
||||||
|
|
||||||
l = c:option(ListValue, "lang", translate("language"))
|
l = c:option(ListValue, "lang", translate("language"))
|
||||||
|
l:value("auto")
|
||||||
|
|
||||||
local i18ndir = luci.i18n.i18ndir .. "default."
|
local i18ndir = luci.i18n.i18ndir .. "default."
|
||||||
for k, v in pairs(luci.config.languages) do
|
for k, v in pairs(luci.config.languages) do
|
||||||
|
|
|
@ -25,6 +25,7 @@ end
|
||||||
c = m:section(NamedSection, "main", "core", translate("general"))
|
c = m:section(NamedSection, "main", "core", translate("general"))
|
||||||
|
|
||||||
l = c:option(ListValue, "lang", translate("language"))
|
l = c:option(ListValue, "lang", translate("language"))
|
||||||
|
l:value("auto")
|
||||||
|
|
||||||
local i18ndir = luci.i18n.i18ndir .. "default."
|
local i18ndir = luci.i18n.i18ndir .. "default."
|
||||||
for k, v in pairs(luci.config.languages) do
|
for k, v in pairs(luci.config.languages) do
|
||||||
|
|
Loading…
Reference in a new issue