modules: add m-i18n

Add simple gettext i18n module.

Add Lua script API functions I18n.gettext, I18n.ngettext.
This commit is contained in:
Pauli Virtanen
2022-04-09 13:43:53 +03:00
parent f8e7b39c25
commit bbe9ac00f3
7 changed files with 155 additions and 0 deletions

View File

@@ -186,6 +186,29 @@ local Feature = {
},
}
local I18n = {
gettext = function (msgid)
local i18n = WpPlugin.find("i18n")
if i18n then
return i18n:call("gettext", msgid)
else
return msgid
end
end,
ngettext = function (msgid, msgid_plural, n)
local i18n = WpPlugin.find("i18n")
if i18n then
return i18n:call("ngettext", msgid, msgid_plural, n)
else
if n == 1 then
return msgid
else
return msgid_plural
end
end
end
}
SANDBOX_EXPORT = {
Debug = Debug,
Id = Id,
@@ -209,4 +232,5 @@ SANDBOX_EXPORT = {
State = WpState_new,
LocalModule = WpImplModule_new,
ImplMetadata = WpImplMetadata_new,
I18n = I18n
}