Add files via upload
Added support for translations using either MT v.50+ built in translations, (disabled by default), or use intllib mod or included template file. Add settingstype to enable/disable builtin translations or mod based translations. Added intllib.lua template file.
This commit is contained in:
parent
3c9e248e14
commit
e7b58ec381
138
init.lua
138
init.lua
@ -1,61 +1,93 @@
|
|||||||
|
|
||||||
lib_trm = {}
|
lib_trm = {}
|
||||||
lib_trm.name = "lib_trm"
|
lib_trm.name = "lib_trm"
|
||||||
lib_trm.ver_max = 0
|
lib_trm.ver_max = 0
|
||||||
lib_trm.ver_min = 1
|
lib_trm.ver_min = 1
|
||||||
lib_trm.ver_rev = 0
|
lib_trm.ver_rev = 0
|
||||||
lib_trm.ver_str = lib_trm.ver_max .. "." .. lib_trm.ver_min .. "." .. lib_trm.ver_rev
|
lib_trm.ver_str = lib_trm.ver_max .. "." .. lib_trm.ver_min .. "." .. lib_trm.ver_rev
|
||||||
lib_trm.authorship = "lisacvuk, davidthecreator, shadmordre"
|
lib_trm.authorship = "lisacvuk, davidthecreator, shadmordre"
|
||||||
lib_trm.license = "LGLv2.1"
|
lib_trm.license = "LGLv2.1"
|
||||||
lib_trm.copyright = "2019"
|
lib_trm.copyright = "2019"
|
||||||
lib_trm.path_mod = minetest.get_modpath(minetest.get_current_modname())
|
lib_trm.path_mod = minetest.get_modpath(minetest.get_current_modname())
|
||||||
lib_trm.path_world = minetest.get_worldpath()
|
lib_trm.path_world = minetest.get_worldpath()
|
||||||
|
|
||||||
|
lib_trm.intllib = minetest.setting_get("lib_trm_engine_translation") or false
|
||||||
|
|
||||||
|
local S
|
||||||
|
local NS
|
||||||
|
if not lib_trm.intllib then
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
S = intllib.Getter()
|
||||||
|
else
|
||||||
|
-- S = function(s) return s end
|
||||||
|
-- internationalization boilerplate
|
||||||
|
S, NS = dofile(lib_trm.path_mod.."/intllib.lua")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
S = minetest.get_translator(lib_trm.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log(S("[MOD] lib_trm: Loading..."))
|
||||||
|
minetest.log(S("[MOD] lib_trm: Version:") .. S(lib_trm.ver_str))
|
||||||
|
minetest.log(S("[MOD] lib_trm: Legal Info: Copyright ") .. S(lib_trm.copyright) .. " " .. S(lib_trm.authorship) .. "")
|
||||||
|
minetest.log(S("[MOD] lib_trm: License: ") .. S(lib_trm.license) .. "")
|
||||||
|
|
||||||
lib_trm.intllib = minetest.get_translator(lib_trm.name)
|
--minetest.log("[MOD] lib_trm: Loading...")
|
||||||
local S = lib_trm.intllib
|
--minetest.log("[MOD] lib_trm: Version:" .. lib_trm.ver_str)
|
||||||
|
--minetest.log("[MOD] lib_trm: Legal Info: Copyright " .. lib_trm.copyright .. " " ..lib_trm.authorship) .. "")
|
||||||
--minetest.log(S("[MOD] lib_trm: Loading..."))
|
--minetest.log("[MOD] lib_trm: License: " .. lib_trm.license .. "")
|
||||||
--minetest.log(S("[MOD] lib_trm: Legal Info: Copyright " .. lib_trm.copyright .. " " ..lib_trm.authorship .. ""))
|
|
||||||
--minetest.log(S("[MOD] lib_trm: License: " .. lib_trm.license .. ""))
|
|
||||||
|
|
||||||
|
|
||||||
minetest.log("[MOD] lib_trm: Loading...")
|
|
||||||
minetest.log("[MOD] lib_trm: Version:" .. lib_trm.ver_str)
|
|
||||||
minetest.log("[MOD] lib_trm: Legal Info: Copyright " .. lib_trm.copyright .. " " ..lib_trm.authorship .. "")
|
|
||||||
minetest.log("[MOD] lib_trm: License: " .. lib_trm.license .. "")
|
|
||||||
|
|
||||||
|
|
||||||
dofile(lib_trm.path_mod.."/lib_trm_toolcap_modifier.lua")
|
|
||||||
dofile(lib_trm.path_mod.."/lib_trm_tool_ranks.lua")
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_on_mods_loaded(function()
|
|
||||||
for node_name, node_def in pairs(minetest.registered_tools) do
|
|
||||||
if node_name and node_name ~= "" then
|
|
||||||
if node_def then
|
|
||||||
if not node_def.original_description then
|
|
||||||
local node_desc = node_def.description
|
|
||||||
minetest.override_item(node_name, {
|
|
||||||
original_description = node_desc,
|
|
||||||
description = toolranks.create_description(node_desc, 0, 1),
|
|
||||||
after_use = toolranks.new_afteruse,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dofile(lib_trm.path_mod.."/lib_trm_toolcap_modifier.lua")
|
||||||
|
dofile(lib_trm.path_mod.."/lib_trm_tool_ranks.lua")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_on_mods_loaded(function()
|
||||||
|
for node_name, node_def in pairs(minetest.registered_tools) do
|
||||||
|
if node_name and node_name ~= "" then
|
||||||
|
if node_def then
|
||||||
|
if not node_def.original_description then
|
||||||
|
local node_desc = node_def.description
|
||||||
|
minetest.override_item(node_name, {
|
||||||
|
original_description = node_desc,
|
||||||
|
description = toolranks.create_description(node_desc, 0, 1),
|
||||||
|
after_use = toolranks.new_afteruse,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
minetest.log(S("[MOD] lib_trm: Successfully loaded."))
|
minetest.log(S("[MOD] lib_trm: Successfully loaded."))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
45
intllib.lua
Normal file
45
intllib.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
-- Fallback functions for when `intllib` is not installed.
|
||||||
|
-- Code released under Unlicense <http://unlicense.org>.
|
||||||
|
|
||||||
|
-- Get the latest version of this file at:
|
||||||
|
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
|
||||||
|
|
||||||
|
local function format(str, ...)
|
||||||
|
local args = { ... }
|
||||||
|
local function repl(escape, open, num, close)
|
||||||
|
if escape == "" then
|
||||||
|
local replacement = tostring(args[tonumber(num)])
|
||||||
|
if open == "" then
|
||||||
|
replacement = replacement..close
|
||||||
|
end
|
||||||
|
return replacement
|
||||||
|
else
|
||||||
|
return "@"..open..num..close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
|
||||||
|
end
|
||||||
|
|
||||||
|
local gettext, ngettext
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
if intllib.make_gettext_pair then
|
||||||
|
-- New method using gettext.
|
||||||
|
gettext, ngettext = intllib.make_gettext_pair()
|
||||||
|
else
|
||||||
|
-- Old method using text files.
|
||||||
|
gettext = intllib.Getter()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fill in missing functions.
|
||||||
|
|
||||||
|
gettext = gettext or function(msgid, ...)
|
||||||
|
return format(msgid, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
|
||||||
|
return format(n==1 and msgid or msgid_plural, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return gettext, ngettext
|
2
mod.conf
2
mod.conf
@ -1,4 +1,4 @@
|
|||||||
name=lib_trm
|
name=lib_trm
|
||||||
description=Combines Tool Ranks (toolranks) and Crafted Tools Modifiers (ctm) into a single working mod.
|
description=Combines Tool Ranks (toolranks) and Crafted Tools Modifiers (ctm) into a single working mod.
|
||||||
depends=
|
depends=
|
||||||
optional_depends=
|
optional_depends=intllib
|
8
settingtypes.txt
Normal file
8
settingtypes.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#lib_trm settings
|
||||||
|
|
||||||
|
|
||||||
|
#If enabled, will use MT v5.0+ built in translation system. Disable will use intllib, mod provided intllib, or none, in that order. Defaults to false.
|
||||||
|
lib_trm_engine_translation (If true, will use the MT v5.0+ built in translation system. Disable will use intllib, mod provided intllib, or none, in that order. Defaults to false. true/false) bool false
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user