From ba2bdf83684e92bc344a4d3c25548db673ab6130 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 28 Apr 2024 18:41:52 +0200 Subject: [PATCH] technic_cnc: Use client-side translation API (#636) --- technic_cnc/cnc.lua | 12 +- technic_cnc/cnc_materials.lua | 168 ++++++++------------------- technic_cnc/init.lua | 16 +-- technic_cnc/locale/de.txt | 36 ------ technic_cnc/locale/technic_cnc.de.tr | 50 ++++++++ technic_cnc/locale/template.txt | 84 ++++++++------ 6 files changed, 156 insertions(+), 210 deletions(-) delete mode 100644 technic_cnc/locale/de.txt create mode 100644 technic_cnc/locale/technic_cnc.de.tr diff --git a/technic_cnc/cnc.lua b/technic_cnc/cnc.lua index 2f28264..c032fcf 100644 --- a/technic_cnc/cnc.lua +++ b/technic_cnc/cnc.lua @@ -29,7 +29,7 @@ if technic_cnc.use_technic then allow_metadata_inventory_take = technic.machine_inventory_take allow_metadata_inventory_move = technic.machine_inventory_move can_dig = technic.machine_can_dig - desc_tr = S("%s CNC Machine"):format("LV") + desc_tr = S("@1 CNC Machine", S("LV")) else minetest.register_craft({ output = 'technic:cnc', @@ -130,9 +130,9 @@ local cnc_formspec = "image_button[5,4;1,1;technic_cnc_element_t.png;element_t; ]".. "image_button[6,4;1,1;technic_cnc_element_edge.png;element_edge; ]".. - "label[0, 5.5;"..S("In:").."]".. + "label[0, 5;"..S("In:").."]".. "list[current_name;src;0.5,5.5;1,1;]".. - "label[4, 5.5;"..S("Out:").."]".. + "label[4, 5;"..S("Out:").."]".. "list[current_name;dst;5,5.5;4,1;]".. "list[current_player;main;0,7;8,4;]".. @@ -221,7 +221,7 @@ local run = function(pos, node) (not minetest.registered_nodes[result]) or (not inv:room_for_item("dst", result)) then technic.swap_node(pos, machine_node) - meta:set_string("infotext", S("%s Idle"):format(machine_name)) + meta:set_string("infotext", S("@1 Idle", machine_name)) meta:set_string("cnc_product", "") meta:set_int("LV_EU_demand", 0) return @@ -229,10 +229,10 @@ local run = function(pos, node) if eu_input < demand then technic.swap_node(pos, machine_node) - meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) + meta:set_string("infotext", S("@1 Unpowered", machine_name)) elseif eu_input >= demand then technic.swap_node(pos, machine_node.."_active") - meta:set_string("infotext", S("%s Active"):format(machine_name)) + meta:set_string("infotext", S("@1 Active", machine_name)) meta:set_int("src_time", meta:get_int("src_time") + 1) if meta:get_int("src_time") >= 3 then -- 3 ticks per output meta:set_int("src_time", 0) diff --git a/technic_cnc/cnc_materials.lua b/technic_cnc/cnc_materials.lua index e63c792..c20187c 100644 --- a/technic_cnc/cnc_materials.lua +++ b/technic_cnc/cnc_materials.lua @@ -3,129 +3,61 @@ local S = technic_cnc.getter --- DIRT -------- -technic_cnc.register_all("default:dirt", - {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, - {"default_dirt.png"}, - S("Dirt")) --- (DIRT WITH) GRASS --------------------- -technic_cnc.register_all("default:dirt_with_grass", - {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, - {"default_grass.png"}, - S("Grassy dirt")) --- WOOD -------- -technic_cnc.register_all("default:wood", - {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1}, - {"default_wood.png"}, - S("Wooden")) --- STONE --------- -technic_cnc.register_all("default:stone", - {cracky=3, not_in_creative_inventory=1}, - {"default_stone.png"}, - S("Stone")) --- COBBLE ---------- -technic_cnc.register_all("default:cobble", - {cracky=3, not_in_creative_inventory=1}, - {"default_cobble.png"}, - S("Cobble")) --- BRICK --------- -technic_cnc.register_all("default:brick", - {cracky=3, not_in_creative_inventory=1}, - {"default_brick.png"}, - S("Brick")) +local function register_material(nodename, tiles_override, descr_override) + local ndef = minetest.registered_nodes[nodename] + if not ndef then + return + end --- SANDSTONE ------------- -technic_cnc.register_all("default:sandstone", - {crumbly=2, cracky=3, not_in_creative_inventory=1}, - {"default_sandstone.png"}, - S("Sandstone")) + local groups = { + crumbly = ndef.groups.crumbly, + choppy = ndef.groups.choppy, + flammable = ndef.groups.flammable, + level = ndef.groups.level, + snappy = ndef.groups.snappy, + wood = ndef.groups.wood, + oddly_breakable_by_hand = ndef.groups.oddly_breakable_by_hand, + not_in_creative_inventory = 1, + } + local tiles = tiles_override or { ndef.tiles[#ndef.tiles] } + assert(tiles and #tiles == 1, "Unknown tile format in node name=" .. nodename) --- LEAVES ---------- -technic_cnc.register_all("default:leaves", - {snappy=2, choppy=2, oddly_breakable_by_hand=3, not_in_creative_inventory=1}, - {"default_leaves.png"}, - S("Leaves")) --- TREE -------- -technic_cnc.register_all("default:tree", - {snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3, wood=1, not_in_creative_inventory=1}, - {"default_tree.png"}, - S("Tree")) - --- Bronze --------- -technic_cnc.register_all("default:bronzeblock", - {cracky=1, level=2, not_in_creative_inventory=1}, - {"default_bronze_block.png"}, - S("Bronze")) - - -local steeltex = "default_steel_block.png" -local steelname = "Steel" - -if technic_cnc.technic_modpath then - steeltex = "technic_wrought_iron_block.png" - steelname = "Wrought Iron" - - -- Stainless Steel - -------- - technic_cnc.register_all("technic:stainless_steel_block", - {cracky=1, level=2, not_in_creative_inventory=1}, - {"technic_stainless_steel_block.png"}, - S("Stainless Steel")) - - -- Marble - ------------ - technic_cnc.register_all("technic:marble", - {cracky=3, not_in_creative_inventory=1}, - {"technic_marble.png"}, - S("Marble")) - - -- Granite - ------------ - technic_cnc.register_all("technic:granite", - {cracky=1, not_in_creative_inventory=1}, - {"technic_granite.png"}, - S("Granite")) - - -- Blast-resistant concrete - --------------------------- - - technic_cnc.register_all("technic:blast_resistant_concrete", - {cracky=2, level=2, not_in_creative_inventory=1}, - {"technic_blast_resistant_concrete_block.png"}, - S("Blast-resistant concrete")) + technic_cnc.register_all(nodename, + groups, + tiles, + descr_override or ndef.description or "" + ) end --- STEEL ---------------- -technic_cnc.register_all("default:steelblock", - {cracky=1, level=2, not_in_creative_inventory=1}, - {steeltex}, - S(steelname)) +register_material("default:dirt") +register_material("default:dirt_with_grass", {"default_grass.png"}, S("Grassy dirt")) +register_material("default:wood", nil, S("Wooden")) +register_material("default:stone") +register_material("default:cobble") +register_material("default:sandstone") +register_material("default:leaves") +register_material("default:tree") +register_material("default:bronzeblock", nil, S("Bronze")) + +local steelname = S("Steel") + +if technic_cnc.technic_modpath then + steelname = S("Wrought Iron") + + register_material("technic:stainless_steel_block", nil, S("Stainless Steel")) + register_material("technic:stainless_steel_block") + register_material("technic:marble") + register_material("technic:granite") + register_material("technic:blast_resistant_concrete") + register_material("technic:blast_resistant_concrete") +end + +register_material("default:steelblock", nil, steelname) + -- CONCRETE AND CEMENT ---------------------- -technic_cnc.register_all("basic_materials:concrete_block", - {cracky=2, level=2, not_in_creative_inventory=1}, - {"basic_materials_concrete_block.png"}, - S("Concrete")) - -technic_cnc.register_all("basic_materials:cement_block", - {cracky=2, level=2, not_in_creative_inventory=1}, - {"basic_materials_cement_block.png"}, - S("Cement")) - -technic_cnc.register_all("basic_materials:brass_block", - {cracky=1, level=2, not_in_creative_inventory=1}, - {"basic_materials_brass_block.png"}, - S("Brass block")) +register_material("basic_materials:concrete_block") +register_material("basic_materials:cement_block") +register_material("basic_materials:brass_block") diff --git a/technic_cnc/init.lua b/technic_cnc/init.lua index f1cb03b..3b33fe7 100644 --- a/technic_cnc/init.lua +++ b/technic_cnc/init.lua @@ -3,25 +3,11 @@ local modpath = minetest.get_modpath("technic_cnc") technic_cnc = {} technic_cnc.technic_modpath = minetest.get_modpath("technic") +technic_cnc.getter = minetest.get_translator("technic_cnc") technic_cnc.use_technic = technic_cnc.technic_modpath and minetest.settings:get_bool("technic_cnc_use_technic") ~= false -if rawget(_G, "intllib") then - technic_cnc.getter = intllib.Getter() -else - -- Intllib copypasta: TODO replace with the client-side translation API - technic_cnc.getter = 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"") - end - return "@"..o..n..c - end) - end -end dofile(modpath.."/cnc.lua") dofile(modpath.."/cnc_api.lua") diff --git a/technic_cnc/locale/de.txt b/technic_cnc/locale/de.txt deleted file mode 100644 index 8b4e5ff..0000000 --- a/technic_cnc/locale/de.txt +++ /dev/null @@ -1,36 +0,0 @@ -## CNC -CNC Machine = CNC-Maschine -%s CNC Machine = %s CNC-Maschine -Cylinder = Zylinder -Element Cross = Halbes Kreuzelement -Element Cross Double = Kreuzelement -Element Edge = Halbes Eckelement -Element Edge Double = Eckelement -Element End = Halbes Endelement -Element End Double = Endelement -Element Straight = Halbes aufrechtes Element -Element Straight Double = Aufrechtes Element -Element T = Halbes T-Element -Element T Double = T-Element -Horizontal Cylinder = Liegender Zylinder -One Curved Edge Block = Block mit einer abgerundeten Kante -Pyramid = Pyramide -Slope = Schraege -Slope Edge = Schraege mit Ecke -Slope Inner Edge = Schraege mit Innenecke -Slope Lying = Liegende Schraege -Slope Upside Down = Umgedrehte Schraege -Slope Upside Down Edge = Umgedrehte Schraege mit Ecke -Slope Upside Down Inner Edge = Umgedrehte Schraege mit Innenecke -Sphere = Kugel -Spike = Spitze -Stick = Stange -Two Curved Edge Block = Block mit zwei abgerundeten Kanten -Brick = Ziegel: -Cobble = Pflasterstein: -Dirt = Erde: -Leaves = Laub: -Sandstone = Sandstein: -Stone = Stein: -Tree = Baumstamm: -Wooden = Holz: diff --git a/technic_cnc/locale/technic_cnc.de.tr b/technic_cnc/locale/technic_cnc.de.tr new file mode 100644 index 0000000..e6619bc --- /dev/null +++ b/technic_cnc/locale/technic_cnc.de.tr @@ -0,0 +1,50 @@ +# textdomain: technic_cnc +## CNC + +##[ cnc.lua ]## +CNC Machine=CNC-Maschine +@1 CNC Machine=@1 CNC-Maschine +LV=LV +Choose Milling Program:=Wähle das Fräsprogramm aus: +Slim Elements half / normal height:=Schmale halb- / normalhohe Elemente: +In:=Eingabe: +Out:=Ausgabe: +@1 Idle=@1 (wartend) +@1 Unpowered=@1 (unbestromt) +@1 Active=@1 (aktiv) + +##[ cnc_api.lua ]## +Stick=Stock +Element End Double=Endelement +Element Cross Double=Kreuzelement +Element T Double=T-Element +Element Edge Double=Eckelement +Element Straight Double=Gerades Element +Element End=Halbes Endelement +Element Cross=Halbes Kreuzelement +Element T=Halbes T-Element +Element Edge=Halbes Eckelement +Element Straight=Halbes Gerades Eleent +Oblate spheroid=Sphärenstück +Sphere=Sphäre +Horizontal Cylinder=Horizontaler Zylinder +Cylinder=Zylinder +Two Curved Edge/Corner Block=Doppelt gekrümmter Eck/-Randblock +One Curved Edge Block=Einfach gekrümmter Eckblock +Spike=Spitze +Pyramid=Pyramide +Slope Upside Down Inner Edge/Corner=Schräge (kopfüber), innere Ecke +Slope Upside Down Outer Edge/Corner=Schräge (kopfüber), äussere Ecke +Slope Inner Edge/Corner=Schräge, innere Ecke +Slope Outer Edge/Corner=Schräge äussere Ecke +Slope Upside Down=Schräge (kopfüber) +Slope Lying=Liegende Schräge +Slope=Schräge + +##[ cnc_materials.lua ]## +Grassy dirt=Erde mit Gras +Wooden=Holz +Bronze=Bronze +Steel=Stahl +Wrought Iron=Schmiedeeisen +Stainless Steel=Edelstahl diff --git a/technic_cnc/locale/template.txt b/technic_cnc/locale/template.txt index bf3cb08..96432b2 100644 --- a/technic_cnc/locale/template.txt +++ b/technic_cnc/locale/template.txt @@ -1,36 +1,50 @@ +# textdomain: technic_cnc ## CNC -CNC Machine = -%s CNC Machine = -Cylinder = -Element Cross = -Element Cross Double = -Element Edge = -Element Edge Double = -Element End = -Element End Double = -Element Straight = -Element Straight Double = -Element T = -Element T Double = -Horizontal Cylinder = -One Curved Edge Block = -Pyramid = -Slope = -Slope Edge = -Slope Inner Edge = -Slope Lying = -Slope Upside Down = -Slope Upside Down Edge = -Slope Upside Down Inner Edge = -Sphere = -Spike = -Stick = -Two Curved Edge Block = -Brick = -Cobble = -Dirt = -Leaves = -Sandstone = -Stone = -Tree = -Wooden = + +##[ cnc.lua ]## +CNC Machine= +@1 CNC Machine= +LV= +Choose Milling Program:= +Slim Elements half / normal height:= +In:= +Out:= +@1 Idle= +@1 Unpowered= +@1 Active= + +##[ cnc_api.lua ]## +Stick= +Element End Double= +Element Cross Double= +Element T Double= +Element Edge Double= +Element Straight Double= +Element End= +Element Cross= +Element T= +Element Edge= +Element Straight= +Oblate spheroid= +Sphere= +Horizontal Cylinder= +Cylinder= +Two Curved Edge/Corner Block= +One Curved Edge Block= +Spike= +Pyramid= +Slope Upside Down Inner Edge/Corner= +Slope Upside Down Outer Edge/Corner= +Slope Inner Edge/Corner= +Slope Outer Edge/Corner= +Slope Upside Down= +Slope Lying= +Slope= + +##[ cnc_materials.lua ]## +Grassy dirt= +Wooden= +Bronze= +Steel= +Wrought Iron= +Stainless Steel=