mirror of
https://github.com/minetest-mods/intllib.git
synced 2025-01-23 16:30:18 +01:00
Add get_strings()
This commit is contained in:
parent
4be14170e7
commit
3a3da7359c
14
init.lua
14
init.lua
@ -16,6 +16,8 @@ LANG = LANG:sub(1, 2)
|
|||||||
-- Support the old multi-load method
|
-- Support the old multi-load method
|
||||||
intllib.getters = intllib.getters or {}
|
intllib.getters = intllib.getters or {}
|
||||||
|
|
||||||
|
intllib.strings = {}
|
||||||
|
|
||||||
local function noop_getter(s)
|
local function noop_getter(s)
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
@ -27,6 +29,7 @@ function intllib.Getter(modname)
|
|||||||
if modpath then
|
if modpath then
|
||||||
local filename = modpath.."/locale/"..LANG..".txt"
|
local filename = modpath.."/locale/"..LANG..".txt"
|
||||||
local msgstr = intllib.load_strings(filename)
|
local msgstr = intllib.load_strings(filename)
|
||||||
|
intllib.strings[modname] = msgstr or false
|
||||||
if msgstr then
|
if msgstr then
|
||||||
intllib.getters[modname] = function (s)
|
intllib.getters[modname] = function (s)
|
||||||
if msgstr[s] and msgstr[s] ~= "" then
|
if msgstr[s] and msgstr[s] ~= "" then
|
||||||
@ -42,3 +45,14 @@ function intllib.Getter(modname)
|
|||||||
return intllib.getters[modname]
|
return intllib.getters[modname]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function intllib.get_strings(modname)
|
||||||
|
modname = modname or minetest.get_current_modname()
|
||||||
|
local msgstr = intllib.strings[modname]
|
||||||
|
if msgstr == nil then
|
||||||
|
local modpath = minetest.get_modpath(modname)
|
||||||
|
msgstr = intllib.load_strings(modpath.."/locale/"..LANG..".txt")
|
||||||
|
intllib.strings[modname] = msgstr
|
||||||
|
end
|
||||||
|
return msgstr or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user