diff options
author | Steven Barth <steven@midlink.org> | 2009-01-14 23:47:56 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-01-14 23:47:56 +0000 |
commit | d0d1fe0a28c5dcd5ffe62c59fde634dda2b5f1cd (patch) | |
tree | 2c0741ce91c03c1fc5caf2a8549cb3ceda4dbd92 | |
parent | d415e9ac42e23ce2c0784be0e092205ec82c78df (diff) |
Automatic language detection
-rw-r--r-- | libs/web/luasrc/dispatcher.lua | 13 | ||||
-rw-r--r-- | libs/web/root/etc/config/luci | 2 | ||||
-rw-r--r-- | modules/admin-full/luasrc/model/cbi/admin_index/luci.lua | 1 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/luci.lua | 1 |
4 files changed, 15 insertions, 2 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 5f450eb5e..c0d8b98c2 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -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 diff --git a/libs/web/root/etc/config/luci b/libs/web/root/etc/config/luci index 0178f6c28..207b962d6 100644 --- a/libs/web/root/etc/config/luci +++ b/libs/web/root/etc/config/luci @@ -1,5 +1,5 @@ config core main - option lang en + option lang auto option mediaurlbase /luci-static/openwrt.org option resourcebase /luci-static/resources diff --git a/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua b/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua index 9a0282f3a..20d50cceb 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua @@ -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 diff --git a/modules/admin-mini/luasrc/model/cbi/mini/luci.lua b/modules/admin-mini/luasrc/model/cbi/mini/luci.lua index 819a9b64d..9eea8715e 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/luci.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/luci.lua @@ -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 |