Add localization support...

Breaks compatibility with Minetever versions 0.4.x
This commit is contained in:
Jordan Irwin 2021-07-12 20:02:03 -07:00
parent 50db695476
commit df3428059c
6 changed files with 86 additions and 36 deletions

View file

@ -1,22 +1,18 @@
## Cleaner mod for Minetest ## Cleaner mod for Minetest
---
### Description: ### Description:
A [Minetest][] mod that can be used to remove/replace unknown entities, nodes, & items. Originally forked from [PilzAdam's ***clean*** mod][f.pilzadam]. A [Minetest][] mod that can be used to remove/replace unknown entities, nodes, & items. Originally forked from [PilzAdam's ***clean*** mod][f.pilzadam].
---
### Licensing: ### Licensing:
[MIT](LICENSE.txt) [MIT](LICENSE.txt)
---
### Requirements: ### Requirements:
- Minetest 0.4.16 or newer - Minetest minimum version: 5.0
- Depends: none - Depends: none
---
### Usage: ### Usage:
Registering items, entities, etc. for cleaning can be done in `cleaner.json` in the world directory. If it does not exist it will be created automatically when the server is started. Registering items, entities, etc. for cleaning can be done in `cleaner.json` in the world directory. If it does not exist it will be created automatically when the server is started.
@ -72,7 +68,6 @@ cleaner.unsafe
- default: false - default: false
``` ```
---
### Links: ### Links:
- [![ContentDB](https://content.minetest.net/packages/AntumDeluge/cleaner/shields/title/)][ContentDB] - [![ContentDB](https://content.minetest.net/packages/AntumDeluge/cleaner/shields/title/)][ContentDB]

View file

@ -1,4 +1,3 @@
TODO: TODO:
- add localization support
- update world file when chat commands are used - update world file when chat commands are used

View file

@ -11,6 +11,7 @@ v1.2
- added setting for enabling "unsafe" methods & commands - added setting for enabling "unsafe" methods & commands
- added support for unregistering ores - added support for unregistering ores
- all types are loaded from <world_path>/cleaner.json file - all types are loaded from <world_path>/cleaner.json file
- added localization support
v1.1 v1.1
---- ----

View file

@ -4,6 +4,9 @@
-- @topic commands -- @topic commands
local S = core.get_translator(cleaner.modname)
local function pos_list(ppos, radius) local function pos_list(ppos, radius)
local plist = {} local plist = {}
@ -19,14 +22,37 @@ local function pos_list(ppos, radius)
end end
local help_repo = {
entity = {
remove_params = "<" .. S("entity") .. "> [" .. S("radius") .. "]",
},
node = {
remove_params = "<" .. S("node") .. "> [" .. S("radius") .. "]",
replace_params = "<" .. S("old_node") .. "> <" .. S("new_node") .. "> [" .. S("radius") .. "]",
},
item = {
replace_params = "<" .. S("old_item") .. "> <" .. S("new_item") .. ">",
},
ore = {
remove_params = "<" .. S("ore") .. ">",
},
param = {
missing = S("Missing parameter."),
excess = S("Too many parameters."),
mal_radius = S("Radius must be a number."),
opt_radius = "[" .. S("radius") .. "]",
},
}
--- Removes nearby entities. --- Removes nearby entities.
-- --
-- @chatcmd remove_entity -- @chatcmd remove_entity
-- @param entity Entity technical name. -- @param entity Entity technical name.
core.register_chatcommand("remove_entity", { core.register_chatcommand("remove_entity", {
privs = {server=true}, privs = {server=true},
description = "Remove an entity from game.", description = S("Remove an entity from game."),
params = "<entity> [radius]", params = help_repo.entity.remove_params,
func = function(name, param) func = function(name, param)
local entity local entity
local radius = 100 local radius = 100
@ -39,9 +65,9 @@ core.register_chatcommand("remove_entity", {
end end
if not entity or entity:trim() == "" then if not entity or entity:trim() == "" then
return false, "Must supply entity name." return false, help_repo.param.missing
elseif not radius then elseif not radius then
return false, "Radius must be a number." return false, help_repo.param.mal_radius
end end
local player = core.get_player_by_name(name) local player = core.get_player_by_name(name)
@ -70,8 +96,8 @@ core.register_chatcommand("remove_entity", {
-- @param node Node technical name. -- @param node Node technical name.
core.register_chatcommand("remove_node", { core.register_chatcommand("remove_node", {
privs = {server=true}, privs = {server=true},
description = "Remove a node from game.", description = S("Remove a node from game."),
params = "<node> [radius]", params = help_repo.node.remove_params,
func = function(name, param) func = function(name, param)
local nname local nname
local radius = 100 local radius = 100
@ -84,9 +110,9 @@ core.register_chatcommand("remove_node", {
end end
if not nname or nname:trim() == "" then if not nname or nname:trim() == "" then
return false, "Must supply node name." return false, help_repo.param.missing
elseif not radius then elseif not radius then
return false, "Radius must be a number." return false, help_repo.param.mal_radius
end end
local ppos = core.get_player_by_name(name):get_pos() local ppos = core.get_player_by_name(name):get_pos()
@ -104,7 +130,7 @@ core.register_chatcommand("remove_node", {
local function replace_item(src, tgt) local function replace_item(src, tgt)
if not core.registered_items[tgt] then if not core.registered_items[tgt] then
return false, "Cannot use unknown item \"" .. tgt .. "\" as replacement." return false, S('Cannot use unknown item "@1" as replacement.', tgt)
end end
if core.registered_items[src] then if core.registered_items[src] then
@ -124,11 +150,11 @@ end
-- @param new_item Technical name of item to be used in place. -- @param new_item Technical name of item to be used in place.
core.register_chatcommand("replace_item", { core.register_chatcommand("replace_item", {
privs = {server=true}, privs = {server=true},
description = "Replace an item in game.", description = S("Replace an item in game."),
params = "<old_item> <new_item>", params = help_repo.item.replace_params,
func = function(name, param) func = function(name, param)
if not param:find(" ") then if not param:find(" ") then
return false, "Not enough parameters." return false, help_repo.param.missing
end end
local src = param:split(" ") local src = param:split(" ")
@ -151,11 +177,11 @@ core.register_chatcommand("replace_item", {
-- @param new_node Technical name of node to be used in place. -- @param new_node Technical name of node to be used in place.
core.register_chatcommand("replace_node", { core.register_chatcommand("replace_node", {
privs = {server=true}, privs = {server=true},
description = "Replace a node in game.", description = S("Replace a node in game."),
params = "<old_node> <new_node> [radius]", params = help_repo.node.replace_params,
func = function(name, param) func = function(name, param)
if not param:find(" ") then if not param:find(" ") then
return false, "Not enough parameters." return false, help_repo.param.missing
end end
local radius = 100 local radius = 100
@ -168,12 +194,12 @@ core.register_chatcommand("replace_node", {
end end
if not radius then if not radius then
return false, "Radius must be a number." return false, help_repo.param.mal_radius
end end
local new_node = core.registered_nodes[tgt] local new_node = core.registered_nodes[tgt]
if not new_node then if not new_node then
return false, "Cannot use unknown node \"" .. tgt .. "\" as replacement." return false, S('Cannot use unknown node "@1" as replacement.', tgt)
end end
local total_replaced = 0 local total_replaced = 0
@ -188,7 +214,7 @@ core.register_chatcommand("replace_node", {
end end
end end
core.chat_send_player(name, "Replaced " .. total_replaced .. " nodes.") core.chat_send_player(name, S("Replaced @1 nodes.", total_replaced))
return true return true
end, end,
}) })
@ -199,11 +225,11 @@ core.register_chatcommand("replace_node", {
-- @tparam[opt] int radius Search radius. -- @tparam[opt] int radius Search radius.
core.register_chatcommand("find_unknown_nodes", { core.register_chatcommand("find_unknown_nodes", {
privs = {server=true}, privs = {server=true},
description = "Find names of unknown nodes.", description = S("Find names of unknown nodes."),
params = "[radius]", params = help_repo.param.opt_radius,
func = function(name, param) func = function(name, param)
if param:find(" ") then if param:find(" ") then
return false, "Too many parameters." return false, help_repo.param.excess
end end
local radius = 100 local radius = 100
@ -212,7 +238,7 @@ core.register_chatcommand("find_unknown_nodes", {
end end
if not radius then if not radius then
return false, "Radius must be a number." return false, help_repo.param.mal_radius
end end
local ppos = core.get_player_by_name(name):get_pos() local ppos = core.get_player_by_name(name):get_pos()
@ -231,9 +257,9 @@ core.register_chatcommand("find_unknown_nodes", {
end end
if #unknown_nodes > 0 then if #unknown_nodes > 0 then
core.chat_send_player(name, "Found unknown nodes: " .. table.concat(unknown_nodes, ", ")) core.chat_send_player(name, S("Found unknown nodes: @1", table.concat(unknown_nodes, ", ")))
else else
core.chat_send_player(name, "No unknown nodes found") core.chat_send_player(name, S("No unknown nodes found."))
end end
return true return true
@ -255,20 +281,20 @@ if cleaner.unsafe then
-- @param ore Ore technical name. -- @param ore Ore technical name.
core.register_chatcommand("remove_ore", { core.register_chatcommand("remove_ore", {
privs = {server=true}, privs = {server=true},
description = "Remove an ore from game.", description = S("Remove an ore from game."),
params = "<ore>", params = help_repo.ore.remove_params,
func = function(name, param) func = function(name, param)
if param:find(" ") then if param:find(" ") then
return false, "Too many parameters." return false, help_repo.param.excess
end end
core.after(0, function() core.after(0, function()
local registered, total_removed = cleaner.remove_ore(param) local registered, total_removed = cleaner.remove_ore(param)
if not registered then if not registered then
core.chat_send_player(name, "Ore \"" .. param .. "\" not found, not unregistering.") core.chat_send_player(name, S('Ore "@1" not found, not unregistering.', param))
else else
core.chat_send_player(name, "Unregistered " .. total_removed .. " ores (this will be undone after server restart).") core.chat_send_player(name, S("Unregistered @1 ores (this will be undone after server restart).", total_removed))
end end
end) end)

28
locale/template.txt Normal file
View file

@ -0,0 +1,28 @@
# Translated by
# chat commands
entity=
node=
radius=
old_item=
new_item=
old_node=
new_node=
ore=
Remove an entity from game.=
Remove a node from game.=
Replace an item in game.=
Replace a node in game.=
Find names of unknown nodes.=
Remove an ore from game.=
Missing parameter.=
Too many parameters.=
Radius must be a number.=
Cannot use unknown item "@1" as replacement.=
Cannot use unknown node "@1" as replacement.=
Replaced @1 nodes.=
Found unknown nodes: @1=
No unknown nodes found.=
Ore "@1" not found, not unregistering.=
Unregistered @1 ores (this will be undone after server restart).=

View file

@ -3,3 +3,4 @@ description = A mod that can be used to remove/replace unknown entities, nodes,
version = 1.1 version = 1.1
license = MIT license = MIT
author = PilzAdam, Jordan Irwin (AntumDeluge) author = PilzAdam, Jordan Irwin (AntumDeluge)
min_minetest_version = 5.0