add translation infrastructure

and add languages:
- Catalan
- German (CH)
- English (not sure this works yet)
- Spanish
This commit is contained in:
Luke aka SwissalpS 2024-04-22 02:52:29 +02:00
parent 8fc1f596d2
commit 76b9c933c5
8 changed files with 180 additions and 14 deletions

View File

@ -1,5 +1,6 @@
globals = {
"areas",
"hangglider",
}
read_globals = {

View File

@ -1,4 +1,6 @@
local S = hangglider.translator
local has_unifieddyes = minetest.get_modpath("unifieddyes")
local dye_colors = {
@ -19,6 +21,24 @@ local dye_colors = {
pink = "ff7f9f",
}
local translated_colors = {
white = S("white"),
grey = S("grey"),
dark_grey = S("dark_grey"),
black = S("black"),
violet = S("violet"),
blue = S("blue"),
cyan = S("cyan"),
dark_green = S("dark_green"),
green = S("green"),
yellow = S("yellow"),
brown = S("brown"),
orange = S("orange"),
red = S("red"),
magenta = S("magenta"),
pink = S("pink"),
}
local function get_dye_color(name)
local color
if has_unifieddyes then
@ -35,15 +55,13 @@ end
local function get_color_name(name)
name = string.gsub(name, "^dye:", "")
name = string.gsub(name, "_", " ")
name = string.gsub(name, "(%l)(%w*)", function(a, b) return string.upper(a)..b end)
return name
return translated_colors[name]
end
local function get_color_name_from_color(color)
for name, color_hex in pairs(dye_colors) do
if color == color_hex then
return name
return translated_colors[name]
end
end
end
@ -51,7 +69,7 @@ end
-- This recipe is just a placeholder
do
local item = ItemStack("hangglider:hangglider")
item:get_meta():set_string("description", "Colored Glider")
item:get_meta():set_string("description", S("Colored Glider"))
minetest.register_craft({
output = item:to_string(),
recipe = {"hangglider:hangglider", "group:dye"},
@ -85,7 +103,7 @@ minetest.register_on_craft(function(crafted_item, _, old_craft_grid)
return ItemStack({name = "hangglider:hangglider", wear = wear})
end
local meta = crafted_item:get_meta()
meta:set_string("description", color_name.." Glider")
meta:set_string("description", S("@1 Glider", color_name))
meta:set_string("inventory_image", "hangglider_item.png^(hangglider_color.png^[multiply:#"..color..")")
meta:set_string("hangglider_color", color)
crafted_item:set_wear(wear)

View File

@ -1,4 +1,9 @@
hangglider = {
translator = minetest.get_translator('hangglider'),
}
local S = hangglider.translator
local has_player_monoids = minetest.get_modpath("player_monoids")
local has_areas = minetest.get_modpath("areas")
@ -7,29 +12,31 @@ local enable_flak = has_areas and minetest.settings:get_bool("hangglider.enable_
local flak_warning_time = tonumber(minetest.settings:get("hangglider.flak_warning_time")) or 2
local hangglider_uses = tonumber(minetest.settings:get("hangglider.uses")) or 250
local flak_warning = "You have entered restricted airspace!\n"..
"You will be shot down in "..flak_warning_time.." seconds by anti-aircraft guns!"
local flak_warning = S("You have entered restricted airspace!@n"
.. "You will be shot down in @1 seconds by anti-aircraft guns!",
flak_warning_time)
local hanggliding_players = {}
local hud_overlay_ids = {}
if enable_flak then
minetest.register_chatcommand("area_flak", {
params = "<ID>",
description = "Toggle airspace restrictions for area <ID>",
params = S("<ID>"),
description = S("Toggle airspace restrictions for area <ID>."),
func = function(name, param)
local id = tonumber(param)
if not id then
return false, "Invalid usage, see /help area_flak."
return false, S("Invalid usage, see /help area_flak.")
end
if not areas:isAreaOwner(id, name) then
return false, "Area "..id.." does not exist or is not owned by you."
return false, S("Area @1 does not exist or is not owned by you.", id)
end
local open = not areas.areas[id].flak
-- Save false as nil to avoid inflating the DB.
areas.areas[id].flak = open or nil
areas:save()
return true, "Area "..id.." airspace "..(open and "closed" or "opened")
return true, S("Area @1 airspace is @2.", id,
open and S("closed") or S("opened"))
end
})
end
@ -236,7 +243,7 @@ minetest.register_entity("hangglider:glider", {
})
minetest.register_tool("hangglider:hangglider", {
description = "Glider",
description = S("Glider"),
inventory_image = "hangglider_item.png",
sound = {breaks = "default_tool_breaks"},
on_use = hangglider_use,

28
locale/hangglider.ca.tr Normal file
View File

@ -0,0 +1,28 @@
# textdomain: hangglider
white=blanc
grey=gris
dark_grey=gris fosc
black=negre
violet=violeta
blue=blau
cyan=cian
dark_green=verd fosc
green=verd
yellow=groc
brown=marró
orange=taronja
red=vermell
magenta=magenta
pink=rosa
Colored Glider=Planador de color
@1 Glider=Planador @1
You have entered restricted airspace!@@You will be shot down in @1 seconds by anti-aircraft guns!=Has entrat a l'espai aeri restringit!@@Seràs abatut en @1 segons per canons antiaeris!
<ID>=
Toggle airspace restrictions for area <ID>.=Activa o desactiva les restriccions d'espai aeri per a l'àrea <ID>.
Invalid usage, see /help area_flak.=Ús no vàlid, consulta /help area_flak.
Area @1 does not exist or is not owned by you.=L'àrea @1 no existeix o no és propietat teva.
Area @1 airspace is @2.=L'àrea @1 espai aeri és @2.
closed=tancat
opened=obert
Glider=Planador

28
locale/hangglider.de.tr Normal file
View File

@ -0,0 +1,28 @@
# textdomain: hangglider
white=Weisser
grey=Grauer
dark_grey=Dunkelgrauer
black=Schwarzer
violet=Violeter
blue=Blauer
cyan=Cyan farbener
dark_green=Dunkelgrüner
green=Grüner
yellow=Gelber
brown=Brauner
orange=Orange farbener
red=Roter
magenta=Magenta farbener
pink=Rosa
Colored Glider=Farbiger Gleitschirm
@1 Glider=@1 Gleitschirm
You have entered restricted airspace!@@You will be shot down in @1 seconds by anti-aircraft guns!=Du bist in eingeschränktem Luftraum eingedrungen!@nDu wirst in @1 Sekunden von FLAK abgeschossen.
<ID>=
Toggle airspace restrictions for area <ID>.=Luftraumbeschränkungen für Gebiet <ID> umschalten.
Invalid usage, see /help area_flak.=Ungültige Verwendung, siehe /help area_flak.=
Area @1 does not exist or is not owned by you.=Gebiet @1 existiert nicht oder es gehört dir nicht.
Area @1 airspace is @2.=Gebiet @1 Luftraum ist @2.
closed=eingeschränkt
opened=geöffnet
Glider=Gleitschirm

28
locale/hangglider.en.tr Normal file
View File

@ -0,0 +1,28 @@
# textdomain: hangglider
white=White
grey=Grey
dark_grey=Dark Grey
black=Black
violet=Violet
blue=Blue
cyan=Cyan
dark_green=Dark Green
green=Green
yellow=Yellow
brown=Brown
orange=Orange
red=Red
magenta=Magenta
pink=Pink
Colored Glider=
@1 Glider=
You have entered restricted airspace!@@You will be shot down in @1 seconds by anti-aircraft guns!=
<ID>=
Toggle airspace restrictions for area <ID>.=
Invalid usage, see /help area_flak.=
Area @1 does not exist or is not owned by you.=
Area @1 airspace is @2.=
closed=
opened=
Glider=

28
locale/hangglider.es.tr Normal file
View File

@ -0,0 +1,28 @@
# textdomain: hangglider
white=blanco
grey=gris
dark_grey=gris oscuro
black=negro
violet=violeta
blue=azul
cyan=cian
dark_green=verde oscuro
green=verde
yellow=amarillo
brown=marrón
orange=naranja
red=rojo
magenta=magenta
pink=rosa
Colored Glider=Planeador Colorizado
@1 Glider=Planeador @1
You have entered restricted airspace!@@You will be shot down in @1 seconds by anti-aircraft guns!=¡Has entrado en espacio aéreo restringido!@n¡Serás derribado en @1 segundos por cañones antiaéreos!
<ID>=
Toggle airspace restrictions for area <ID>.=Alternar restricciones de espacio aéreo para el área <ID>.
Invalid usage, see /help area_flak.=Uso no válido, consulta /help area_flak.
Area @1 does not exist or is not owned by you.=El área @1 no existe o no es tuya.
Area @1 airspace is @2.=Área @1 espacio aéreo está @2.
closed=cerrado
opened=abierto
Glider=Planeador

28
locale/template.txt Normal file
View File

@ -0,0 +1,28 @@
# textdomain: hangglider
white=
grey=
dark_grey=
black=
violet=
blue=
cyan=
dark_green=
green=
yellow=
brown=
orange=
red=
magenta=
pink=
Colored Glider=
@1 Glider=
You have entered restricted airspace!@@You will be shot down in @1 seconds by anti-aircraft guns!=
<ID>=
Toggle airspace restrictions for area <ID>.=
Invalid usage, see /help area_flak.=
Area @1 does not exist or is not owned by you.=
Area @1 airspace is @2.=
closed=
opened=
Glider=