From d0569a3850cc1348c9d50ea3c89f94481cc54893 Mon Sep 17 00:00:00 2001 From: Christian Aistleitner Date: Fri, 8 Nov 2024 12:19:06 +0100 Subject: [PATCH] Internationalize libri page content --- api/libri.lua | 24 ++++++++++++++++++++---- locale/libri/README.txt | 7 +++++++ locale/template.txt | 12 ++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 locale/libri/README.txt diff --git a/api/libri.lua b/api/libri.lua index 71276b1..2712095 100644 --- a/api/libri.lua +++ b/api/libri.lua @@ -2,6 +2,9 @@ -- Libri -- ----------- +-- Load support for MT game translation. +local S = minetest.get_translator("animalia") + local libri = {} 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 local mob_name = mob:split(":")[2] 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 offset_y = offset_y + 2 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 = (def.font_size or 16) * font_size_x if def.file then - local filename = path .. "/libri/" .. def.file - local file = io.open(filename) + local 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 + -- Some content was found, so we load and display it. local text = "" for line in file:lines() do text = text .. line .. "\n" @@ -427,7 +443,7 @@ local function iterate_libri_images() if info.element_type == "image" then info.text = biome_cubes[spawn_biome] else - info.text = correct_string(spawn_biome) + info.text = S(correct_string(spawn_biome)) end end end diff --git a/locale/libri/README.txt b/locale/libri/README.txt new file mode 100644 index 0000000..268eec7 --- /dev/null +++ b/locale/libri/README.txt @@ -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). diff --git a/locale/template.txt b/locale/template.txt index f8ff811..ee5954e 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -10,20 +10,26 @@ Cat= Cat Toy= Chicken Egg= Chicken= +Coniferous Forest= Contains a @1= Cooked Mutton= Cooked Porkchop= Cooked Poultry= Cooked Rat= Cow= +Deciduous Forest= +Deciduous Forest Ocean= +Deciduous Forest Shore= Feather= Female= Fox= Fried @1= Frog= +Grassland= Grizzly Bear= Guano= Horse= +Icesheet Ocean= Lasso= Leather= Male= @@ -31,6 +37,9 @@ Nametag= Opossum= Owl= Pig= +Rainforest Ocean= +Rainforest= +Rainforest Swamp= Rat= Raw Beef= Raw Mutton= @@ -40,6 +49,8 @@ Raw Rat= Raw Venison= Reindeer= Saddle= +Savanna Ocean= +Savanna= Shears= Sheep= Song Bird Egg= @@ -49,6 +60,7 @@ Steak= This @1 already contains a @2= Tropical Fish= Trust= +Tundra Ocean= Turkey Egg= Turkey= Venison Steak=