From 179364ff8f6e6b7e0361b0b5a85a51d463644515 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sun, 30 Mar 2014 19:32:13 -0400 Subject: [PATCH] Add translation support to technic_chests --- technic_chests/depends.txt | 1 + technic_chests/gold_chest.lua | 17 ------- technic_chests/locale/template.txt | 33 ++++++++++++++ technic_chests/register.lua | 71 ++++++++++++++++++++---------- 4 files changed, 81 insertions(+), 41 deletions(-) create mode 100644 technic_chests/locale/template.txt diff --git a/technic_chests/depends.txt b/technic_chests/depends.txt index d5cf46a..8009e56 100644 --- a/technic_chests/depends.txt +++ b/technic_chests/depends.txt @@ -2,4 +2,5 @@ default technic moreores pipeworks +intllib? diff --git a/technic_chests/gold_chest.lua b/technic_chests/gold_chest.lua index 7ba3f48..71aadb0 100644 --- a/technic_chests/gold_chest.lua +++ b/technic_chests/gold_chest.lua @@ -1,20 +1,3 @@ -local chest_mark_colors = { - 'Black', - 'Blue', - 'Brown', - 'Cyan', - 'Dark Green', - 'Dark Grey', - 'Green', - 'Grey', - 'Magenta', - 'Orange', - 'Pink', - 'Red', - 'Violet', - 'White', - 'Yellow', -} minetest.register_craft({ output = 'technic:gold_chest', diff --git a/technic_chests/locale/template.txt b/technic_chests/locale/template.txt new file mode 100644 index 0000000..f320251 --- /dev/null +++ b/technic_chests/locale/template.txt @@ -0,0 +1,33 @@ +# technic_chests translation template + +%s Chest = +%s Locked Chest = +%s Locked Chest (owned by %s) = +Color Filter: %s = +Edit chest description: = + +# Colors +Black = +Blue = +Brown = +Byan = +Dark Green = +Dark Grey = +Green = +Grey = +Magenta = +Orange = +Pink = +Red = +Violet = +White = +Yellow = +None = + +# Materials +Copper = +Gold = +Iron = +Mithril = +Silver = + diff --git a/technic_chests/register.lua b/technic_chests/register.lua index 797c652..3092f14 100644 --- a/technic_chests/register.lua +++ b/technic_chests/register.lua @@ -1,25 +1,33 @@ + +local S +if intllib then + S = intllib.Getter() +else + S = function(s) return s end +end + local chest_mark_colors = { - 'Black', - 'Blue', - 'Brown', - 'Cyan', - 'Dark Green', - 'Dark Grey', - 'Green', - 'Grey', - 'Magenta', - 'Orange', - 'Pink', - 'Red', - 'Violet', - 'White', - 'Yellow', + {"black", S("Black")}, + {"blue", S("Blue")}, + {"brown", S("Brown")}, + {"cyan", S("Byan")}, + {"dark_green", S("Dark Green")}, + {"dark_grey", S("Dark Grey")}, + {"green", S("Green")}, + {"grey", S("Grey")}, + {"magenta", S("Magenta")}, + {"orange", S("Orange")}, + {"pink", S("Pink")}, + {"red", S("Red")}, + {"violet", S("Violet")}, + {"white", S("White")}, + {"yellow", S("Yellow")}, } local function colorid_to_postfix(id) - return (chest_mark_colors[id] and "_"..chest_mark_colors[id] or ""):lower():gsub(" ", "_") + return chest_mark_colors[id] and "_"..chest_mark_colors[id][1] or "" end @@ -42,7 +50,7 @@ local function check_color_buttons(pos, meta, chest_name, fields) for i = 1, 16 do if fields["color_button"..i] then technic.swap_node(pos, chest_name..colorid_to_postfix(i)) - meta:set_string("color", chest_mark_colors[i]) + meta:set_string("color", i) return end end @@ -75,15 +83,21 @@ local function get_receive_fields(name, data) formspec = formspec.."image_button[2.1,0.1;0.8,0.8;" .."technic_checkmark_icon.png;save_infotext;]" .."field[3.3,0.2;4.8,1;" - .."infotext_box;Edit chest description:;" + .."infotext_box;"..S("Edit chest description:")..";" ..formspec_infotext.."]" end if data.color then -- This sets the node local nn = "technic:"..lname..(data.locked and "_locked" or "").."_chest" check_color_buttons(pos, meta, nn, fields) - local color = meta:get_string("color") - formspec = formspec.."label[8.2,9;Color Filter: "..color.."]" + local colorID = meta:get_int("color") + local colorName + if chest_mark_colors[colorID] then + colorName = chest_mark_colors[colorID][2] + else + colorName = S("None") + end + formspec = formspec.."label[8.2,9;"..S("Color Filter: %s"):format(colorName).."]" end meta:set_string("formspec", formspec) end @@ -92,6 +106,7 @@ end function technic.chests:register(name, data) local lname = name:lower() + name = S(name) local width = math.max(data.color and 11 or 8, data.width) @@ -112,14 +127,22 @@ function technic.chests:register(name, data) locked_after_place = function(pos, placer) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name() or "") - meta:set_string("infotext", name.." Locked Chest (owned by ".. - meta:get_string("owner")..")") + meta:set_string("infotext", + S("%s Locked Chest (owned by %s)") + :format(name, meta:get_string("owner"))) end table.insert(front, "technic_"..lname.."_chest_lock_overlay.png") end + local desc + if data.locked then + desc = S("%s Locked Chest"):format(name) + else + desc = S("%s Chest"):format(name) + end + local def = { - description = name..(data.locked and " Locked" or "").." Chest", + description = desc, tiles = {"technic_"..lname.."_chest_top.png", "technic_"..lname.."_chest_top.png", "technic_"..lname.."_chest_side.png", "technic_"..lname.."_chest_side.png", "technic_"..lname.."_chest_side.png", table.concat(front, "^")}, @@ -135,7 +158,7 @@ function technic.chests:register(name, data) ..(data.color and "label[8.2,9;Color Filter: None" or "") ..(data.infotext and "image_button[2.1,0.1;0.8,0.8;" .."technic_pencil_icon.png;edit_infotext;]" or "")) - meta:set_string("infotext", name.." Chest") + meta:set_string("infotext", S("%s Chest"):format(name)) local inv = meta:get_inventory() inv:set_size("main", data.width * 4) end,