2019-08-23 20:40:33 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-08-23 21:18:14 -04:00
|
|
|
local ipairs, minetest, nodecore, pairs, table, type
|
|
|
|
= ipairs, minetest, nodecore, pairs, table, type
|
2019-08-23 20:40:33 -04:00
|
|
|
local table_sort
|
|
|
|
= table.sort
|
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
|
|
|
local strings = {}
|
|
|
|
local strings_dirty
|
|
|
|
|
2019-09-07 09:08:57 -04:00
|
|
|
local token = nodecore.product
|
2019-08-23 20:40:33 -04:00
|
|
|
local prefix = minetest.translate(modname, token)
|
|
|
|
prefix = prefix:sub(1, prefix:find(token) - 1)
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
minetest.register_globalstep(function()
|
2019-08-27 19:14:51 -04:00
|
|
|
if not strings_dirty then return end
|
|
|
|
strings_dirty = nil
|
2019-08-23 20:40:33 -04:00
|
|
|
|
2019-08-27 19:14:51 -04:00
|
|
|
local keys = {}
|
2019-08-31 09:26:53 -04:00
|
|
|
for k in pairs(strings) do keys[#keys + 1] = k end
|
2019-08-27 19:14:51 -04:00
|
|
|
table_sort(keys)
|
2019-08-23 20:40:33 -04:00
|
|
|
|
2019-08-27 19:14:51 -04:00
|
|
|
local data = "# textdomain: " .. modname .. "\n"
|
|
|
|
for _, k in ipairs(keys) do
|
|
|
|
data = data .. k .. "=" .. "\n"
|
|
|
|
end
|
2019-08-23 20:40:33 -04:00
|
|
|
|
2019-08-27 19:14:51 -04:00
|
|
|
local p = minetest.get_worldpath() .. "/" .. modname .. ".template.tr"
|
|
|
|
return minetest.safe_file_write(p, data)
|
|
|
|
end)
|