Automatic language detection
authorSteven Barth <steven@midlink.org>
Wed, 14 Jan 2009 23:48:51 +0000 (23:48 +0000)
committerSteven Barth <steven@midlink.org>
Wed, 14 Jan 2009 23:48:51 +0000 (23:48 +0000)
libs/web/luasrc/dispatcher.lua
libs/web/root/etc/config/luci
modules/admin-full/luasrc/model/cbi/admin_index/luci.lua
modules/admin-mini/luasrc/model/cbi/mini/luci.lua

index 5f450eb..c0d8b98 100644 (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
index 0178f6c..207b962 100644 (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
        
index 9a0282f..20d50cc 100644 (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
index 819a9b6..9eea871 100644 (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