i18n.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. module("luci.i18n", package.seeall)
  4. require("luci.util")
  5. local tparser = require "luci.template.parser"
  6. table = {}
  7. i18ndir = luci.util.libpath() .. "/i18n/"
  8. loaded = {}
  9. context = luci.util.threadlocal()
  10. default = "en"
  11. function clear()
  12. end
  13. function load(file, lang, force)
  14. end
  15. -- Alternatively load the translation of the fallback language.
  16. function loadc(file, force)
  17. end
  18. function setlanguage(lang)
  19. context.lang = lang:gsub("_", "-")
  20. context.parent = (context.lang:match("^([a-z][a-z])_"))
  21. if not tparser.load_catalog(context.lang, i18ndir) then
  22. if context.parent then
  23. tparser.load_catalog(context.parent, i18ndir)
  24. return context.parent
  25. end
  26. end
  27. return context.lang
  28. end
  29. function translate(key)
  30. return tparser.translate(key) or key
  31. end
  32. function translatef(key, ...)
  33. return tostring(translate(key)):format(...)
  34. end
  35. -- and ensure that the returned value is a Lua string value.
  36. -- This is the same as calling <code>tostring(translate(...))</code>
  37. function string(key)
  38. return tostring(translate(key))
  39. end
  40. -- Ensure that the returned value is a Lua string value.
  41. -- This is the same as calling <code>tostring(translatef(...))</code>
  42. function stringf(key, ...)
  43. return tostring(translate(key)):format(...)
  44. end