1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local tparser = require "luci.template.parser"
5 local util = require "luci.util"
6 local tostring = tostring
10 i18ndir = util.libpath() .. "/i18n/"
11 context = util.threadlocal()
15 function setlanguage(lang)
16 local code, subcode = lang:match("^([A-Za-z][A-Za-z])[%-_]([A-Za-z][A-Za-z])$")
17 if not (code and subcode) then
18 subcode = lang:match("^([A-Za-z][A-Za-z])$")
24 context.parent = code and code:lower()
25 context.lang = context.parent and context.parent.."-"..subcode:lower() or subcode:lower()
27 if tparser.load_catalog(context.lang, i18ndir) and
28 tparser.change_catalog(context.lang)
32 elseif context.parent then
33 if tparser.load_catalog(context.parent, i18ndir) and
34 tparser.change_catalog(context.parent)
43 function translate(key)
44 return tparser.translate(key) or key
47 function translatef(key, ...)
48 return tostring(translate(key)):format(...)
53 tparser.get_translations(function(k, v) rv[k] = v end)