From 2679114d2913dda08ed681e8293e46ab8835955e Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:43:56 -0500 Subject: [PATCH] i18n translation support --- init.lua | 19 ++++++++++--------- locale/template.txt | 10 ++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 locale/template.txt diff --git a/init.lua b/init.lua index 719731d..926cb67 100644 --- a/init.lua +++ b/init.lua @@ -18,13 +18,14 @@ fs_themes.themes = {} local storage = minetest.get_mod_storage() local modpath = minetest.get_modpath(minetest.get_current_modname()) +local S = minetest.get_translator(minetest.get_current_modname()); -- Set a player’s theme by a registered theme’s name. -- If dont_save is provided, the player’s default theme won’t change. function fs_themes.set_theme(player, theme_name, dont_save) if not fs_themes.themes[theme_name] then - minetest.log("warning", string.format("Theme “%s” was not found.", theme_name)) + minetest.log("warning", string.format(S("Theme “%s” was not found."), theme_name)) return false elseif not dont_save then storage:set_string(player:get_player_name(), theme_name) @@ -45,7 +46,7 @@ end minetest.register_chatcommand( "themes", { - description = "Lists available GUI (Formspecs) themes.", + description = S("Lists available GUI (Formspecs) themes."), func = function(name, param) local ret = nil for name,fs in pairs(fs_themes.themes) do @@ -56,7 +57,7 @@ minetest.register_chatcommand( end end if ret == nil then - ret = "No themes are installed!" + ret = S("No themes are installed!") end return true, ret end @@ -67,13 +68,13 @@ minetest.register_chatcommand( minetest.register_chatcommand( "set_theme", { - params = "", - description = "Sets your theme for GUI (Formspecs) windows.", + params = S(""), + description = S("Sets your theme for GUI (Formspecs) windows."), func = function(name, param) if fs_themes.set_theme(minetest.get_player_by_name(name), param) then - return true, "Theme set!" + return true, S("Theme set!") elseif param ~= "" then - return false, string.format("No such theme “%s”.", param) + return false, string.format(S("No such theme “%s”."), param) else return false end @@ -98,7 +99,7 @@ minetest.register_on_joinplayer( if player_theme ~= "" and not fs_themes.set_theme(player, player_theme) then minetest.chat_send_player( player_name, - string.format("The theme “%s” no longer exists! Resetting preference.", player_theme)) + string.format(S("The theme “%s” no longer exists! Resetting preference."), player_theme)) player_theme = "" storage:set_string(player_name, "") end @@ -116,7 +117,7 @@ local theme_file_paths = minetest.get_dir_list(theme_dir_path, false) for _, file_name in pairs(theme_file_paths) do local fs_file, open_err = io.open(theme_dir_path .. file_name, "r") if fs_file == nil then - minetest.log("warning", string.format("Theme “%s” could not be opened: %s", name, open_err)) + minetest.log("warning", string.format(S("Theme “%s” could not be opened: %s"), name, open_err)) return false end diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..8dadc7b --- /dev/null +++ b/locale/template.txt @@ -0,0 +1,10 @@ +# textdomain: fs_themes +Theme “%s” was not found.= +Lists available GUI (Formspecs) themes.= +No themes are installed!= += +Sets your theme for GUI (Formspecs) windows.= +Theme set!= +No such theme “%s”.= +The theme “%s” no longer exists! Resetting preference.= +Theme “%s” could not be opened: %s=