projects
/
oweals
/
luci.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
* luci/libs: move time fix to luci-addons
[oweals/luci.git]
/
libs
/
web
/
luasrc
/
i18n.lua
diff --git
a/libs/web/luasrc/i18n.lua
b/libs/web/luasrc/i18n.lua
index 546429933b050067fd39138da53bb6b26e720328..35ad0965d0715ed01a8c8e914f70054b45733544 100644
(file)
--- a/
libs/web/luasrc/i18n.lua
+++ b/
libs/web/luasrc/i18n.lua
@@
-30,6
+30,8
@@
require("luci.sys")
table = {}
i18ndir = luci.sys.libpath() .. "/i18n/"
loaded = {}
table = {}
i18ndir = luci.sys.libpath() .. "/i18n/"
loaded = {}
+context = luci.util.threadlocal()
+default = "en"
-- Clears the translation table
function clear()
-- Clears the translation table
function clear()
@@
-37,13
+39,17
@@
function clear()
end
-- Loads a translation and copies its data into the global translation table
end
-- Loads a translation and copies its data into the global translation table
-function load(file, force)
- if force or not loaded[file] then
- local f = loadfile(i18ndir..file..".lua") or loadfile(i18ndir..file)
+function load(file, lang, force)
+ lang = lang or ""
+ if force or not loaded[lang] or not loaded[lang][file] then
+ local f = loadfile(i18ndir .. file .. "." .. lang .. ".lua")
+ or loadfile(i18ndir .. file .. "." .. lang)
if f then
if f then
- setfenv(f, table)
+ table[lang] = table[lang] or {}
+ setfenv(f, table[lang])
f()
f()
- loaded[file] = true
+ loaded[lang] = loaded[lang] or {}
+ loaded[lang][file] = true
return true
else
return false
return true
else
return false
@@
-55,12
+61,20
@@
end
-- Same as load but autocompletes the filename with .LANG from config.lang
function loadc(file, force)
-- Same as load but autocompletes the filename with .LANG from config.lang
function loadc(file, force)
- return load(file .. "." .. require("luci.config").main.lang, force)
+ load(file, default, force)
+ return load(file, context.lang, force)
+end
+
+-- Sets the context language
+function setlanguage(lang)
+ context.lang = lang
end
-- Returns the i18n-value defined by "key" or if there is no such: "default"
function translate(key, default)
end
-- Returns the i18n-value defined by "key" or if there is no such: "default"
function translate(key, default)
- return table[key] or default
+ return (table[context.lang] and table[context.lang][key])
+ or (table[default] and table[default][key])
+ or default
end
-- Translate shourtcut with sprintf/string.format inclusion
end
-- Translate shourtcut with sprintf/string.format inclusion