2015-01-16 22:38:38 +00:00
|
|
|
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
|
|
|
-- Licensed to the public under the Apache License 2.0.
|
2008-03-02 21:52:58 +00:00
|
|
|
|
2008-05-25 17:00:30 +00:00
|
|
|
module("luci.i18n", package.seeall)
|
2008-08-06 20:20:40 +00:00
|
|
|
require("luci.util")
|
2012-11-25 19:17:55 +00:00
|
|
|
|
|
|
|
local tparser = require "luci.template.parser"
|
2008-03-02 21:52:58 +00:00
|
|
|
|
|
|
|
table = {}
|
2008-08-06 20:20:40 +00:00
|
|
|
i18ndir = luci.util.libpath() .. "/i18n/"
|
2008-05-31 13:57:30 +00:00
|
|
|
loaded = {}
|
2008-06-14 14:12:12 +00:00
|
|
|
context = luci.util.threadlocal()
|
|
|
|
default = "en"
|
2008-03-02 21:52:58 +00:00
|
|
|
|
|
|
|
function clear()
|
|
|
|
end
|
|
|
|
|
2008-06-14 14:12:12 +00:00
|
|
|
function load(file, lang, force)
|
2008-03-02 21:52:58 +00:00
|
|
|
end
|
|
|
|
|
2008-07-29 20:32:02 +00:00
|
|
|
-- Alternatively load the translation of the fallback language.
|
2008-06-01 12:12:18 +00:00
|
|
|
function loadc(file, force)
|
2008-06-14 14:12:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function setlanguage(lang)
|
2009-05-28 00:24:04 +00:00
|
|
|
context.lang = lang:gsub("_", "-")
|
|
|
|
context.parent = (context.lang:match("^([a-z][a-z])_"))
|
2012-11-25 19:17:55 +00:00
|
|
|
if not tparser.load_catalog(context.lang, i18ndir) then
|
|
|
|
if context.parent then
|
|
|
|
tparser.load_catalog(context.parent, i18ndir)
|
2012-12-02 13:30:46 +00:00
|
|
|
return context.parent
|
2012-11-25 19:17:55 +00:00
|
|
|
end
|
|
|
|
end
|
2012-12-02 13:30:46 +00:00
|
|
|
return context.lang
|
2008-03-02 21:52:58 +00:00
|
|
|
end
|
|
|
|
|
2009-10-31 15:42:07 +00:00
|
|
|
function translate(key)
|
2012-11-25 19:17:55 +00:00
|
|
|
return tparser.translate(key) or key
|
2008-05-25 15:55:39 +00:00
|
|
|
end
|
|
|
|
|
2009-10-31 15:42:07 +00:00
|
|
|
function translatef(key, ...)
|
|
|
|
return tostring(translate(key)):format(...)
|
2008-10-05 16:08:33 +00:00
|
|
|
end
|
2009-07-26 22:48:09 +00:00
|
|
|
|
|
|
|
-- and ensure that the returned value is a Lua string value.
|
|
|
|
-- This is the same as calling <code>tostring(translate(...))</code>
|
2009-10-31 15:42:07 +00:00
|
|
|
function string(key)
|
|
|
|
return tostring(translate(key))
|
2009-07-26 22:48:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Ensure that the returned value is a Lua string value.
|
|
|
|
-- This is the same as calling <code>tostring(translatef(...))</code>
|
2009-10-31 15:42:07 +00:00
|
|
|
function stringf(key, ...)
|
|
|
|
return tostring(translate(key)):format(...)
|
2009-07-26 22:48:09 +00:00
|
|
|
end
|