Internationalize libri page content

This commit is contained in:
Christian Aistleitner 2024-11-08 12:19:06 +01:00
parent 4107115ddc
commit d0569a3850
3 changed files with 39 additions and 4 deletions

View file

@ -2,6 +2,9 @@
-- Libri -- -- Libri --
----------- -----------
-- Load support for MT game translation.
local S = minetest.get_translator("animalia")
local libri = {} local libri = {}
local path = minetest.get_modpath(minetest.get_current_modname()) local path = minetest.get_modpath(minetest.get_current_modname())
@ -281,7 +284,7 @@ function libri.generate_list(meta, offset, start_iter)
if i > start_iter then if i > start_iter then
local mob_name = mob:split(":")[2] local mob_name = mob:split(":")[2]
local offset_txt = offset_x .. "," .. offset_y local offset_txt = offset_x .. "," .. offset_y
local element = "button[" .. offset_txt .. ";4,1;btn_" .. mob_name .. ";" .. correct_string(mob_name) .. "]" local element = "button[" .. offset_txt .. ";4,1;btn_" .. mob_name .. ";" .. S(correct_string(mob_name)) .. "]"
elements = elements .. element elements = elements .. element
offset_y = offset_y + 2 offset_y = offset_y + 2
if offset_y > 7.5 then if offset_y > 7.5 then
@ -310,9 +313,22 @@ function libri.render_element(def, meta, playername)
local font_size_x = (animalia.libri_font_size[playername] or 1) local font_size_x = (animalia.libri_font_size[playername] or 1)
local font_size = (def.font_size or 16) * font_size_x local font_size = (def.font_size or 16) * font_size_x
if def.file then if def.file then
local filename = path .. "/libri/" .. def.file local filename
local file = io.open(filename) local file
-- We try to find localized content first and fall back to default content.
local player_information = core.get_player_information(playername)
if player_information and player_information.lang_code then
local lang_code = player_information.lang_code
filename = path .. "/locale/libri/" .. lang_code .. "/" .. def.file
file = io.open(filename)
end
if not file then
-- No localized content available. So we try the default content
filename = path .. "/libri/" .. def.file
file = io.open(filename)
end
if file then if file then
-- Some content was found, so we load and display it.
local text = "" local text = ""
for line in file:lines() do for line in file:lines() do
text = text .. line .. "\n" text = text .. line .. "\n"
@ -427,7 +443,7 @@ local function iterate_libri_images()
if info.element_type == "image" then if info.element_type == "image" then
info.text = biome_cubes[spawn_biome] info.text = biome_cubes[spawn_biome]
else else
info.text = correct_string(spawn_biome) info.text = S(correct_string(spawn_biome))
end end
end end
end end

7
locale/libri/README.txt Normal file
View file

@ -0,0 +1,7 @@
The screen estate for text in the rendered book pages is limited.
To avoid broken lines, use only 44 (or less) characters per line.
To avoid scrollbars (which are unusable due to the once-per-second refresh),
only use 10 (or less) lines per file.
(In the home page, you can up to 14 lines).

View file

@ -10,20 +10,26 @@ Cat=
Cat Toy= Cat Toy=
Chicken Egg= Chicken Egg=
Chicken= Chicken=
Coniferous Forest=
Contains a @1= Contains a @1=
Cooked Mutton= Cooked Mutton=
Cooked Porkchop= Cooked Porkchop=
Cooked Poultry= Cooked Poultry=
Cooked Rat= Cooked Rat=
Cow= Cow=
Deciduous Forest=
Deciduous Forest Ocean=
Deciduous Forest Shore=
Feather= Feather=
Female= Female=
Fox= Fox=
Fried @1= Fried @1=
Frog= Frog=
Grassland=
Grizzly Bear= Grizzly Bear=
Guano= Guano=
Horse= Horse=
Icesheet Ocean=
Lasso= Lasso=
Leather= Leather=
Male= Male=
@ -31,6 +37,9 @@ Nametag=
Opossum= Opossum=
Owl= Owl=
Pig= Pig=
Rainforest Ocean=
Rainforest=
Rainforest Swamp=
Rat= Rat=
Raw Beef= Raw Beef=
Raw Mutton= Raw Mutton=
@ -40,6 +49,8 @@ Raw Rat=
Raw Venison= Raw Venison=
Reindeer= Reindeer=
Saddle= Saddle=
Savanna Ocean=
Savanna=
Shears= Shears=
Sheep= Sheep=
Song Bird Egg= Song Bird Egg=
@ -49,6 +60,7 @@ Steak=
This @1 already contains a @2= This @1 already contains a @2=
Tropical Fish= Tropical Fish=
Trust= Trust=
Tundra Ocean=
Turkey Egg= Turkey Egg=
Turkey= Turkey=
Venison Steak= Venison Steak=