Automatic language detection

This commit is contained in:
Steven Barth 2009-01-14 23:48:51 +00:00
parent 5407471378
commit 62cba232e5
4 changed files with 15 additions and 2 deletions

View file

@ -130,7 +130,18 @@ function dispatch(request)
ctx.path = request
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 stat

View file

@ -1,5 +1,5 @@
config core main
option lang en
option lang auto
option mediaurlbase /luci-static/openwrt.org
option resourcebase /luci-static/resources

View file

@ -25,6 +25,7 @@ end
c = m:section(NamedSection, "main", "core", translate("general"))
l = c:option(ListValue, "lang", translate("language"))
l:value("auto")
local i18ndir = luci.i18n.i18ndir .. "default."
for k, v in pairs(luci.config.languages) do

View file

@ -25,6 +25,7 @@ end
c = m:section(NamedSection, "main", "core", translate("general"))
l = c:option(ListValue, "lang", translate("language"))
l:value("auto")
local i18ndir = luci.i18n.i18ndir .. "default."
for k, v in pairs(luci.config.languages) do