Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translation infrastructure #18

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
globals = {
"areas",
"hangglider",
}

read_globals = {
Expand Down
30 changes: 24 additions & 6 deletions crafts.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

local S = hangglider.translator

local has_unifieddyes = minetest.get_modpath("unifieddyes")

local dye_colors = {
Expand All @@ -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
Expand All @@ -35,23 +55,21 @@ 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

-- 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"},
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 15 additions & 8 deletions init.lua
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions locale/hangglider.ca.tr
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions locale/hangglider.de.tr
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions locale/hangglider.es.tr
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions locale/template.txt
Original file line number Diff line number Diff line change
@@ -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=