Automatic language detection
authorSteven Barth <steven@midlink.org>
Wed, 14 Jan 2009 23:47:56 +0000 (23:47 +0000)
committerSteven Barth <steven@midlink.org>
Wed, 14 Jan 2009 23:47:56 +0000 (23:47 +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 5f450eb5e1caad2f6bac59f7792b4f3f8229448a..c0d8b98c28a1b32aa52ec17a1444845abb2673f4 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 0178f6c281f04c90eecf1a3788e5e276bd0c68d0..207b962d6f40777f3453af4ed7fc3725620584a7 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 9a0282f3a763b6ea37db73a01053392860ae4a10..20d50cceb5d452dd3b7049d58f43f6c499ababdc 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 819a9b64d3e1b8b0da8ae4768fae1e81f579ee1d..9eea8715ed312504d7281afefc3c317b4ef1c686 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