From 8430e9fab5135cee7cffb1627d2f0f9107c93d56 Mon Sep 17 00:00:00 2001 From: Crabman77 Date: Tue, 5 Jul 2022 03:27:00 +0200 Subject: [PATCH] WIP: not tested add search in translated string add translate missing string --- exchange_machine.lua | 22 ++++++++++++++++++---- init.lua | 10 ++++++---- locale/global_exchange.fr.tr | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/exchange_machine.lua b/exchange_machine.lua index 7fc852e..fb8c974 100644 --- a/exchange_machine.lua +++ b/exchange_machine.lua @@ -135,12 +135,26 @@ minetest.after(0, function() pagemax = math.max(math.ceil(#selectable_list / pageitems), 1) end) -local function filter_list(filter) +local function filter_list(p_name, filter) local filtered_list = {} 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 - 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 filtered_list[#filtered_list+1] = name end @@ -459,14 +473,14 @@ local function handle_main(player, fields) end 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 show_main(p_name) end if fields.reset_filter then 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 show_main(p_name) end diff --git a/init.lua b/init.lua index 07f1c56..16518f4 100644 --- a/init.lua +++ b/init.lua @@ -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 S = minetest.get_translator("global_exchange") + local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env). open_exchange(minetest.get_worldpath() .. "/global_exchange.db") @@ -17,13 +19,13 @@ local function handle_setbalance_command(caller, name, newbalance) end minetest.register_privilege("balance", { - description = "Can use /setbalance", + description = S("Can use /setbalance"), give_to_singleplayer = false }) minetest.register_chatcommand("setbalance", { - params = "[] ", - description = "set a player's trading balance", + params = S("[] "), + description = S("set a player's trading balance"), privs = {balance=true}, func = function(caller, param) local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)") @@ -31,7 +33,7 @@ minetest.register_chatcommand("setbalance", { name = caller balancestr = string.match(param, "([0-9]+)") if not balancestr then - return false, "Invalid parameters (see /help setbalance)" + return false, S("Invalid parameters (see /help setbalance)") end end return handle_setbalance_command(caller, name, tonumber(balancestr)) diff --git a/locale/global_exchange.fr.tr b/locale/global_exchange.fr.tr index 66494e7..d832de5 100644 --- a/locale/global_exchange.fr.tr +++ b/locale/global_exchange.fr.tr @@ -21,6 +21,7 @@ No such order.=Pas un tel ordre. Order does not exist.=L'ordre n'existe pas. ### init.lua ### +Can use /setbalance=Peut utiliser /setbalance 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)