From 62cba232e53b039414835e5dc03222fbe5bd6796 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Wed, 14 Jan 2009 23:48:51 +0000 Subject: [PATCH] Automatic language detection --- libs/web/luasrc/dispatcher.lua | 13 ++++++++++++- libs/web/root/etc/config/luci | 2 +- .../luasrc/model/cbi/admin_index/luci.lua | 1 + 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 5f450eb5e1..c0d8b98c28 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 0178f6c281..207b962d6f 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 9a0282f3a7..20d50cceb5 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 819a9b64d3..9eea8715ed 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 -- 2.30.2