From db7e02af1a8e674934ce6646516e25f5a2b88aca Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sat, 11 Jun 2016 09:47:43 +0100 Subject: [PATCH] added intllib support (en/de) --- api.lua | 53 +++++++++++++++++++++++++++++++-------------- crafts.lua | 16 ++++++++------ depends.txt | 1 + locale/de.txt | 38 ++++++++++++++++++++++++++++++++ locale/template.txt | 36 ++++++++++++++++++++++++++++++ spawner.lua | 16 +++++++++----- 6 files changed, 131 insertions(+), 29 deletions(-) create mode 100644 locale/de.txt create mode 100644 locale/template.txt diff --git a/api.lua b/api.lua index 742fba9..945f781 100644 --- a/api.lua +++ b/api.lua @@ -4,8 +4,29 @@ mobs = {} mobs.mod = "redo" --- Invisibility mod +-- Intllib +local S +if minetest.get_modpath("intllib") then + S = intllib.Getter() +else + S = function(s, a, ...) + if a == nil then + return s + end + a = {a, ...} + return s:gsub("(@?)@(%(?)(%d+)(%)?)", + function(e, o, n, c) + if e == "" then + return a[tonumber(n)] .. (o == "" and c or "") + else + return "@" .. o .. n .. c + end + end) + end +end +mobs.intllib = S +-- Invisibility mod local invisibility = invisibility or {} -- Load settings @@ -1769,7 +1790,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) -- error checking when mod profiling is enabled if not tool_capabilities then - print ("[MOBS] mod profiling enabled, damage not enabled") + print (S("[MOBS] mod profiling enabled, damage not enabled")) return end @@ -2079,7 +2100,7 @@ local mob_step = function(self, dtime) end minetest.log("action", - "lifetimer expired, removed " .. self.name) + S("lifetimer expired, removed @1", self.name)) effect(pos, 15, "tnt_smoke.png") @@ -2336,13 +2357,13 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, if new_chance ~= nil then if new_chance == 0 then - print("[Mobs Redo] " .. name .. " has spawning disabled") + print(S("[Mobs Redo] @1 has spawning disabled", name)) return end chance = new_chance - print ("[Mobs Redo] Chance setting for " .. name .. " changed to " .. chance) + print (S("[Mobs Redo] Chance setting for @1 changed to @2", name, chance)) end @@ -2430,8 +2451,8 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, -- .. minetest.pos_to_string(pos) .. " on " -- .. node.name .. " near " .. neighbors[1]) else - print ("[mobs]" .. name .. " failed to spawn at " - .. minetest.pos_to_string(pos)) + print (S("[mobs] @1 failed to spawn at @2", + name, minetest.pos_to_string(pos))) end end @@ -2711,7 +2732,7 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, if self.tamed == false and force_take == false then - minetest.chat_send_player(name, "Not tamed!") + minetest.chat_send_player(name, S("Not tamed!")) return end @@ -2720,7 +2741,7 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, if self.owner ~= name and force_take == false then - minetest.chat_send_player(name, self.owner.." is owner!") + minetest.chat_send_player(name, S("@1 is owner!", self.owner)) return end @@ -2761,7 +2782,7 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, self.object:remove() else - minetest.chat_send_player(name, "Missed!") + minetest.chat_send_player(name, S("Missed!")) end end end @@ -2800,8 +2821,8 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame) if self.htimer < 1 then minetest.chat_send_player(clicker:get_player_name(), - self.name:split(":")[2] - .. " at full health (" .. tostring(self.health) .. ")") + S("@1 at full health (@2)", + self.name:split(":")[2], tostring(self.health))) self.htimer = 5 end @@ -2835,8 +2856,8 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame) if self.tamed == false then minetest.chat_send_player(clicker:get_player_name(), - self.name:split(":")[2] - .. " has been tamed!") + S("@1 has been tamed!", + self.name:split(":")[2])) end self.tamed = true @@ -2876,8 +2897,8 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame) minetest.show_formspec(name, "mobs_nametag", "size[8,4]" .. default.gui_bg .. default.gui_bg_img - .. "field[0.5,1;7.5,0;name;Enter name:;" .. tag .. "]" - .. "button_exit[2.5,3.5;3,1;mob_rename;Rename]") + .. "field[0.5,1;7.5,0;name;" .. S("Enter name:") .. ";" .. tag .. "]" + .. "button_exit[2.5,3.5;3,1;mob_rename;" .. S("Rename") .. "]") end diff --git a/crafts.lua b/crafts.lua index 176ff7b..15521ef 100644 --- a/crafts.lua +++ b/crafts.lua @@ -1,7 +1,9 @@ +local S = mobs.intllib + -- name tag minetest.register_craftitem("mobs:nametag", { - description = "Nametag", + description = S("Nametag"), inventory_image = "mobs_nametag.png", }) @@ -13,20 +15,20 @@ core.register_craft({ -- leather minetest.register_craftitem("mobs:leather", { - description = "Leather", + description = S("Leather"), inventory_image = "mobs_leather.png", }) -- raw meat minetest.register_craftitem("mobs:meat_raw", { - description = "Raw Meat", + description = S("Raw Meat"), inventory_image = "mobs_meat_raw.png", on_use = minetest.item_eat(3), }) -- cooked meat minetest.register_craftitem("mobs:meat", { - description = "Meat", + description = S("Meat"), inventory_image = "mobs_meat.png", on_use = minetest.item_eat(8), }) @@ -40,7 +42,7 @@ minetest.register_craft({ -- golden lasso minetest.register_tool("mobs:magic_lasso", { - description = "Magic Lasso (right-click animal to put in inventory)", + description = S("Magic Lasso (right-click animal to put in inventory)"), inventory_image = "mobs_magic_lasso.png", }) @@ -55,7 +57,7 @@ minetest.register_craft({ -- net minetest.register_tool("mobs:net", { - description = "Net (right-click animal to put in inventory)", + description = S("Net (right-click animal to put in inventory)"), inventory_image = "mobs_net.png", }) @@ -70,7 +72,7 @@ minetest.register_craft({ -- shears (right click to shear animal) minetest.register_tool("mobs:shears", { - description = "Steel Shears (right-click to shear)", + description = S("Steel Shears (right-click to shear)"), inventory_image = "mobs_shears.png", }) diff --git a/depends.txt b/depends.txt index 04581de..2631f61 100644 --- a/depends.txt +++ b/depends.txt @@ -1,2 +1,3 @@ default invisibility? +intllib? diff --git a/locale/de.txt b/locale/de.txt new file mode 100644 index 0000000..aa7a7a7 --- /dev/null +++ b/locale/de.txt @@ -0,0 +1,38 @@ +# German Translation for mobs_redo mod +# Deutsche Übersetzung der mobs_redo Mod +# last update: 2016/June/10 +# Author: Xanthin + +#init.lua +[MOD] Mobs Redo loaded = [MOD] Mobs Redo geladen + +#api.lua +[MOBS] mod profiling enabled, damage not enabled = [MOBS] Modanalyse aktiviert, Schaden deaktiviert +lifetimer expired, removed @1 = Lebensdauer abgelaufen, @1 wurde entfernt +[Mobs Redo] @1 has spawning disabled = [Mobs Redo] Spawnen von @1 ist deaktiviert +[Mobs Redo] Chance setting for @1 is now @2 = [Mobs Redo] Wahrscheinlichkeitswert für @1 ist jetzt @2 +[mobs] @1 failed to spawn at @2 = [mobs] @1 konnte nicht bei @2 spawnen +Not tamed! = Nicht gezähmt! +@1 is owner! = @1 ist Besitzer! +Missed! = Verfehlt! +@1 at full health (@2) = @1 bei voller Gesundheit (@2) +@1 has been tamed! = @1 ist gezähmt worden! +Enter name: = Namen eingeben: +Rename = Umbenennen + +#crafts.lua +Nametag = Namensschild +Leather = Leder +Raw Meat = Rohes Fleisch +Meat = Fleisch +Magic Lasso (right-click animal to put in inventory) = Magisches Lasso (Rechtsklick auf Tier,\num es ins Inventar zu legen) +Net (right-click animal to put in inventory) = Netz (Rechtsklick auf Tier,\num es ins Inventar zu legen) +Steel Shears (right-click to shear) = Stahlschere (Rechtsklick zum Scheren) + +#spawner.lua +Mob Spawner = Mobspawner +Mob MinLight MaxLight Amount PlayerDist = Mob MinLicht MaxLicht Menge SpielerEntfng +Spawner Not Active (enter settings) = Spawner nicht aktiv (Einstellungen eintragen) +Spawner Active (@1) = Spawner aktiv (@1) +Mob Spawner settings failed! = Mobspawnereinstellungen gescheitert! +> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10] = Name min. Licht[0-14] max. Licht[0-14] max. Mobs in Gebiet[0 zum deaktivieren] Entfernung zum Spieler[1-20] Höhe[-10 bis 10] \ No newline at end of file diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..c263ce9 --- /dev/null +++ b/locale/template.txt @@ -0,0 +1,36 @@ +# Template for translations of mobs_redo mod +# last update: 2016/June/10 + +#init.lua +[MOD] Mobs Redo loaded = + +#api.lua +[MOBS] mod profiling enabled, damage not enabled = +lifetimer expired, removed @1 = +[Mobs Redo] @1 has spawning disabled = +[Mobs Redo] Chance setting for @1 is now @2 = +[mobs] @1 failed to spawn at @2 = +Not tamed! = +@1 is owner! = +Missed! = +@1 at full health (@2) = +@1 has been tamed! = +Enter name: = +Rename = + +#crafts.lua +Nametag = +Leather = +Raw Meat = +Meat = +Magic Lasso (right-click animal to put in inventory) = +Net (right-click animal to put in inventory) = +Steel Shears (right-click to shear) = + +#spawner.lua +Mob Spawner = +Mob MinLight MaxLight Amount PlayerDist = +Spawner Not Active (enter settings) = +Spawner Active (@1) = +Mob Spawner settings failed! = +> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10] = \ No newline at end of file diff --git a/spawner.lua b/spawner.lua index 4d30303..cb7cd16 100644 --- a/spawner.lua +++ b/spawner.lua @@ -1,4 +1,6 @@ +local S = mobs.intllib + -- mob spawner local spawner_default = "mobs_animal:pumba 10 15 0 0" @@ -8,7 +10,7 @@ minetest.register_node("mobs:spawner", { drawtype = "glasslike", paramtype = "light", walkable = true, - description = "Mob Spawner", + description = S("Mob Spawner"), groups = {cracky = 1}, on_construct = function(pos) @@ -16,8 +18,9 @@ minetest.register_node("mobs:spawner", { local meta = minetest.get_meta(pos) -- text entry formspec - meta:set_string("formspec", "field[text;Mob MinLight MaxLight Amount PlayerDist;${command}]") - meta:set_string("infotext", "Spawner Not Active (enter settings)") + meta:set_string("formspec", + "field[text;" .. S("Mob MinLight MaxLight Amount PlayerDist") .. ";${command}]") + meta:set_string("infotext", S("Spawner Not Active (enter settings)")) meta:set_string("command", spawner_default) end, @@ -58,11 +61,12 @@ minetest.register_node("mobs:spawner", { and yof and yof > -10 and yof < 10 then meta:set_string("command", fields.text) - meta:set_string("infotext", "Spawner Active (" .. mob .. ")") + meta:set_string("infotext", S("Spawner Active (@1)", mob)) else - minetest.chat_send_player(name, "Mob Spawner settings failed!") - minetest.chat_send_player(name, "> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10]") + minetest.chat_send_player(name, S("Mob Spawner settings failed!")) + minetest.chat_send_player(name, + S("> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10]")) end end, })