Skip to content

Commit

Permalink
technic_cnc: Use client-side translation API (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker authored Apr 28, 2024
1 parent d5ff69d commit ba2bdf8
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 208 deletions.
12 changes: 6 additions & 6 deletions technic_cnc/cnc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;]"..
Expand Down Expand Up @@ -221,18 +221,18 @@ 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
end

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)
Expand Down
164 changes: 48 additions & 116 deletions technic_cnc/cnc_materials.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

-- SANDSTONE
------------
technic_cnc.register_all("default:sandstone",
{crumbly=2, cracky=3, not_in_creative_inventory=1},
{"default_sandstone.png"},
S("Sandstone"))

-- 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 function register_material(nodename, tiles_override, descr_override)
local ndef = minetest.registered_nodes[nodename]
if not ndef then
return
end

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)

technic_cnc.register_all(nodename,
groups,
tiles,
descr_override or ndef.description or "<unknown>"
)
end

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 steeltex = "default_steel_block.png"
local steelname = "Steel"
local steelname = S("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"))
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

-- STEEL
---------------
technic_cnc.register_all("default:steelblock",
{cracky=1, level=2, not_in_creative_inventory=1},
{steeltex},
S(steelname))
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")
16 changes: 1 addition & 15 deletions technic_cnc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 0 additions & 36 deletions technic_cnc/locale/de.txt

This file was deleted.

50 changes: 50 additions & 0 deletions technic_cnc/locale/technic_cnc.de.tr
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit ba2bdf8

Please sign in to comment.