add search in translated string add translate missing string

This commit is contained in:
bri cassa 2022-07-09 18:02:17 +02:00
commit 15bba05412
3 changed files with 25 additions and 8 deletions

View File

@ -135,12 +135,26 @@ minetest.after(0, function()
pagemax = math.max(math.ceil(#selectable_list / pageitems), 1) pagemax = math.max(math.ceil(#selectable_list / pageitems), 1)
end) end)
local function filter_list(filter) local function filter_list(p_name, filter)
local filtered_list = {} local filtered_list = {}
if not filter or filter == "" then return nil, pagemax end if not filter or filter == "" then return nil, pagemax end
-- search by translated language
local player_info = minetest.get_player_information(p_name)
local lang = player_info and player_info.lang_code or ""
local can_translate = minetest.get_translated_string and lang ~= ""
for index, name in ipairs(selectable_list) do for index, name in ipairs(selectable_list) do
local match = string.match(name, filter) or nil local match = string.find(name, filter) -- search in name
if not match then -- si not found, search in description and translated description ie:(filter="pomme", description="pomme d'or" )
local def = minetest.registered_items[name]
if def and def.description and def.description ~= "" then
if string.find(string.lower(def.description), filter) or
can_translate and string.find(string.lower(minetest.get_translated_string(lang, def.description)), filter) then
match = true
end
end
end
if match then if match then
filtered_list[#filtered_list+1] = name filtered_list[#filtered_list+1] = name
end end
@ -459,14 +473,14 @@ local function handle_main(player, fields)
end end
if fields.filter then if fields.filter then
state.filtered_list, state.buy_pagemax = filter_list(state.buy_filter) state.filtered_list, state.buy_pagemax = filter_list(p_name, string.lower(minetest.formspec_escape(state.buy_filter)))
state.buy_page = 1 state.buy_page = 1
show_main(p_name) show_main(p_name)
end end
if fields.reset_filter then if fields.reset_filter then
state.buy_filter = "" state.buy_filter = ""
state.filtered_list, state.buy_pagemax = filter_list(nil) state.filtered_list, state.buy_pagemax = filter_list(p_name, nil)
state.buy_page = 1 state.buy_page = 1
show_main(p_name) show_main(p_name)
end end

View File

@ -3,6 +3,8 @@ assert(insecure_env, "global_exchange needs to be trusted to run under mod secur
local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/" local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/"
local S = minetest.get_translator("global_exchange")
local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env). local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env).
open_exchange(minetest.get_worldpath() .. "/global_exchange.db") open_exchange(minetest.get_worldpath() .. "/global_exchange.db")
@ -17,13 +19,13 @@ local function handle_setbalance_command(caller, name, newbalance)
end end
minetest.register_privilege("balance", { minetest.register_privilege("balance", {
description = "Can use /setbalance", description = S("Can use /setbalance"),
give_to_singleplayer = false give_to_singleplayer = false
}) })
minetest.register_chatcommand("setbalance", { minetest.register_chatcommand("setbalance", {
params = "[<name>] <balance>", params = S("[<name>] <balance>"),
description = "set a player's trading balance", description = S("set a player's trading balance"),
privs = {balance=true}, privs = {balance=true},
func = function(caller, param) func = function(caller, param)
local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)") local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)")
@ -31,7 +33,7 @@ minetest.register_chatcommand("setbalance", {
name = caller name = caller
balancestr = string.match(param, "([0-9]+)") balancestr = string.match(param, "([0-9]+)")
if not balancestr then if not balancestr then
return false, "Invalid parameters (see /help setbalance)" return false, S("Invalid parameters (see /help setbalance)")
end end
end end
return handle_setbalance_command(caller, name, tonumber(balancestr)) return handle_setbalance_command(caller, name, tonumber(balancestr))

View File

@ -21,6 +21,7 @@ No such order.=Pas un tel ordre.
Order does not exist.=L'ordre n'existe pas. Order does not exist.=L'ordre n'existe pas.
### init.lua ### ### init.lua ###
Can use /setbalance=Peut utiliser /setbalance
set a player's trading balance=définir le solde commercial d'un joueur set a player's trading balance=définir le solde commercial d'un joueur
Invalid parameters (see /help setbalance)=Paramètres invalides (voir /help setbalance) Invalid parameters (see /help setbalance)=Paramètres invalides (voir /help setbalance)