Translation support

This commit is contained in:
Paul Ouellette 2020-03-24 11:38:03 -04:00
parent 4fd22706bd
commit fbcf555aad
2 changed files with 85 additions and 30 deletions

View file

@ -180,7 +180,7 @@ end
local function item_button_fs(fs, x, y, item, element_name, groups) local function item_button_fs(fs, x, y, item, element_name, groups)
table.insert(fs, ("item_image_button[%s,%s;1.05,1.05;%s;%s;%s]") table.insert(fs, ("item_image_button[%s,%s;1.05,1.05;%s;%s;%s]")
:format(x, y, item, element_name, groups and "\nG" or "")) :format(x, y, item, element_name, groups and "\n"..esc(S("G")) or ""))
local tooltip local tooltip
if groups then if groups then
@ -192,15 +192,15 @@ local function item_button_fs(fs, x, y, item, element_name, groups)
table.insert(groupstr, minetest.colorize("yellow", group)) table.insert(groupstr, minetest.colorize("yellow", group))
end end
groupstr = table.concat(groupstr, ", ") groupstr = table.concat(groupstr, ", ")
tooltip = "Any item belonging to the group(s): "..groupstr tooltip = S("Any item belonging to the group(s): @1", groupstr)
end end
elseif is_fuel(item) then elseif is_fuel(item) then
local itemdef = minetest.registered_items[item] local itemdef = minetest.registered_items[item]
local desc = itemdef and itemdef.description or "Unknown Item" local desc = itemdef and itemdef.description or S("Unknown Item")
tooltip = desc.."\n"..minetest.colorize("orange", "Fuel") tooltip = desc.."\n"..minetest.colorize("orange", S("Fuel"))
end end
if tooltip then if tooltip then
table.insert(fs, ("tooltip[%s;%s]"):format(element_name, tooltip)) table.insert(fs, ("tooltip[%s;%s]"):format(element_name, esc(tooltip)))
end end
end end
@ -216,20 +216,22 @@ local function recipe_fs(fs, data)
width = #recipe.items <= 4 and 2 or math.min(3, #recipe.items) width = #recipe.items <= 4 and 2 or math.min(3, #recipe.items)
end end
table.insert(fs, ("label[5.5,6.6;%s %d of %d]") table.insert(fs, ("label[5.5,6.6;%s]"):format(esc(data.show_usages
:format(data.show_usages and "Usage" or "Recipe", data.rnum, #data.recipes)) and S("Usage @1 of @2", data.rnum, #data.recipes)
or S("Recipe @1 of @2", data.rnum, #data.recipes))))
if #data.recipes > 1 then if #data.recipes > 1 then
table.insert(fs, table.insert(fs,
"image_button[5.5,7.2;0.8,0.8;craftguide_prev_icon.png;recipe_prev;]".. "image_button[5.5,7.2;0.8,0.8;craftguide_prev_icon.png;recipe_prev;]"..
"image_button[6.2,7.2;0.8,0.8;craftguide_next_icon.png;recipe_next;]".. "image_button[6.2,7.2;0.8,0.8;craftguide_next_icon.png;recipe_next;]"..
"tooltip[recipe_prev;Previous recipe]".. "tooltip[recipe_prev;"..esc(S("Previous recipe")).."]"..
"tooltip[recipe_next;Next recipe]") "tooltip[recipe_next;"..esc(S("Next recipe")).."]")
end end
local rows = math.ceil(table.maxn(recipe.items) / width) local rows = math.ceil(table.maxn(recipe.items) / width)
if width > 3 or rows > 3 then if width > 3 or rows > 3 then
table.insert(fs, "label[0,6.6;Recipe is too big to be displayed.]") table.insert(fs, ("label[0,6.6;%s]")
:format(esc(S("Recipe is too big to be displayed."))))
return return
end end
@ -247,9 +249,9 @@ local function recipe_fs(fs, data)
if shapeless or recipe.method == "cooking" then if shapeless or recipe.method == "cooking" then
table.insert(fs, ("image[3.2,6.1;0.5,0.5;craftguide_%s.png]") table.insert(fs, ("image[3.2,6.1;0.5,0.5;craftguide_%s.png]")
:format(shapeless and "shapeless" or "furnace")) :format(shapeless and "shapeless" or "furnace"))
local tooltip = shapeless and "Shapeless" or local tooltip = shapeless and S("Shapeless") or
"Cooking time: "..minetest.colorize("yellow", cooktime) S("Cooking time: @1", minetest.colorize("yellow", cooktime))
table.insert(fs, "tooltip[3.2,6.1;0.5,0.5;"..tooltip.."]") table.insert(fs, "tooltip[3.2,6.1;0.5,0.5;"..esc(tooltip).."]")
end end
table.insert(fs, "image[3,6.6;1,1;sfinv_crafting_arrow.png]") table.insert(fs, "image[3,6.6;1,1;sfinv_crafting_arrow.png]")
@ -262,8 +264,7 @@ local function get_formspec(player)
data.pagemax = math.max(1, math.ceil(#data.items / 32)) data.pagemax = math.max(1, math.ceil(#data.items / 32))
local fs = {} local fs = {}
table.insert(fs, ("field[0.3,4.2;2.8,1.2;filter;;%s]") table.insert(fs, "field[0.3,4.2;2.8,1.2;filter;;"..esc(data.filter).."]")
:format(minetest.formspec_escape(data.filter)))
table.insert(fs, ("label[5.8,4.15;%s / %d]") table.insert(fs, ("label[5.8,4.15;%s / %d]")
:format(minetest.colorize("yellow", data.pagenum), data.pagemax)) :format(minetest.colorize("yellow", data.pagenum), data.pagemax))
table.insert(fs, table.insert(fs,
@ -271,14 +272,14 @@ local function get_formspec(player)
"image_button[3.25,4.05;0.8,0.8;craftguide_clear_icon.png;clear;]".. "image_button[3.25,4.05;0.8,0.8;craftguide_clear_icon.png;clear;]"..
"image_button[5,4.05;0.8,0.8;craftguide_prev_icon.png;prev;]".. "image_button[5,4.05;0.8,0.8;craftguide_prev_icon.png;prev;]"..
"image_button[7.25,4.05;0.8,0.8;craftguide_next_icon.png;next;]".. "image_button[7.25,4.05;0.8,0.8;craftguide_next_icon.png;next;]"..
"tooltip[search;Search]".. "tooltip[search;"..esc(S("Search")).."]"..
"tooltip[clear;Reset]".. "tooltip[clear;"..esc(S("Reset")).."]"..
"tooltip[prev;Previous page]".. "tooltip[prev;"..esc(S("Previous page")).."]"..
"tooltip[next;Next page]".. "tooltip[next;"..esc(S("Next page")).."]"..
"field_close_on_enter[filter;false]") "field_close_on_enter[filter;false]")
if #data.items == 0 then if #data.items == 0 then
table.insert(fs, "label[3,2;No items to show.]") table.insert(fs, "label[3,2;"..esc(S("No items to show.")).."]")
else else
local first_item = (data.pagenum - 1) * 32 local first_item = (data.pagenum - 1) * 32
for i = first_item, first_item + 31 do for i = first_item, first_item + 31 do
@ -292,14 +293,12 @@ local function get_formspec(player)
end end
end end
if data.recipes then
if #data.recipes > 0 then if #data.recipes > 0 then
recipe_fs(fs, data) recipe_fs(fs, data)
elseif data.show_usages then elseif data.prev_item then
table.insert(fs, "label[2,6.6;No usages.\nClick again to show recipes.]") table.insert(fs, ("label[2,6.6;%s]"):format(esc(data.show_usages
else and S("No usages.\nClick again to show recipes.")
table.insert(fs, "label[2,6.6;No recipes.\nClick again to show usages.]") or S("No recipes.\nClick again to show usages."))))
end
end end
return table.concat(fs) return table.concat(fs)
@ -327,7 +326,7 @@ local function reset_data(data)
data.filter = "" data.filter = ""
data.pagenum = 1 data.pagenum = 1
data.prev_item = nil data.prev_item = nil
data.recipes = nil data.recipes = {}
data.items = init_items data.items = init_items
end end
@ -406,6 +405,7 @@ minetest.register_on_joinplayer(function(player)
player_data[name] = { player_data[name] = {
filter = "", filter = "",
pagenum = 1, pagenum = 1,
recipes = {},
items = init_items items = init_items
} }
end) end)
@ -416,7 +416,7 @@ minetest.register_on_leaveplayer(function(player)
end) end)
sfinv.register_page("mtg_craftguide:craftguide", { sfinv.register_page("mtg_craftguide:craftguide", {
title = "Craft Guide", title = esc(S("Craft Guide")),
get = function(self, player, context) get = function(self, player, context)
return sfinv.make_formspec(player, context, get_formspec(player)) return sfinv.make_formspec(player, context, get_formspec(player))
end, end,

View file

@ -0,0 +1,55 @@
# textdomain: mtg_craftguide
### init.lua ###
Any black dye=
Any black flower=
Any blue dye=
Any blue flower=
Any brown dye=
Any coal=
Any cyan dye=
Any dark green dye=
Any dark grey dye=
Any green dye=
Any green flower=
Any grey dye=
Any item belonging to the group(s): @1=
Any kind of stone block=
Any magenta dye=
Any orange dye=
Any orange flower=
Any pink dye=
Any red dye=
Any red flower=
Any sand=
Any stick=
Any vessel=
Any violet dye=
Any violet flower=
Any white dye=
Any white flower=
Any wood planks=
Any wool=
Any yellow dye=
Any yellow flower=
Cooking time: @1=
Craft Guide=
Fuel=
# Label for group ingredients
G=
Next page=
Next recipe=
No items to show.=
No recipes.@nClick again to show usages.=
No usages.@nClick again to show recipes.=
Previous page=
Previous recipe=
Recipe @1 of @2=
Recipe is too big to be displayed.=
Reset=
Search=
Shapeless=
Unknown Item=
Usage @1 of @2=