From cd3741e757c1931b1b8a40c1d113bea79f815663 Mon Sep 17 00:00:00 2001 From: "A.C.M." Date: Sat, 27 Jan 2024 02:06:23 +0100 Subject: [PATCH] Translate updatet and german Language added. --- airutils_biofuel.lua | 18 +- airutils_papi.lua | 12 +- airutils_repair.lua | 4 +- airutils_tug.lua | 4 +- airutils_wind.lua | 10 +- init.lua | 60 +++-- lib_copter/control.lua | 5 +- lib_planes/control.lua | 5 +- lib_planes/entities.lua | 12 +- lib_planes/forms.lua | 56 ++--- lib_planes/hud.lua | 3 +- lib_planes/utilities.lua | 12 +- locale/airutils.de.tr | 85 +++++++ locale/template.txt | 85 +++++++ mod_translation_updater.py | 495 +++++++++++++++++++++++++++++++++++++ pilot_skin_manager.lua | 9 +- 16 files changed, 782 insertions(+), 93 deletions(-) create mode 100644 locale/airutils.de.tr create mode 100644 locale/template.txt create mode 100755 mod_translation_updater.py diff --git a/airutils_biofuel.lua b/airutils_biofuel.lua index 0086789..f97e699 100644 --- a/airutils_biofuel.lua +++ b/airutils_biofuel.lua @@ -1,7 +1,7 @@ ---------- --biofuel ---------- - +local S = airutils.S local module_name = "airutils" if minetest.get_modpath("technic") then @@ -48,7 +48,7 @@ end -- biofuel local new_gallon_id = "airutils:biofuel" minetest.register_craftitem(new_gallon_id,{ - description = "Bio Fuel", + description = S("Bio Fuel"), inventory_image = "airutils_biofuel_inv.png", }) @@ -83,7 +83,7 @@ local biofueldistiller_formspec = "size[8,9]" .. "image[3.5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]" minetest.register_node( module_name .. ":biofuel_distiller", { - description = "Biofuel Distiller", + description = S("Biofuel Distiller"), tiles = {"airutils_black.png", "airutils_aluminum.png", "airutils_copper.png" }, drawtype = "mesh", mesh = "airutils_biofuel_distiller.b3d", @@ -101,7 +101,7 @@ minetest.register_node( module_name .. ":biofuel_distiller", { local meta = minetest.get_meta(pos) meta:set_string("formspec", biofueldistiller_formspec) - meta:set_string("infotext", "Biofuel Distiller") + meta:set_string("infotext", S("Biofuel Distiller")) meta:set_float("status", 0.0) local inv = meta:get_inventory() @@ -181,7 +181,7 @@ minetest.register_node( module_name .. ":biofuel_distiller", { if not inv or inv:is_empty("src") then meta:set_float("status", 0.0) - meta:set_string("infotext", "Fuel Distiller") + meta:set_string("infotext", S("Fuel Distiller")) return false end @@ -220,12 +220,12 @@ minetest.register_node( module_name .. ":biofuel_distiller", { -- is there room for additional fermentation? if has_item and not inv:room_for_item("dst", ferment[has_item][2]) then - meta:set_string("infotext", "Fuel Distiller (FULL)") + meta:set_string("infotext", S("Fuel Distiller (FULL)")) return true end if has_group and not inv:room_for_item("dst", new_gallon_id) then - meta:set_string("infotext", "Fuel Distiller (FULL)") + meta:set_string("infotext", S("Fuel Distiller (FULL)")) return true end @@ -233,7 +233,7 @@ minetest.register_node( module_name .. ":biofuel_distiller", { -- fermenting (change status) if status < 100 then - meta:set_string("infotext", "Fuel Distiller " .. status .. "% done") + meta:set_string("infotext", S("Fuel Distiller @1% done", status)) meta:set_float("status", status + 5) else if not has_group then @@ -251,7 +251,7 @@ minetest.register_node( module_name .. ":biofuel_distiller", { if inv:is_empty("src") then meta:set_float("status", 0.0) - meta:set_string("infotext", "Fuel Distiller") + meta:set_string("infotext", S("Fuel Distiller")) end return true diff --git a/airutils_papi.lua b/airutils_papi.lua index 824332b..d589392 100644 --- a/airutils_papi.lua +++ b/airutils_papi.lua @@ -1,3 +1,5 @@ +local S = airutils.S + local function check_protection(pos, name) if minetest.is_protected(pos, name) then minetest.log("action", name @@ -26,7 +28,7 @@ function airutils.PAPIplace(player,pos) core.set_node(pos, {name="airutils:papi", param2=dir}) local meta = core.get_meta(pos) - meta:set_string("infotext", "PAPI\rOwned by: "..player_name) + meta:set_string("infotext", S("PAPI") .. "\r" .. S("Owned by: @1", player_name)) meta:set_string("owner", player_name) meta:set_string("dont_destroy", "false") return true @@ -43,10 +45,10 @@ function airutils.togglePapiSide(pos, node, clicker, itemstack) local dir=node.param2 if node.name == "airutils:papi_right" then core.set_node(pos, {name="airutils:papi", param2=dir}) - meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name) + meta:set_string("infotext", S("PAPI") .. " - " .. S("left side") .. "\r" .. S("Owned by: @1",player_name)) elseif node.name == "airutils:papi" then core.set_node(pos, {name="airutils:papi_right", param2=dir}) - meta:set_string("infotext", "PAPI - right side\rOwned by: "..player_name) + meta:set_string("infotext", S("PAPI") .. " - " .. S("right side") .. "\r" .. S("Owned by: @1",player_name)) end meta:set_string("owner", player_name) @@ -68,7 +70,7 @@ airutils.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2} -- PAPI node (default left) minetest.register_node("airutils:papi",{ - description = "PAPI", + description = S("PAPI"), --inventory_image = "papi.png", --wield_image = "papi.png", tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png", @@ -136,7 +138,7 @@ end -- PAPI right node minetest.register_node("airutils:papi_right",{ - description = "PAPI_right_side", + description = S("PAPI") .. "_" .. S("right_side"), tiles = {"airutils_black.png", "airutils_u_black.png", "airutils_white.png", "airutils_metal.png", {name = "airutils_red.png", backface_culling = true},}, groups = airutils.groups_right, diff --git a/airutils_repair.lua b/airutils_repair.lua index 6aaa151..ee6f06e 100644 --- a/airutils_repair.lua +++ b/airutils_repair.lua @@ -1,8 +1,8 @@ -local S = minetest.get_translator("airutils") +local S = airutils.S -- trike repair minetest.register_craftitem("airutils:repair_tool",{ - description = "Repair Tool", + description = S("Repair Tool"), inventory_image = "airutils_repair_tool.png", }) diff --git a/airutils_tug.lua b/airutils_tug.lua index 9ae359c..0b8f8d0 100644 --- a/airutils_tug.lua +++ b/airutils_tug.lua @@ -1,4 +1,4 @@ -local S = minetest.get_translator("airutils") +local S = airutils.S function airutils.move_target(player, pointed_thing) local pos = player:get_pos() @@ -42,7 +42,7 @@ function airutils.move_target(player, pointed_thing) end minetest.register_tool("airutils:tug", { - description = "Tug tool for airport", + description = S("Tug tool for airport"), inventory_image = "airutils_tug.png", stack_max=1, on_use = function(itemstack, player, pointed_thing) diff --git a/airutils_wind.lua b/airutils_wind.lua index 5c4e190..786807e 100644 --- a/airutils_wind.lua +++ b/airutils_wind.lua @@ -1,3 +1,5 @@ +local S = airutils.S + local function check_protection(pos, name) if minetest.is_protected(pos, name) then minetest.log("action", name @@ -26,7 +28,7 @@ function airutils.WindDplace(player,pos) core.set_node(pos1, {name="airutils:wind", param2=dir}) local meta = core.get_meta(pos) - meta:set_string("infotext", "Wind Indicator\rOwned by: "..player_name) + meta:set_string("infotext", S("Wind Indicator") .. "\r" .. S("Owned by: @1",player_name)) meta:set_string("owner", player_name) meta:set_string("dont_destroy", "false") return true @@ -115,7 +117,7 @@ minetest.register_entity("airutils:wind_indicator",{ on_rightclick = function(self, clicker) local wind = airutils.get_wind(pos, 2.0) local wind_yaw = minetest.dir_to_yaw(wind) - minetest.chat_send_player(clicker:get_player_name(),core.colorize('#00ff00', " >>> The wind direction now is "..math.deg(wind_yaw))) + minetest.chat_send_player(clicker:get_player_name(),core.colorize('#00ff00', S(" >>> The wind direction now is @1", math.deg(wind_yaw)))) return end, @@ -125,7 +127,7 @@ minetest.register_entity("airutils:wind_indicator",{ -- Wind Indicator node (default left) minetest.register_node("airutils:wind",{ - description = "Wind Direction Indicator", + description = S("Wind Direction Indicator"), waving = 1, tiles = {"default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png"}, paramtype = "light", @@ -159,7 +161,7 @@ minetest.register_node("airutils:wind",{ itemstack:take_item() end else - minetest.chat_send_player(player_name, "Node is protected") + minetest.chat_send_player(player_name, S("Node is protected")) minetest.record_protection_violation(pos, player_name) end diff --git a/init.lua b/init.lua index 01d74bf..506f217 100644 --- a/init.lua +++ b/init.lua @@ -23,6 +23,18 @@ airutils.colors ={ yellow='#ffe400', } +airutils.S = nil + +if(minetest.get_translator ~= nil) then + airutils.S = minetest.get_translator(minetest.get_current_modname()) + +else + airutils.S = function ( s ) return s end + +end + +local S = airutils.S + local load_blast_damage = storage:get_int("blast_damage") airutils.blast_damage = true -- 1 == true ---- 2 == false @@ -113,12 +125,12 @@ function airutils.setText(self, vehicle_name) local formatted = "" if type(self.hp_max) ~= "number" then self.hp_max = 0.1 end --strange error when hpmax is NaN if self.hp_max then - formatted = " Current hp: " .. string.format( + formatted = S(" Current hp: ") .. string.format( "%.2f", self.hp_max ) end if properties then - properties.infotext = "Nice ".. vehicle_name .." of " .. self.owner .. "." .. formatted + properties.infotext = S("Nice @1 of @2.@3", vehicle_name, self.owner, formatted) self.object:set_properties(properties) end end @@ -129,19 +141,19 @@ function airutils.transfer_control(self, status) self._command_is_given = false if self.co_pilot then minetest.chat_send_player(self.co_pilot, - core.colorize('#ff0000', " >>> The captain got the control.")) + core.colorize('#ff0000', S(" >>> The captain got the control."))) end if self.driver_name then minetest.chat_send_player(self.driver_name, - core.colorize('#00ff00', " >>> The control is with you now.")) + core.colorize('#00ff00', S(" >>> The control is with you now."))) end else self._command_is_given = true if self.co_pilot then minetest.chat_send_player(self.co_pilot, - core.colorize('#00ff00', " >>> The control is with you now.")) + core.colorize('#00ff00', S(" >>> The control is with you now."))) end - if self.driver_name then minetest.chat_send_player(self.driver_name," >>> The control was given.") end + if self.driver_name then minetest.chat_send_player(self.driver_name,S(" >>> The control was given.")) end end end @@ -472,17 +484,17 @@ end minetest.register_chatcommand("enable_blast_damage", { params = "", - description = "Enable/disable explosion blast damage", + description = S("Enable/disable explosion blast damage"), privs = {server=true}, func = function(name, param) local command = param if command == "false" then airutils.blast_damage = false - minetest.chat_send_player(name, ">>> Blast damage by explosion is disabled") + minetest.chat_send_player(name, S(">>> Blast damage by explosion is disabled")) else airutils.blast_damage = true - minetest.chat_send_player(name, ">>> Blast damage by explosion is enabled") + minetest.chat_send_player(name, S(">>> Blast damage by explosion is enabled")) end local save = 2 if airutils.blast_damage == true then save = 1 end @@ -492,7 +504,7 @@ minetest.register_chatcommand("enable_blast_damage", { minetest.register_chatcommand("transfer_ownership", { params = "", - description = "Transfer the property of a plane to another player", + description = S("Transfer the property of a plane to another player"), privs = {interact=true}, func = function(name, param) local player = minetest.get_player_by_name(name) @@ -507,27 +519,27 @@ minetest.register_chatcommand("transfer_ownership", { if entity then if entity.owner == name or minetest.check_player_privs(name, {protection_bypass=true}) then entity.owner = param - minetest.chat_send_player(name,core.colorize('#00ff00', " >>> This plane now is property of: "..param)) + minetest.chat_send_player(name,core.colorize('#00ff00', S(" >>> This plane now is property of: ")..param)) else - minetest.chat_send_player(name,core.colorize('#ff0000', " >>> only the owner or moderators can transfer this airplane")) + minetest.chat_send_player(name,core.colorize('#ff0000', S(" >>> only the owner or moderators can transfer this airplane"))) end end end else - minetest.chat_send_player(name,core.colorize('#ff0000', " >>> the target player must be logged in")) + minetest.chat_send_player(name,core.colorize('#ff0000', S(" >>> the target player must be logged in"))) end else - minetest.chat_send_player(name,core.colorize('#ff0000', " >>> you are not inside a plane to perform the command")) + minetest.chat_send_player(name,core.colorize('#ff0000', S(" >>> you are not inside a plane to perform the command"))) end end }) minetest.register_chatcommand("eject_from_plane", { params = "", - description = "Ejects from a plane", + description = S("Ejects from a plane"), privs = {interact = true}, func = function(name, param) - local colorstring = core.colorize('#ff0000', " >>> you are not inside a plane") + local colorstring = core.colorize('#ff0000', S(" >>> you are not inside a plane")) local player = minetest.get_player_by_name(name) local attached_to = player:get_attach() @@ -556,40 +568,40 @@ minetest.register_chatcommand("eject_from_plane", { minetest.register_chatcommand("ground_effect", { params = "", - description = "Enables/disables the ground effect (for debug purposes)", + description = S("Enables/disables the ground effect (for debug purposes)"), privs = {interact=true}, func = function(name, param) local player = minetest.get_player_by_name(name) if minetest.check_player_privs(name, {server=true}) then if param == "on" or param == "" then airutils.ground_effect_is_disabled = nil - minetest.chat_send_player(name,core.colorize('#00ff00', " >>> Ground effect was turned on.")) + minetest.chat_send_player(name,core.colorize('#00ff00', S(" >>> Ground effect was turned on."))) elseif param == "off" then airutils.ground_effect_is_disabled = true - minetest.chat_send_player(name,core.colorize('#0000ff', " >>> Ground effect was turned off.")) + minetest.chat_send_player(name,core.colorize('#0000ff', S(">>> Ground effect was turned off."))) end else - minetest.chat_send_player(name,core.colorize('#ff0000', " >>> You need 'server' priv to run this command.")) + minetest.chat_send_player(name,core.colorize('#ff0000', S(" >>> You need 'server' priv to run this command."))) end end }) minetest.register_chatcommand("show_lift", { params = "", - description = "Enables/disables the lift printing (for debug purposes)", + description = S("Enables/disables the lift printing (for debug purposes)"), privs = {interact=true}, func = function(name, param) local player = minetest.get_player_by_name(name) if minetest.check_player_privs(name, {server=true}) then if param == "on" or param == "" then airutils.show_lift = name - minetest.chat_send_player(name,core.colorize('#0000ff', " >>> Lift printing turned on.")) + minetest.chat_send_player(name,core.colorize('#0000ff', S(" >>> Lift printing turned on."))) elseif param == "off" then airutils.show_lift = nil - minetest.chat_send_player(name,core.colorize('#00ff00', " >>> Lift printing turned off.")) + minetest.chat_send_player(name,core.colorize('#00ff00', S(" >>> Lift printing turned off."))) end else - minetest.chat_send_player(name,core.colorize('#ff0000', " >>> You need 'server' priv to run this command.")) + minetest.chat_send_player(name,core.colorize('#ff0000', S(" >>> You need 'server' priv to run this command."))) end end }) diff --git a/lib_copter/control.lua b/lib_copter/control.lua index c28265b..26e0b32 100755 --- a/lib_copter/control.lua +++ b/lib_copter/control.lua @@ -1,5 +1,6 @@ --[[airutils.rudder_limit = 30 airutils.elevator_limit = 40]]-- +local S = airutils.S dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "utilities.lua") @@ -160,10 +161,10 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit self._last_time_command = 0 local name = player:get_player_name() if self._yaw_by_mouse == true then - minetest.chat_send_player(name, core.colorize('#0000ff', " >>> Mouse control disabled.")) + minetest.chat_send_player(name, core.colorize('#0000ff', S(" >>> Mouse control disabled."))) self._yaw_by_mouse = false else - minetest.chat_send_player(name, core.colorize('#0000ff', " >>> Mouse control enabled.")) + minetest.chat_send_player(name, core.colorize('#0000ff', S(" >>> Mouse control enabled."))) self._yaw_by_mouse = true end end diff --git a/lib_planes/control.lua b/lib_planes/control.lua index ba6d39f..ce9ff4f 100755 --- a/lib_planes/control.lua +++ b/lib_planes/control.lua @@ -5,6 +5,7 @@ airutils.ideal_step = 0.02 airutils.elevator_limit = 40]]-- dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "utilities.lua") +local S = airutils.S function airutils.powerAdjust(self,dtime,factor,dir,max_power) local max = max_power or 100 @@ -138,10 +139,10 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag self._last_time_command = 0 local name = player:get_player_name() if self._yaw_by_mouse == true then - minetest.chat_send_player(name, core.colorize('#0000ff', " >>> Mouse control disabled.")) + minetest.chat_send_player(name, core.colorize('#0000ff', S(" >>> Mouse control disabled."))) self._yaw_by_mouse = false else - minetest.chat_send_player(name, core.colorize('#0000ff', " >>> Mouse control enabled.")) + minetest.chat_send_player(name, core.colorize('#0000ff', S(" >>> Mouse control enabled."))) self._yaw_by_mouse = true end end diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index f4884b9..4929681 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -1,5 +1,7 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "global_definitions.lua") +local S = airutils.S + function lib_change_color(self, colstr) airutils.param_paint(self, colstr) end @@ -238,14 +240,14 @@ function airutils.logic(self) if ctrl.sneak or ctrl.jump or ctrl.up or ctrl.down or ctrl.right or ctrl.left then self._last_time_command = 0 self._autopilot = false - minetest.chat_send_player(self.driver_name," >>> Autopilot deactivated") + minetest.chat_send_player(self.driver_name,S(" >>> Autopilot deactivated")) end else if ctrl.sneak == true and ctrl.jump == true and self._have_auto_pilot then self._last_time_command = 0 self._autopilot = true self._auto_pilot_altitude = curr_pos.y - minetest.chat_send_player(self.driver_name,core.colorize('#00ff00', " >>> Autopilot on")) + minetest.chat_send_player(self.driver_name,core.colorize('#00ff00', S(" >>> Autopilot on"))) end end end @@ -613,7 +615,7 @@ function airutils.logic(self) if (longit_speed / 2) > self._max_speed and self._flap == true then if is_attached and self.driver_name then - minetest.chat_send_player(self.driver_name, core.colorize('#ff0000', " >>> Flaps retracted due for overspeed")) + minetest.chat_send_player(self.driver_name, core.colorize('#ff0000', S(" >>> Flaps retracted due for overspeed"))) end self._flap = false end @@ -721,7 +723,7 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) if self.hp_max > self._max_plane_hp then self.hp_max = self._max_plane_hp end airutils.setText(self, self._vehicle_name) else - minetest.chat_send_player(puncher:get_player_name(), "You need steel ingots in your inventory to perform this repair.") + minetest.chat_send_player(puncher:get_player_name(), S("You need steel ingots in your inventory to perform this repair.")) end end return @@ -878,7 +880,7 @@ function airutils.on_rightclick(self, clicker) end else airutils.dettach_pax(self, clicker) - minetest.chat_send_player(name, core.colorize('#ff0000', " >>> You aren't the owner of this "..self.infotext..".")) + minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> You aren't the owner of this "..self.infotext.."."))) end --========================= diff --git a/lib_planes/forms.lua b/lib_planes/forms.lua index 741381f..937cd47 100644 --- a/lib_planes/forms.lua +++ b/lib_planes/forms.lua @@ -1,5 +1,5 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "global_definitions.lua") - +local S = airutils.S -------------- -- Manual -- -------------- @@ -55,53 +55,53 @@ function airutils.pilot_formspec(name) local ver_pos = 1.0 local basic_form = "" --basic_form = basic_form.."button[1,"..ver_pos..";4,1;turn_on;Start/Stop Engines]" - basic_form = basic_form.."checkbox[1,"..ver_pos..";turn_on;"..core.colorize(eng_status_color, "Start/Stop Engines")..";"..eng_status.."]" + basic_form = basic_form.."checkbox[1,"..ver_pos..";turn_on;"..core.colorize(eng_status_color, S("Start/Stop Engines"))..";"..eng_status.."]" ver_pos = ver_pos + 1.1 - basic_form = basic_form.."button[1,"..ver_pos..";4,1;hud;Show/Hide Gauges]" + basic_form = basic_form.."button[1,"..ver_pos..";4,1;hud;" .. S("Show/Hide Gauges") .. "]" ver_pos = ver_pos + 1.1 - basic_form = basic_form.."button[1,"..ver_pos..";4,1;inventory;Show Inventory]" + basic_form = basic_form.."button[1,"..ver_pos..";4,1;inventory;" .. S("Show Inventory") .. "]" ver_pos = ver_pos + 1.5 - basic_form = basic_form.."checkbox[1,"..ver_pos..";yaw;Yaw by mouse;"..yaw.."]" + basic_form = basic_form.."checkbox[1,"..ver_pos..";yaw;" .. S("Yaw by mouse") .. ";"..yaw.."]" ver_pos = ver_pos + 0.5 - basic_form = basic_form.."button[1,"..ver_pos..";4,1;go_out;Go Out!]" + basic_form = basic_form.."button[1,"..ver_pos..";4,1;go_out;" .. S("Go Out!") .. "]" --form second part local expand_form = false ver_pos = 1.2 --restart in second collumn if have_flaps then - basic_form = basic_form.."checkbox[6,"..ver_pos..";flap_is_down;Flaps down;"..flap_is_down.."]" + basic_form = basic_form.."checkbox[6,"..ver_pos..";flap_is_down;" .. S("Flaps down") .. ";"..flap_is_down.."]" ver_pos = ver_pos + 0.5 expand_form = true end if ent._have_landing_lights then - basic_form = basic_form.."checkbox[6,"..ver_pos..";light;Landing Light;"..light.."]" + basic_form = basic_form.."checkbox[6,"..ver_pos..";light;" .. S("Landing Light") .. ";"..light.."]" ver_pos = ver_pos + 0.5 expand_form = true end if ent._have_auto_pilot then - basic_form = basic_form.."checkbox[6,"..ver_pos..";turn_auto_pilot_on;Autopilot;"..autopilot.."]" + basic_form = basic_form.."checkbox[6,"..ver_pos..";turn_auto_pilot_on;" .. S("Autopilot") .. ";"..autopilot.."]" ver_pos = ver_pos + 0.5 expand_form = true end if ent._have_copilot and name == ent.driver_name then - basic_form = basic_form.."button[6,"..ver_pos..";4,1;copilot_form;Co-pilot Manager]" + basic_form = basic_form.."button[6,"..ver_pos..";4,1;copilot_form;" .. S("Co-pilot Manager") .. "]" ver_pos = ver_pos + 1.25 expand_form = true end if ent._have_adf then - basic_form = basic_form.."button[6,"..ver_pos..";4,1;adf_form;Adf Manager]" + basic_form = basic_form.."button[6,"..ver_pos..";4,1;adf_form;" .. S("Adf Manager") .. "]" ver_pos = ver_pos + 1.1 expand_form = true end if ent._have_manual then - basic_form = basic_form.."button[6,5.2;4,1;manual;Manual]" + basic_form = basic_form.."button[6,5.2;4,1;manual;" .. S("Manual") .. "]" expand_form = true end @@ -133,14 +133,14 @@ function airutils.manage_copilot_formspec(name) "size[6,4.5]", }, "") - basic_form = basic_form.."label[1,1.0;Bring a copilot:]" + basic_form = basic_form.."label[1,1.0;" .. S("Bring a copilot") .. ":]" local max_seats = table.getn(ent._seats) if ent._have_copilot and max_seats > 2 then --no need to select if there are only 2 occupants basic_form = basic_form.."dropdown[1,1.5;4,0.6;copilot;"..pass_list..";0;false]" end - basic_form = basic_form.."button[1,2.5;4,1;pass_control;Pass the Control]" + basic_form = basic_form.."button[1,2.5;4,1;pass_control;" .. S("Pass the Control") .. "]" minetest.show_formspec(name, "lib_planes:manage_copilot", basic_form) end @@ -177,10 +177,10 @@ function airutils.adf_formspec(name) "size[6,3.5]", }, "") - basic_form = basic_form.."checkbox[1.0,1.0;adf;Auto Direction Find;"..adf.."]" + basic_form = basic_form.."checkbox[1.0,1.0;adf;" .. S("Auto Direction Find") .. ";"..adf.."]" basic_form = basic_form.."field[1.0,1.7;1.5,0.6;adf_x;pos x;"..x.."]" basic_form = basic_form.."field[2.8,1.7;1.5,0.6;adf_z;pos z;"..z.."]" - basic_form = basic_form.."button[4.5,1.7;0.6,0.6;save_adf;OK]" + basic_form = basic_form.."button[4.5,1.7;0.6,0.6;save_adf;" .. S("OK") .. "]" minetest.show_formspec(name, "lib_planes:adf_main", basic_form) end @@ -191,8 +191,8 @@ function airutils.pax_formspec(name) "size[6,5]", }, "") - basic_form = basic_form.."button[1,1.0;4,1;new_seat;Change Seat]" - basic_form = basic_form.."button[1,2.5;4,1;go_out;Go Offboard]" + basic_form = basic_form.."button[1,1.0;4,1;new_seat;" .. S("Change Seat") .. "]" + basic_form = basic_form.."button[1,2.5;4,1;go_out;" .. S("Go Offboard") .. "]" minetest.show_formspec(name, "lib_planes:passenger_main", basic_form) end @@ -203,9 +203,9 @@ function airutils.go_out_confirmation_formspec(name) "size[7,2.2]", }, "") - basic_form = basic_form.."label[0.5,0.5;Do you really want to go offboard now?]" - basic_form = basic_form.."button[1.3,1.0;2,0.8;no;No]" - basic_form = basic_form.."button[3.6,1.0;2,0.8;yes;Yes]" + basic_form = basic_form.."label[0.5,0.5;" .. S("Do you really want to go offboard now?") .. "]" + basic_form = basic_form.."button[1.3,1.0;2,0.8;no;" .. S("No") .. "]" + basic_form = basic_form.."button[3.6,1.0;2,0.8;yes;" .. S("Yes") .. "]" minetest.show_formspec(name, "lib_planes:go_out_confirmation_form", basic_form) end @@ -230,7 +230,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local name = player:get_player_name() local plane_obj = airutils.getPlaneFromPlayer(player) if plane_obj == nil then - minetest.chat_send_player(name, core.colorize('#ff0000', " >>> There is something wrong with the plane...")) + minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> There is something wrong with the plane..."))) minetest.close_formspec(name, "lib_planes:adf_main") return end @@ -239,10 +239,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.adf then if ent._adf == true then ent._adf = false - minetest.chat_send_player(name, core.colorize('#0000ff', " >>> ADF deactivated.")) + minetest.chat_send_player(name, core.colorize('#0000ff', S(" >>> ADF deactivated."))) else ent._adf = true - minetest.chat_send_player(name, core.colorize('#00ff00', " >>> ADF activated.")) + minetest.chat_send_player(name, core.colorize('#00ff00', S(" >>> ADF activated."))) end end if fields.save_adf then @@ -252,17 +252,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if tonumber(fields.adf_x, 10) ~= nil and tonumber(fields.adf_z, 10) ~= nil then ent._adf_destiny.x = tonumber(fields.adf_x, 10) ent._adf_destiny.z = tonumber(fields.adf_z, 10) - minetest.chat_send_player(name, core.colorize('#00ff00', " >>> Destination written successfully.")) + minetest.chat_send_player(name, core.colorize('#00ff00', S(" >>> Destination written successfully."))) else - minetest.chat_send_player(name, core.colorize('#ff0000', " >>> There is something wrong with the ADF fields values.")) + minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> There is something wrong with the ADF fields values."))) end else - minetest.chat_send_player(name, core.colorize('#ff0000', " >>> Both ADF fields must be given to complete the operation.")) + minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> Both ADF fields must be given to complete the operation."))) end end end else - minetest.chat_send_player(name, core.colorize('#ff0000', " >>> There is something wrong on ADF saving...")) + minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> There is something wrong on ADF saving..."))) end minetest.close_formspec(name, "lib_planes:adf_main") end diff --git a/lib_planes/hud.lua b/lib_planes/hud.lua index 2112514..91a1dfb 100755 --- a/lib_planes/hud.lua +++ b/lib_planes/hud.lua @@ -1,4 +1,5 @@ airutils.hud_list = {} +local S = airutils.S function airutils.animate_gauge(player, ids, prefix, x, y, angle) local angle_in_rad = math.rad(angle + 180) @@ -58,7 +59,7 @@ function airutils.update_hud(player, climb, speed, power, fuel) hud_elem_type = "text", position = {x = 0, y = 1}, offset = {x = screen_pos_x +140, y = screen_pos_y -100}, - text = "Flight Information", + text = S("Flight Information"), alignment = 0, scale = { x = 100, y = 30}, number = 0xFFFFFF, diff --git a/lib_planes/utilities.lua b/lib_planes/utilities.lua index 2a5c75d..987a710 100644 --- a/lib_planes/utilities.lua +++ b/lib_planes/utilities.lua @@ -1,6 +1,8 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "global_definitions.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "hud.lua") +local S = airutils.S + function airutils.properties_copy(origin_table) local tablecopy = {} for k, v in pairs(origin_table) do @@ -60,7 +62,7 @@ function airutils.attach(self, player, instructor_mode) if self._needed_licence then local can_fly = minetest.check_player_privs(player, self._needed_licence) if not can_fly then - minetest.chat_send_player(player:get_player_name(), core.colorize('#ff0000', ' >>> You need trhe priv "'..self._needed_licence..'" to fly this plane.')) + minetest.chat_send_player(player:get_player_name(), core.colorize('#ff0000', S(' >>> You need the priv') .. '"'..self._needed_licence..'" ' .. S('to fly this plane.'))) return end end @@ -907,7 +909,7 @@ function airutils.start_engine(self) self._last_applied_power = -1 --send signal to start else if self.driver_name then - minetest.chat_send_player(self.driver_name,core.colorize('#ff0000', " >>> The engine is damaged, start procedure failed.")) + minetest.chat_send_player(self.driver_name,core.colorize('#ff0000', S(" >>> The engine is damaged, start procedure failed."))) end end end @@ -1033,7 +1035,7 @@ end function airutils.flap_operate(self, player) if self._flap == false then - minetest.chat_send_player(player:get_player_name(), ">>> Flap down") + minetest.chat_send_player(player:get_player_name(), S(">>> Flap down")) self._flap = true airutils.flap_on(self) minetest.sound_play("airutils_collision", { @@ -1044,7 +1046,7 @@ function airutils.flap_operate(self, player) pitch = 0.5, }, true) else - minetest.chat_send_player(player:get_player_name(), ">>> Flap up") + minetest.chat_send_player(player:get_player_name(), S(">>> Flap up")) self._flap = false airutils.flap_off(self) minetest.sound_play("airutils_collision", { @@ -1192,7 +1194,7 @@ function airutils.destroyed_open_inventory(self, clicker) end airutils.show_vehicle_trunk_formspec(self, clicker, self._trunk_slots) else - minetest.chat_send_player(name, core.colorize('#ff0000', '>>> You cannot claim this scrap yet, wait some minutes.')) + minetest.chat_send_player(name, core.colorize('#ff0000', S('>>> You cannot claim this scrap yet, wait some minutes.'))) end end diff --git a/locale/airutils.de.tr b/locale/airutils.de.tr new file mode 100644 index 0000000..ea3bce8 --- /dev/null +++ b/locale/airutils.de.tr @@ -0,0 +1,85 @@ +# textdomain: airutils +Bio Fuel=Biotreibstoff +Biofuel Distiller=Biotreibstoff-Brenner +Fuel Distiller=Treibstoff-Destilliergerät +Fuel Distiller (FULL)=Treibstoff-Destilliergerät (VOLL) +Fuel Distiller @1% done=Treibstoff-Destilliergerät @1% fertig +PAPI=PAPI +left side=linke Seite +right side=rechte Seite +right_side=rechte_seite +Owned by: @1=Gehört: @1 +Repair Tool=Reparaturwerkzeug +Tug tool for airport=Schleppwerkzeug für den Flughafen +@1 is protected by @2.=@1 ist geschützt von @2. +@1 is protected.=@1 ist geschützt. +Wind Indicator=Windanzeiger + >>> The wind direction now is @1= >>> Die Windrichtung ist nun @1 +Wind Direction Indicator=Windrichtungsanzeiger +Node is protected=Block ist geschützt + Current hp: = Aktuelle Lp: +Nice @1 of @2.@3= Schnöne(s) @1 von @2.@3 + >>> The captain got the control.= >>> Der Kaptain übernimmt die Kontrolle. + >>> The control is with you now.= >>> Du hast nun die Kontrolle. + >>> The control was given.= >>> Die Kontrolle wurde erteilt. +Enable/disable explosion blast damage=Explosionsschaden aktivieren/deaktivieren +>>> Blast damage by explosion is disabled=Explosionsschaden ist deaktiviert. +>>> Blast damage by explosion is enabled=Explosionsschaden ist aktiviert. +Transfer the property of a plane to another player=Überträgt die Eigentümerschaft des Fluggerätes an einen anderen Spieler. + >>> This plane now is property of: = >>> Dieses Fluggerät ist nun Eigentum von: + >>> only the owner or moderators can transfer this airplane= >>> Nur der Eigentümer oder Moderator kann die Eigentümerschaft ändern. + >>> the target player must be logged in= >>> der Zielspieler muß eingeloggt sein. + >>> you are not inside a plane to perform the command= >>> du sitzt in keinem Fluggerät um dieses Kommando zu geben +Ejects from a plane=Wirft dich aus dem Fluggerät + >>> you are not inside a plane= >>> du sitzt in keinem Fluggerät +Enables/disables the ground effect (for debug purposes)=Ein/Ausschaltet den Bodeneffekt (zur Fehlersuche) + >>> Ground effect was turned on.= >>> Bodeneffekt wurde eingeschalten. +>>> Ground effect was turned off.=>>> Bodeneffekt wurde ausgeschalten. + >>> You need 'server' priv to run this command.= >>> Du brauchst 'server'-rechte um dieses Kommando auszuführen. +Enables/disables the lift printing (for debug purposes)=Ein/Ausschalten des Lift schreibens (zur Fehlersuche) + >>> Lift printing turned on.= >>> Lift schreiben eingeschalten. + >>> Lift printing turned off.= >>> Lift schreiben ausgeschalten. + >>> Mouse control disabled.= >>> Mauslenkung ausgeschalten. + >>> Mouse control enabled.= >>> Mauslenkung eingeschalten. + >>> Autopilot deactivated= >>> Autopilot ausgeschalten + >>> Autopilot on= >>> Autopilot eingeschalten + >>> Flaps retracted due for overspeed= >>> Klappen eingefahren wegen Hochgeschwindigkeit +You need steel ingots in your inventory to perform this repair.=Du brauchst Eisenbarren in einem Inventar um das zu reparieren. +Start/Stop Engines=Starte/Stoppe Maschinen +Show/Hide Gauges=Blende Messgeräte ein/aus +Show Inventory=Zeige Inventar +Yaw by mouse=Lenke mit Maus +Go Out!=Steig aus! +Flaps down=Klappen unten +Landing Light=Landelicht +Autopilot=Autopilot +Co-pilot Manager=Co-Pilot Manager +Adf Manager=Adf Manager +Manual=Manuell +Bring a copilot=Bring einen Copiloten +Pass the Control=Übergebe die Kontrolle +Auto Direction Find=Automatischer Richtungsfinder +OK=OK +Change Seat=Wechlse Sitzplatz +Go Offboard=Aussteigen +Do you really want to go offboard now?=Du willst jetzt wirklich aussteigen? +No=Nein +Yes=Ja + >>> There is something wrong with the plane...= >>> Da stimmt was nicht mit dem Fluggerät + >>> ADF deactivated.= >>> ADF deaktiviert + >>> ADF activated.= >>> ADF aktiviert. + >>> Destination written successfully.= >>> Ziel erfolgreich eingetragen + >>> There is something wrong with the ADF fields values.=Mit den Werten der ADF-Felder ist etwas nicht in Ordnung + >>> Both ADF fields must be given to complete the operation.= >>> Beide ADF-Felder müssen angegeben werden, damit der Vorgang abgeschlossen werden kann + >>> There is something wrong on ADF saving...= >>> Da stimmt etwas nicht mit dem ADF speichern +Flight Information=Fluginformation + >>> You need the priv= >>> Du brauchst das Recht +to fly this plane.=um das Fluggerät zu fliegen. + >>> The engine is damaged, start procedure failed.= >>> Die Maschine ist beschädigt, starten fehlgeschlagen. +>>> Flap down=>>> Klappen unten +>>> Flap up=>>> Klappen oben +>>> You cannot claim this scrap yet, wait some minutes.=Du kannst diesen Schrott noch nicht beanspruchen, warte ein paar Minuten +Sorry, but this module doesn't work when SkinsDb and Armor are instaled together.=Entschuldige, aber dieses Modul funktioniert nicht, wenn SkinsDb und Armor zusammen installiert ist. +Something isn't working...=Etwas funktioniert nicht... +Set Player Texture=Wähle Spielertextur +The isn't activated as secure. Aborting=Das ist zur Sicherheit nicht aktiviert. Abbruch diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..3563107 --- /dev/null +++ b/locale/template.txt @@ -0,0 +1,85 @@ +# textdomain: airutils +Bio Fuel= +Biofuel Distiller= +Fuel Distiller= +Fuel Distiller (FULL)= +Fuel Distiller @1% done= +PAPI= +left side= +right side= +right_side= +Owned by: @1= +Repair Tool= +Tug tool for airport= +@1 is protected by @2.= +@1 is protected.= +Wind Indicator= + >>> The wind direction now is @1= +Wind Direction Indicator= +Node is protected= + Current hp: = +Nice @1 of @2.@3= + >>> The captain got the control.= + >>> The control is with you now.= + >>> The control was given.= +Enable/disable explosion blast damage= +>>> Blast damage by explosion is disabled= +>>> Blast damage by explosion is enabled= +Transfer the property of a plane to another player= + >>> This plane now is property of: = + >>> only the owner or moderators can transfer this airplane= + >>> the target player must be logged in= + >>> you are not inside a plane to perform the command= +Ejects from a plane= + >>> you are not inside a plane= +Enables/disables the ground effect (for debug purposes)= + >>> Ground effect was turned on.= +>>> Ground effect was turned off.= + >>> You need 'server' priv to run this command.= +Enables/disables the lift printing (for debug purposes)= + >>> Lift printing turned on.= + >>> Lift printing turned off.= + >>> Mouse control disabled.= + >>> Mouse control enabled.= + >>> Autopilot deactivated= + >>> Autopilot on= + >>> Flaps retracted due for overspeed= +You need steel ingots in your inventory to perform this repair.= +Start/Stop Engines= +Show/Hide Gauges= +Show Inventory= +Yaw by mouse= +Go Out!= +Flaps down= +Landing Light= +Autopilot= +Co-pilot Manager= +Adf Manager= +Manual= +Bring a copilot= +Pass the Control= +Auto Direction Find= +OK= +Change Seat= +Go Offboard= +Do you really want to go offboard now?= +No= +Yes= + >>> There is something wrong with the plane...= + >>> ADF deactivated.= + >>> ADF activated.= + >>> Destination written successfully.= + >>> There is something wrong with the ADF fields values.= + >>> Both ADF fields must be given to complete the operation.= + >>> There is something wrong on ADF saving...= +Flight Information= + >>> You need the priv= +to fly this plane.= + >>> The engine is damaged, start procedure failed.= +>>> Flap down= +>>> Flap up= +>>> You cannot claim this scrap yet, wait some minutes.= +Sorry, but this module doesn't work when SkinsDb and Armor are instaled together.= +Something isn't working...= +Set Player Texture= +The isn't activated as secure. Aborting= diff --git a/mod_translation_updater.py b/mod_translation_updater.py new file mode 100755 index 0000000..b2feaaf --- /dev/null +++ b/mod_translation_updater.py @@ -0,0 +1,495 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Script to generate Minetest translation template files and update +# translation files. +# +# Copyright (C) 2019 Joachim Stolberg, 2020 FaceDeer, 2020 Louis Royer, +# 2023 Wuzzy. +# License: LGPLv2.1 or later (see LICENSE file for details) + +import os, fnmatch, re, shutil, errno +from sys import argv as _argv +from sys import stderr as _stderr + +# Running params +params = {"recursive": False, + "help": False, + "verbose": False, + "folders": [], + "old-file": False, + "break-long-lines": False, + "print-source": False, + "truncate-unused": False, +} +# Available CLI options +options = {"recursive": ['--recursive', '-r'], + "help": ['--help', '-h'], + "verbose": ['--verbose', '-v'], + "old-file": ['--old-file', '-o'], + "break-long-lines": ['--break-long-lines', '-b'], + "print-source": ['--print-source', '-p'], + "truncate-unused": ['--truncate-unused', '-t'], +} + +# Strings longer than this will have extra space added between +# them in the translation files to make it easier to distinguish their +# beginnings and endings at a glance +doublespace_threshold = 80 + +# These symbols mark comment lines showing the source file name. +# A comment may look like "##[ init.lua ]##". +symbol_source_prefix = "##[" +symbol_source_suffix = "]##" + +# comment to mark the section of old/unused strings +comment_unused = "##### not used anymore #####" + +def set_params_folders(tab: list): + '''Initialize params["folders"] from CLI arguments.''' + # Discarding argument 0 (tool name) + for param in tab[1:]: + stop_param = False + for option in options: + if param in options[option]: + stop_param = True + break + if not stop_param: + params["folders"].append(os.path.abspath(param)) + +def set_params(tab: list): + '''Initialize params from CLI arguments.''' + for option in options: + for option_name in options[option]: + if option_name in tab: + params[option] = True + break + +def print_help(name): + '''Prints some help message.''' + print(f'''SYNOPSIS + {name} [OPTIONS] [PATHS...] +DESCRIPTION + {', '.join(options["help"])} + prints this help message + {', '.join(options["recursive"])} + run on all subfolders of paths given + {', '.join(options["old-file"])} + create *.old files + {', '.join(options["break-long-lines"])} + add extra line breaks before and after long strings + {', '.join(options["print-source"])} + add comments denoting the source file + {', '.join(options["verbose"])} + add output information + {', '.join(options["truncate-unused"])} + delete unused strings from files +''') + +def main(): + '''Main function''' + set_params(_argv) + set_params_folders(_argv) + if params["help"]: + print_help(_argv[0]) + else: + # Add recursivity message + print("Running ", end='') + if params["recursive"]: + print("recursively ", end='') + # Running + if len(params["folders"]) >= 2: + print("on folder list:", params["folders"]) + for f in params["folders"]: + if params["recursive"]: + run_all_subfolders(f) + else: + update_folder(f) + elif len(params["folders"]) == 1: + print("on folder", params["folders"][0]) + if params["recursive"]: + run_all_subfolders(params["folders"][0]) + else: + update_folder(params["folders"][0]) + else: + print("on folder", os.path.abspath("./")) + if params["recursive"]: + run_all_subfolders(os.path.abspath("./")) + else: + update_folder(os.path.abspath("./")) + +# Group 2 will be the string, groups 1 and 3 will be the delimiters (" or ') +# See https://stackoverflow.com/questions/46967465/regex-match-text-in-either-single-or-double-quote +pattern_lua_quoted = re.compile( + r'(?:^|[\.=,{\(\s])' # Look for beginning of file or anything that isn't a function identifier + r'N?F?S\s*\(\s*' # Matches S, FS, NS or NFS function call + r'(["\'])((?:\\\1|(?:(?!\1)).)*)(\1)' # Quoted string + r'[\s,\)]', # End of call or argument + re.DOTALL) +# Handles the [[ ... ]] string delimiters +pattern_lua_bracketed = re.compile( + r'(?:^|[\.=,{\(\s])' # Same as for pattern_lua_quoted + r'N?F?S\s*\(\s*' # Same as for pattern_lua_quoted + r'\[\[(.*?)\]\]' # [[ ... ]] string delimiters + r'[\s,\)]', # Same as for pattern_lua_quoted + re.DOTALL) + +# Handles "concatenation" .. " of strings" +pattern_concat = re.compile(r'["\'][\s]*\.\.[\s]*["\']', re.DOTALL) + +# Handles a translation line in *.tr file. +# Group 1 is the source string left of the equals sign. +# Group 2 is the translated string, right of the equals sign. +pattern_tr = re.compile( + r'(.*)' # Source string + # the separating equals sign, if NOT preceded by @, unless + # that @ is preceded by another @ + r'(?:(?2.5 + if exc.errno == errno.EEXIST and os.path.isdir(path): + pass + else: raise + +# Converts the template dictionary to a text to be written as a file +# dKeyStrings is a dictionary of localized string to source file sets +# dOld is a dictionary of existing translations and comments from +# the previous version of this text +def strings_to_text(dkeyStrings, dOld, mod_name, header_comments, textdomain): + # if textdomain is specified, insert it at the top + if textdomain != None: + lOut = [textdomain] # argument is full textdomain line + # otherwise, use mod name as textdomain automatically + else: + lOut = [f"# textdomain: {mod_name}"] + if header_comments is not None: + lOut.append(header_comments) + + dGroupedBySource = {} + + for key in dkeyStrings: + sourceList = list(dkeyStrings[key]) + sourceString = "\n".join(sourceList) + listForSource = dGroupedBySource.get(sourceString, []) + listForSource.append(key) + dGroupedBySource[sourceString] = listForSource + + lSourceKeys = list(dGroupedBySource.keys()) + lSourceKeys.sort() + for source in lSourceKeys: + localizedStrings = dGroupedBySource[source] + if params["print-source"]: + if lOut[-1] != "": + lOut.append("") + lOut.append(source) + for localizedString in localizedStrings: + val = dOld.get(localizedString, {}) + translation = val.get("translation", "") + comment = val.get("comment") + if params["break-long-lines"] and len(localizedString) > doublespace_threshold and not lOut[-1] == "": + lOut.append("") + if comment != None and comment != "" and not comment.startswith("# textdomain:"): + lOut.append(comment) + lOut.append(f"{localizedString}={translation}") + if params["break-long-lines"] and len(localizedString) > doublespace_threshold: + lOut.append("") + + unusedExist = False + if not params["truncate-unused"]: + for key in dOld: + if key not in dkeyStrings: + val = dOld[key] + translation = val.get("translation") + comment = val.get("comment") + # only keep an unused translation if there was translated + # text or a comment associated with it + if translation != None and (translation != "" or comment): + if not unusedExist: + unusedExist = True + lOut.append("\n\n" + comment_unused + "\n") + if params["break-long-lines"] and len(key) > doublespace_threshold and not lOut[-1] == "": + lOut.append("") + if comment != None: + lOut.append(comment) + lOut.append(f"{key}={translation}") + if params["break-long-lines"] and len(key) > doublespace_threshold: + lOut.append("") + return "\n".join(lOut) + '\n' + +# Writes a template.txt file +# dkeyStrings is the dictionary returned by generate_template +def write_template(templ_file, dkeyStrings, mod_name): + # read existing template file to preserve comments + existing_template = import_tr_file(templ_file) + + text = strings_to_text(dkeyStrings, existing_template[0], mod_name, existing_template[2], existing_template[3]) + mkdir_p(os.path.dirname(templ_file)) + with open(templ_file, "wt", encoding='utf-8') as template_file: + template_file.write(text) + +# Gets all translatable strings from a lua file +def read_lua_file_strings(lua_file): + lOut = [] + with open(lua_file, encoding='utf-8') as text_file: + text = text_file.read() + + text = re.sub(pattern_concat, "", text) + + strings = [] + for s in pattern_lua_quoted.findall(text): + strings.append(s[1]) + for s in pattern_lua_bracketed.findall(text): + strings.append(s) + + for s in strings: + found_bad = pattern_bad_luastring.search(s) + if found_bad: + print("SYNTAX ERROR: Unescaped '@' in Lua string: " + s) + continue + s = s.replace('\\"', '"') + s = s.replace("\\'", "'") + s = s.replace("\n", "@n") + s = s.replace("\\n", "@n") + s = s.replace("=", "@=") + lOut.append(s) + return lOut + +# Gets strings from an existing translation file +# returns both a dictionary of translations +# and the full original source text so that the new text +# can be compared to it for changes. +# Returns also header comments in the third return value. +def import_tr_file(tr_file): + dOut = {} + text = None + in_header = True + header_comments = None + textdomain = None + if os.path.exists(tr_file): + with open(tr_file, "r", encoding='utf-8') as existing_file : + # save the full text to allow for comparison + # of the old version with the new output + text = existing_file.read() + existing_file.seek(0) + # a running record of the current comment block + # we're inside, to allow preceeding multi-line comments + # to be retained for a translation line + latest_comment_block = None + for line in existing_file.readlines(): + line = line.rstrip('\n') + # "##### not used anymore #####" comment + if line == comment_unused: + # Always delete the 'not used anymore' comment. + # It will be re-added to the file if neccessary. + latest_comment_block = None + if header_comments != None: + in_header = False + continue + # Comment lines + elif line.startswith("#"): + # Source file comments: ##[ file.lua ]## + if line.startswith(symbol_source_prefix) and line.endswith(symbol_source_suffix): + # This line marks the end of header comments. + if params["print-source"]: + in_header = False + # Remove those comments; they may be added back automatically. + continue + + # Store first occurance of textdomain + # discard all subsequent textdomain lines + if line.startswith("# textdomain:"): + if textdomain == None: + textdomain = line + continue + elif in_header: + # Save header comments (normal comments at top of file) + if not header_comments: + header_comments = line + else: + header_comments = header_comments + "\n" + line + else: + # Save normal comments + if line.startswith("# textdomain:") and textdomain == None: + textdomain = line + elif not latest_comment_block: + latest_comment_block = line + else: + latest_comment_block = latest_comment_block + "\n" + line + + continue + + match = pattern_tr.match(line) + if match: + # this line is a translated line + outval = {} + outval["translation"] = match.group(2) + if latest_comment_block: + # if there was a comment, record that. + outval["comment"] = latest_comment_block + latest_comment_block = None + in_header = False + + dOut[match.group(1)] = outval + return (dOut, text, header_comments, textdomain) + +# like os.walk but returns sorted filenames +def sorted_os_walk(folder): + tuples = [] + t = 0 + for root, dirs, files in os.walk(folder): + tuples.append( (root, dirs, files) ) + t = t + 1 + + tuples = sorted(tuples) + + paths_and_files = [] + f = 0 + + for tu in tuples: + root = tu[0] + dirs = tu[1] + files = tu[2] + files = sorted(files, key=str.lower) + for filename in files: + paths_and_files.append( (os.path.join(root, filename), filename) ) + f = f + 1 + return paths_and_files + +# Walks all lua files in the mod folder, collects translatable strings, +# and writes it to a template.txt file +# Returns a dictionary of localized strings to source file lists +# that can be used with the strings_to_text function. +def generate_template(folder, mod_name): + dOut = {} + paths_and_files = sorted_os_walk(folder) + for paf in paths_and_files: + fullpath_filename = paf[0] + filename = paf[1] + if fnmatch.fnmatch(filename, "*.lua"): + found = read_lua_file_strings(fullpath_filename) + if params["verbose"]: + print(f"{fullpath_filename}: {str(len(found))} translatable strings") + + for s in found: + sources = dOut.get(s, set()) + sources.add(os.path.relpath(fullpath_filename, start=folder)) + dOut[s] = sources + + if len(dOut) == 0: + return None + + # Convert source file set to list, sort it and add comment symbols. + # Needed because a set is unsorted and might result in unpredictable. + # output orders if any source string appears in multiple files. + for d in dOut: + sources = dOut.get(d, set()) + sources = sorted(list(sources), key=str.lower) + newSources = [] + for i in sources: + newSources.append(f"{symbol_source_prefix} {i} {symbol_source_suffix}") + dOut[d] = newSources + + templ_file = os.path.join(folder, "locale/template.txt") + write_template(templ_file, dOut, mod_name) + return dOut + +# Updates an existing .tr file, copying the old one to a ".old" file +# if any changes have happened +# dNew is the data used to generate the template, it has all the +# currently-existing localized strings +def update_tr_file(dNew, mod_name, tr_file): + if params["verbose"]: + print(f"updating {tr_file}") + + tr_import = import_tr_file(tr_file) + dOld = tr_import[0] + textOld = tr_import[1] + + textNew = strings_to_text(dNew, dOld, mod_name, tr_import[2], tr_import[3]) + + if textOld and textOld != textNew: + print(f"{tr_file} has changed.") + if params["old-file"]: + shutil.copyfile(tr_file, f"{tr_file}.old") + + with open(tr_file, "w", encoding='utf-8') as new_tr_file: + new_tr_file.write(textNew) + +# Updates translation files for the mod in the given folder +def update_mod(folder): + modname = get_modname(folder) + if modname is not None: + print(f"Updating translations for {modname}") + data = generate_template(folder, modname) + if data == None: + print(f"No translatable strings found in {modname}") + else: + for tr_file in get_existing_tr_files(folder): + update_tr_file(data, modname, os.path.join(folder, "locale/", tr_file)) + else: + print(f"Unable to determine the mod name in folder {folder}. Missing 'name' field in mod.conf.", file=_stderr) + exit(1) + +# Determines if the folder being pointed to is a mod or a mod pack +# and then runs update_mod accordingly +def update_folder(folder): + is_modpack = os.path.exists(os.path.join(folder, "modpack.txt")) or os.path.exists(os.path.join(folder, "modpack.conf")) + if is_modpack: + subfolders = [f.path for f in os.scandir(folder) if f.is_dir() and not f.name.startswith('.')] + for subfolder in subfolders: + update_mod(subfolder) + else: + update_mod(folder) + print("Done.") + +def run_all_subfolders(folder): + for modfolder in [f.path for f in os.scandir(folder) if f.is_dir() and not f.name.startswith('.')]: + update_folder(modfolder) + +main() diff --git a/pilot_skin_manager.lua b/pilot_skin_manager.lua index 1e3cbf3..1a4dac1 100644 --- a/pilot_skin_manager.lua +++ b/pilot_skin_manager.lua @@ -1,3 +1,4 @@ +local S = airutils.S airutils.pilot_textures = {"pilot_clothes1.png","pilot_clothes2.png","pilot_clothes3.png","pilot_clothes4.png", "pilot_novaskin_girl.png","pilot_novaskin_girl_steampunk.png","pilot_novaskin_girl_2.png","pilot_novaskin_girl_steampunk_2.png"} @@ -8,14 +9,14 @@ local curr_skin = "airutils:skin" minetest.register_chatcommand("au_uniform", { func = function(name, param) if skinsdb_mod_path and minetest.global_exists("armor") then - minetest.chat_send_player(name, "Sorry, but this module doesn't work when SkinsDb and Armor are instaled together.") + minetest.chat_send_player(name, S("Sorry, but this module doesn't work when SkinsDb and Armor are instaled together.")) else local player = minetest.get_player_by_name(name) if player then airutils.uniform_formspec(name) else - minetest.chat_send_player(name, "Something isn't working...") + minetest.chat_send_player(name, S("Something isn't working...")) end end end, @@ -128,11 +129,11 @@ function airutils.uniform_formspec(name) end basic_form = basic_form.."dropdown[0.5,0.5;4,0.8;textures;".. textures ..";0;false]" - basic_form = basic_form.."button[0.5,1.6;4,0.8;set_texture;Set Player Texture]" + basic_form = basic_form.."button[0.5,1.6;4,0.8;set_texture;" .. S("Set Player Texture") .. "]" minetest.show_formspec(name, "airutils:change", basic_form) else - minetest.chat_send_player(name, "The isn't activated as secure. Aborting") + minetest.chat_send_player(name, S("The isn't activated as secure. Aborting")) end end