i18n translation support

This commit is contained in:
Jaidyn Ann 2024-08-13 00:43:56 -05:00
parent b2c53ad032
commit 2679114d29
2 changed files with 20 additions and 9 deletions

View File

@ -18,13 +18,14 @@ fs_themes.themes = {}
local storage = minetest.get_mod_storage() local storage = minetest.get_mod_storage()
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())
local S = minetest.get_translator(minetest.get_current_modname());
-- Set a players theme by a registered themes name. -- Set a players theme by a registered themes name.
-- If dont_save is provided, the players default theme wont change. -- If dont_save is provided, the players default theme wont change.
function fs_themes.set_theme(player, theme_name, dont_save) function fs_themes.set_theme(player, theme_name, dont_save)
if not fs_themes.themes[theme_name] then 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 return false
elseif not dont_save then elseif not dont_save then
storage:set_string(player:get_player_name(), theme_name) storage:set_string(player:get_player_name(), theme_name)
@ -45,7 +46,7 @@ end
minetest.register_chatcommand( minetest.register_chatcommand(
"themes", "themes",
{ {
description = "Lists available GUI (Formspecs) themes.", description = S("Lists available GUI (Formspecs) themes."),
func = function(name, param) func = function(name, param)
local ret = nil local ret = nil
for name,fs in pairs(fs_themes.themes) do for name,fs in pairs(fs_themes.themes) do
@ -56,7 +57,7 @@ minetest.register_chatcommand(
end end
end end
if ret == nil then if ret == nil then
ret = "No themes are installed!" ret = S("No themes are installed!")
end end
return true, ret return true, ret
end end
@ -67,13 +68,13 @@ minetest.register_chatcommand(
minetest.register_chatcommand( minetest.register_chatcommand(
"set_theme", "set_theme",
{ {
params = "<theme_name>", params = S("<theme_name>"),
description = "Sets your theme for GUI (Formspecs) windows.", description = S("Sets your theme for GUI (Formspecs) windows."),
func = function(name, param) func = function(name, param)
if fs_themes.set_theme(minetest.get_player_by_name(name), param) then 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 elseif param ~= "" then
return false, string.format("No such theme “%s”.", param) return false, string.format(S("No such theme “%s”."), param)
else else
return false return false
end end
@ -98,7 +99,7 @@ minetest.register_on_joinplayer(
if player_theme ~= "" and not fs_themes.set_theme(player, player_theme) then if player_theme ~= "" and not fs_themes.set_theme(player, player_theme) then
minetest.chat_send_player( minetest.chat_send_player(
player_name, 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 = "" player_theme = ""
storage:set_string(player_name, "") storage:set_string(player_name, "")
end 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 for _, file_name in pairs(theme_file_paths) do
local fs_file, open_err = io.open(theme_dir_path .. file_name, "r") local fs_file, open_err = io.open(theme_dir_path .. file_name, "r")
if fs_file == nil then 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 return false
end end

10
locale/template.txt Normal file
View File

@ -0,0 +1,10 @@
# textdomain: fs_themes
Theme “%s” was not found.=
Lists available GUI (Formspecs) themes.=
No themes are installed!=
<theme_name>=
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=