From 511b09c29b14e3703baa4d050c02be9293d72445 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Tue, 27 Jul 2021 14:32:08 -0700 Subject: [PATCH] Add localization support using Minetest's built-in translator... Breaks compatibility with Minetest 0.4. --- init.lua | 23 +++++++++++++++-------- locale/template.txt | 16 ++++++++++++++++ mod.conf | 2 +- rainbow_armor.lua | 12 ++++++++---- rainbow_shield.lua | 6 +++++- 5 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 locale/template.txt diff --git a/init.lua b/init.lua index cdd7013..aec80b9 100644 --- a/init.lua +++ b/init.lua @@ -1,17 +1,24 @@ -- Rainbow_Ore Test Mod ----------- Copyright Robin Kuhn 2015 +rainbow_ore = {} +rainbow_ore.modname = minetest.get_current_modname() +rainbow_ore.modpath = minetest.get_modpath(rainbow_ore.modname) + --Check for mods if minetest.get_modpath("3d_armor") then -dofile(minetest.get_modpath("rainbow_ore").."/rainbow_armor.lua") +dofile(rainbow_ore.modpath.."/rainbow_armor.lua") end if minetest.get_modpath("shields") then -dofile(minetest.get_modpath("rainbow_ore").."/rainbow_shield.lua") +dofile(rainbow_ore.modpath.."/rainbow_shield.lua") end + +local S = minetest.get_translator(rainbow_ore.modname) + -- Define Rainbow_Ore_Block node minetest.register_node("rainbow_ore:rainbow_ore_block", { - description = "Rainbow Ore", + description = S("Rainbow Ore"), tiles = {"rainbow_ore_block.png"}, groups = {stone=2, cracky=3}, drop = "rainbow_ore:rainbow_ore_block", @@ -21,7 +28,7 @@ minetest.register_node("rainbow_ore:rainbow_ore_block", { --Define Rainbow_Ore_Ingot node minetest.register_craftitem("rainbow_ore:rainbow_ore_ingot", { - description = "Rainbow Ore Ingot", + description = S("Rainbow Ore Ingot"), inventory_image = "rainbow_ore_ingot.png", }) @@ -36,7 +43,7 @@ minetest.register_craft({ --Register Rainbow Pickaxe minetest.register_tool("rainbow_ore:rainbow_ore_pickaxe", { - description = "Rainbow Pickaxe", + description = S("Rainbow Pickaxe"), inventory_image = "rainbow_ore_pickaxe.png", tool_capabilities = { full_punch_interval = 0.9, @@ -62,7 +69,7 @@ minetest.register_craft({ --Register Rainbow Axe minetest.register_tool("rainbow_ore:rainbow_ore_axe", { - description = "Rainbow Axe", + description = S("Rainbow Axe"), inventory_image = "rainbow_ore_axe.png", tool_capabilities = { full_punch_interval = 0.9, @@ -97,7 +104,7 @@ minetest.register_craft({ --Register Rainbow shovel minetest.register_tool("rainbow_ore:rainbow_ore_shovel", { - description = "Rainbow Shovel", + description = S("Rainbow Shovel"), inventory_image = "rainbow_ore_shovel.png", wield_image = "rainbow_ore_shovel.png^[transformR90", tool_capabilities = { @@ -124,7 +131,7 @@ minetest.register_craft({ --Register Rainbow sword minetest.register_tool("rainbow_ore:rainbow_ore_sword", { - description = "Rainbow Sword", + description = S("Rainbow Sword"), inventory_image = "rainbow_ore_sword.png", tool_capabilities = { full_punch_interval = 0.7, diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..7c8959b --- /dev/null +++ b/locale/template.txt @@ -0,0 +1,16 @@ +# textdomain:rainbow_ore + +# Translators: + + +Rainbow Ore= +Rainbow Ore Ingot= +Rainbow Pickaxe= +Rainbow Axe= +Rainbow Shovel= +Rainbow Sword= +Rainbow Helmet= +Rainbow Chestplate= +Rainbow Leggings= +Rainbow Boots= +Rainbow Shield= diff --git a/mod.conf b/mod.conf index 8a64b1c..d7070fc 100644 --- a/mod.conf +++ b/mod.conf @@ -3,6 +3,6 @@ title = Rainbow Ore description = Rainbow materials & equipment. author = Robin Kuhn (KingSmarty) license = LGPL -min_minetest_version = 0.4.16 +min_minetest_version = 5.0 depends = default optional_depends = 3d_armor, shields diff --git a/rainbow_armor.lua b/rainbow_armor.lua index b02dc39..02882e6 100644 --- a/rainbow_armor.lua +++ b/rainbow_armor.lua @@ -1,24 +1,28 @@ + +local S = minetest.get_translator(rainbow_ore.modname) + + --Define Rainbow Armor minetest.register_tool("rainbow_ore:rainbow_ore_helmet", { - description = "Rainbow Helmet", + description = S("Rainbow Helmet"), inventory_image = "rainbow_ore_helmet_inv.png", groups = {armor_head=20, armor_heal=17, armor_use=40}, wear = 0, }) minetest.register_tool("rainbow_ore:rainbow_ore_chestplate", { - description = "Rainbow Chestplate", + description = S("Rainbow Chestplate"), inventory_image = "rainbow_ore_chestplate_inv.png", groups = {armor_torso=25, armor_heal=17, armor_use=40}, wear = 0, }) minetest.register_tool("rainbow_ore:rainbow_ore_leggings", { - description = "Rainbow Leggings", + description = S("Rainbow Leggings"), inventory_image = "rainbow_ore_leggings_inv.png", groups = {armor_legs=25, armor_heal=17, armor_use=40}, wear = 0, }) minetest.register_tool("rainbow_ore:rainbow_ore_boots", { - description = "Rainbow Boots", + description = S("Rainbow Boots"), inventory_image = "rainbow_ore_boots_inv.png", groups = {armor_feet=20, armor_heal=17, armor_use=40}, wear = 0, diff --git a/rainbow_shield.lua b/rainbow_shield.lua index 0c1a0bd..11c8201 100644 --- a/rainbow_shield.lua +++ b/rainbow_shield.lua @@ -1,6 +1,10 @@ + +local S = minetest.get_translator(rainbow_ore.modname) + + --Define Rainbow shield minetest.register_tool("rainbow_ore:rainbow_ore_shield", { - description = "Rainbow Shield", + description = S("Rainbow Shield"), inventory_image = "rainbow_ore_shield_inv.png", groups = {armor_shield=20, armor_heal=17, armor_use=40, armor_fire=1}, wear = 0,