1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.i18n", package.seeall)
7 local tparser = require "luci.template.parser"
10 i18ndir = luci.util.libpath() .. "/i18n/"
12 context = luci.util.threadlocal()
18 function load(file, lang, force)
21 -- Alternatively load the translation of the fallback language.
22 function loadc(file, force)
25 function setlanguage(lang)
26 context.lang = lang:gsub("_", "-")
27 context.parent = (context.lang:match("^([a-z][a-z])_"))
28 if not tparser.load_catalog(context.lang, i18ndir) then
29 if context.parent then
30 tparser.load_catalog(context.parent, i18ndir)
37 function translate(key)
38 return tparser.translate(key) or key
41 function translatef(key, ...)
42 return tostring(translate(key)):format(...)
45 -- and ensure that the returned value is a Lua string value.
46 -- This is the same as calling <code>tostring(translate(...))</code>
48 return tostring(translate(key))
51 -- Ensure that the returned value is a Lua string value.
52 -- This is the same as calling <code>tostring(translatef(...))</code>
53 function stringf(key, ...)
54 return tostring(translate(key)):format(...)