2019-08-23 20:40:33 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2020-09-27 09:27:37 -04:00
|
|
|
local ipairs, minetest, nodecore, pairs, string, table, type
|
|
|
|
= ipairs, minetest, nodecore, pairs, string, table, type
|
|
|
|
local string_format, table_sort
|
|
|
|
= string.format, table.sort
|
2019-08-23 20:40:33 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
|
|
|
local strings = {}
|
|
|
|
local strings_dirty
|
|
|
|
|
2020-09-27 09:27:37 -04:00
|
|
|
local loadtimeover
|
|
|
|
minetest.register_on_mods_loaded(function() loadtimeover = true end)
|
|
|
|
|
2019-10-02 07:40:14 -04:00
|
|
|
local prefix = minetest.translate(modname, "x")
|
|
|
|
prefix = prefix:sub(1, prefix:find(modname) - 1)
|
2019-08-23 20:40:33 -04:00
|
|
|
|
2019-08-26 01:01:58 -04:00
|
|
|
function nodecore.translate_inform(str)
|
2019-08-23 20:40:33 -04:00
|
|
|
if (not str) or (type(str) ~= "string") or (#str < 1)
|
2019-08-26 01:01:58 -04:00
|
|
|
or (str:sub(1, #prefix) == prefix) then return end
|
2019-08-23 20:40:33 -04:00
|
|
|
|
|
|
|
if not strings[str] then
|
2020-09-27 09:27:37 -04:00
|
|
|
if loadtimeover then
|
|
|
|
nodecore.log("warning", string_format(
|
|
|
|
"Translation string informed late: %q",
|
|
|
|
str))
|
|
|
|
end
|
2019-08-23 20:40:33 -04:00
|
|
|
strings[str] = true
|
|
|
|
strings_dirty = true
|
|
|
|
end
|
|
|
|
|
2019-08-26 01:01:58 -04:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function nodecore.translate(str, ...)
|
|
|
|
if not nodecore.translate_inform(str) then return str end
|
2019-08-23 20:40:33 -04:00
|
|
|
return minetest.translate(modname, str, ...)
|
|
|
|
end
|
|
|
|
|
2020-04-20 08:15:53 -04:00
|
|
|
if nodecore.infodump() then
|
2020-06-15 07:21:39 -04:00
|
|
|
nodecore.register_globalstep("translate templates", function()
|
2020-04-20 08:15:53 -04:00
|
|
|
if not strings_dirty then return end
|
|
|
|
strings_dirty = nil
|
|
|
|
|
|
|
|
local keys = {}
|
|
|
|
for k in pairs(strings) do keys[#keys + 1] = k end
|
|
|
|
table_sort(keys)
|
|
|
|
|
|
|
|
local data = "# textdomain: " .. modname .. "\n"
|
|
|
|
for _, k in ipairs(keys) do
|
|
|
|
data = data .. k .. "=" .. "\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
local p = minetest.get_worldpath() .. "/" .. modname .. ".template.tr"
|
|
|
|
return minetest.safe_file_write(p, data)
|
|
|
|
end)
|
|
|
|
end
|