diff --git a/API.md b/API.md index 26098e0..f881474 100644 --- a/API.md +++ b/API.md @@ -52,6 +52,7 @@ Veja os métodos de acordo com sua finalidade. * `macromoney.register_value(value_id, {definições de valor})`: Register value #### Manipular valores em contas +* `macromoney.has_amount(player_name, value_id, amount)`: Verifica se possui um montante na conta * `macromoney.get_account(player_name, value_id)`: Pega um valor em uma conta * `macromoney.add_account(player_name, value_id, add_value)`: Adiciona um valor em uma conta * `macromoney.subtract_account(player_name, value_id, subtract_value)`: Subtrai um valor em uma conta diff --git a/aliases.lua b/aliases.lua new file mode 100644 index 0000000..06db245 --- /dev/null +++ b/aliases.lua @@ -0,0 +1,62 @@ +--[[ + Mod Minemacro for Minetest + Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine) + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Aliases + ]] + + +-- Compatibility with older mods + +-- Somar +macromoney.somar = function(name, tipo_v, valor) + if tipo_v ~= "macros" then + minetest.log("error", "[Macromoney] Discontinued method with invalid value (tipo_v ="..dump(tipo_v)..")") + minetest.request_shutdown("Internal error") + return false + end + minetest.log("deprecated", "[Macromoney] Deprecated 'macromoney.somar' method (update code)") + + macromoney.add_account(name, "money", valor) +end + +-- Subtrair +macromoney.subtrair = function(name, tipo_v, valor, confisco) + if tipo_v ~= "macros" then + minetest.log("error", "[Macromoney] Discontinued method with invalid value (tipo_v ="..dump(tipo_v)..")") + minetest.request_shutdown("Internal error") + return false + end + if confisco ~= nil then + minetest.log("error", "[Macromoney] Discontinued method with invalid value ('confisco' param used)") + minetest.request_shutdown("Internal error") + return false + end + minetest.log("deprecated", "[Macromoney] Deprecated 'macromoney.subtrair' method (update code)") + + macromoney.subtract_account(name, "money", valor) +end + +-- Consultar +macromoney.consultar = function(name, tipo_v) + if tipo_v ~= "macros" then + minetest.log("error", "[Macromoney] Discontinued method with invalid value (tipo_v ="..dump(tipo_v)..")") + minetest.request_shutdown("Internal error") + return false + end + minetest.log("deprecated", "[Macromoney] Deprecated 'macromoney.consultar' method (update code)") + + return macromoney.get_account(name, "money") +end + +-- Existe +macromoney.existe = function(name) + minetest.log("deprecated", "[Macromoney] Deprecated 'macromoney.existe' method (update code)") + + return macromoney.exist_account(name) +end + + diff --git a/api.lua b/api.lua index 06a526d..07f8ff7 100644 --- a/api.lua +++ b/api.lua @@ -8,54 +8,10 @@ API ]] --- Basic methods - --- Exists account -macromoney.exist_account = function(name) - return macromoney.db.exist(name) -end - --- Exists account value -macromoney.exist_account_value = function(name, value_type) - local data = macromoney.db.get(name) - if data[value_type] ~= nil then - return true - else - return false - end -end - --- Set -macromoney.set_account = function(name, value_type, new_value) - local data = macromoney.db.get(name) - data[value_type] = new_value - return macromoney.db.set(name, data) -end - --- Get -macromoney.get_account = function(name, value_type) - return macromoney.db.get(name)[value_type] -end - --- Add -macromoney.add_account = function(name, value_type, add_value) - local data = macromoney.db.get(name) - data[value_type] = data[value_type] + add_value - macromoney.db.set(name, data) -end - --- Subtract -macromoney.subtract_account = function(name, value_type, subtract_value) - local data = macromoney.db.get(name) - data[value_type] = data[value_type] - subtract_value - macromoney.db.set(name, data) -end - -- Tags macromoney.tags = {} - -- Registered values macromoney.registered_values = {} @@ -69,9 +25,72 @@ macromoney.register_value = function(value_id, def) end end +-- Get value ID +macromoney.get_value_id = function(tag_or_id) + if macromoney.tags[tag_or_id] then + return macromoney.tags[tag_or_id] + end + return tag_or_id +end +local get_id = macromoney.get_value_id + +-- Basic methods + +-- Exists account +macromoney.exist_account = function(name) + return macromoney.db.exist(name) +end + +-- Exists account value +macromoney.exist_account_value = function(name, value_id) + local data = macromoney.db.get(name) + if data[get_id(value_id)] ~= nil then + return true + else + return false + end +end + +-- Set +macromoney.set_account = function(name, value_id, new_value) + local data = macromoney.db.get(name) + data[get_id(value_id)] = new_value + return macromoney.db.set(name, data) +end + +-- Get +macromoney.get_account = function(name, value_id) + return macromoney.db.get(name)[get_id(value_id)] +end + +-- Add +macromoney.add_account = function(name, value_id, add_value) + local data = macromoney.db.get(name) + data[get_id(value_id)] = data[get_id(value_id)] + add_value + macromoney.db.set(name, data) +end + +-- Subtract +macromoney.subtract_account = function(name, value_id, subtract_value) + local data = macromoney.db.get(name) + data[get_id(value_id)] = data[get_id(value_id)] - subtract_value + macromoney.db.set(name, data) +end + +-- Check amount +macromoney.has_amount = function(name, value_id, amount) + local data = macromoney.db.get(name) + if data[get_id(value_id)] >= amount then + return true + end + return false +end + + + -- Get text value -macromoney.get_text_number_value = function(value_id, value) - local def = macromoney.registered_values[value_id] +macromoney.get_value_to_text = function(value_id, value) + local def = macromoney.registered_values[macromoney.get_value_id(value_id)] local prefix = def.specimen_prefix or "" local text @@ -99,6 +118,8 @@ macromoney.get_text_number_value = function(value_id, value) return text end + + -- Check and register player accounts minetest.register_on_joinplayer(function(player) if not player then return end diff --git a/atm.lua b/atm.lua index 591687b..4d477d3 100644 --- a/atm.lua +++ b/atm.lua @@ -1,18 +1,18 @@ --[[ - Mod Macromoney para Minetest - Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + Mod Minemacro for Minetest + Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine) - Recebeste uma cópia da GNU Lesser General - Public License junto com esse software, - se não, veja em . - - Nodes + You should have received a copy of the GNU General Public License + along with this program. If not, see . + ATM ]] --- Money machine +local S = macromoney.S + +-- ATM minetest.register_node("macromoney:atm", { - description = "Automatic Teller Machine", + description = S("Automatic Teller Machine"), drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir", @@ -47,9 +47,9 @@ minetest.register_node("macromoney:atm", { local formspec = "size[8,5.5;]" ..default.gui_bg ..default.gui_bg_img - .."label[0.256,0;You can deposit or withdraw "..macromoney.get_text_number_value("macromoney:money", 100).."]" - .."button[1,0.5;2,1;withdraw;Withdraw]" - .."button[5,0.5;2,1;deposit;Deposit]" + .."label[0.256,0;"..S("You can deposit or withdraw @1", macromoney.get_value_to_text("macromoney:money", 100)).."]" + .."button[1,0.5;2,1;withdraw;"..S("Withdraw").."]" + .."button[5,0.5;2,1;deposit;"..S("Deposit").."]" .."list[current_player;main;0,1.5;8,4;]" minetest.show_formspec(player:get_player_name(), "macromoney:atm", formspec) @@ -67,12 +67,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) -- Check inventory if not player_inv:room_for_item("main", "macromoney:macro 100") then - minetest.chat_send_player(player_name, "Crowded inventory") + minetest.chat_send_player(player_name, S("Crowded inventory.")) return true -- Check account balance elseif macromoney.get_account(player_name, "macromoney:money") < 100 then - minetest.chat_send_player(player_name, "Insufficient balance for this operation.") + minetest.chat_send_player(player_name, S("Account balance is insufficient.")) return true end @@ -86,7 +86,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) -- Check inventory if not player_inv:contains_item("main", "macromoney:macro 100") then - minetest.chat_send_player(player_name, "You have enough money in your inventory.") + minetest.chat_send_player(player_name, S("You cashed out @1.", 100)) return true end diff --git a/commands.lua b/commands.lua index ede3b3c..f27e399 100644 --- a/commands.lua +++ b/commands.lua @@ -10,11 +10,13 @@ ]] +local S = macromoney.S + -- Accounts manager privilege -minetest.register_privilege("macromoney_admin", "Accounts manager") +minetest.register_privilege("macromoney_admin", S("Accounts manager")) -- Get text number value -local to_text = macromoney.get_text_number_value +local to_text = macromoney.get_value_to_text -- Send account on chat local send_acct_on_chat = function(name, acct_name) @@ -29,14 +31,15 @@ end -- "macromoney" command minetest.register_chatcommand("macromoney", { privs = {macromoney_admin = true}, - params = "[ | ]", - description = "Manage accounts", + params = S("[ | ]"), + description = S("Manage accounts"), func = function(name, param) -- Consult self account if param == "" then --/macromoney - minetest.chat_send_player(name, "Your account") + minetest.chat_send_player(name, "***** "..S("Your account").." *****") send_acct_on_chat(name, name) + return true end local m = string.split(param, " ") @@ -44,12 +47,12 @@ minetest.register_chatcommand("macromoney", { -- Check account if macromoney.exist_account(param1) == false then - return false, "Account not exist." + return false, S("Account not exist.") end -- Consultar conta de outro if param1 and not param2 then --/macromoney - minetest.chat_send_player(name, param1.." account") + minetest.chat_send_player(name, "*** "..S("@1 account", param1).." ***") send_acct_on_chat(name, param1) return end @@ -63,13 +66,13 @@ minetest.register_chatcommand("macromoney", { -- Check value id if macromoney.registered_values[param3] == nil then - return false, "Ivalid value type '"..param3.."'" + return false, S("Ivalid value type '@1'.", param1) end -- Check and adjust numeric value if macromoney.registered_values[param3].value_type == "number" then if not tonumber(param4) then - return false, "Invalid operation. '"..param3.."' is not numeric value." + return false, S("Invalid operation. '@1' is not numeric value.", param3) end param4 = tonumber(param4) end @@ -79,7 +82,7 @@ minetest.register_chatcommand("macromoney", { macromoney.subtract_account(param1, param3, param4) - return true, "Subtracted value. New balance is "..to_text(param3, macromoney.get_account(param1, param3)) + return true, S("Subtracted value. New balance is @1.", to_text(param3, macromoney.get_account(param1, param3))) end -- Add @@ -87,7 +90,7 @@ minetest.register_chatcommand("macromoney", { macromoney.add_account(param1, param3, param4) - return true, "Added value. New balance is "..to_text(param3, macromoney.get_account(param1, param3)) + return true, S("Added value. New balance is @1.", to_text(param3, macromoney.get_account(param1, param3))) end -- Set @@ -95,7 +98,7 @@ minetest.register_chatcommand("macromoney", { macromoney.set_account(param1, param3, param4) - return true, "Setted value. New value is "..to_text(param3, macromoney.get_account(param1, param3)) + return true, S("Setted value. New value is @1.", to_text(param3, macromoney.get_account(param1, param3))) end end diff --git a/init.lua b/init.lua index 5a14f81..6310398 100644 --- a/init.lua +++ b/init.lua @@ -12,11 +12,14 @@ local modpath = minetest.get_modpath("macromoney") -- Global table macromoney = {} +dofile(modpath .. "/translator.lua") dofile(modpath .. "/data_base.lua") dofile(modpath .. "/api.lua") dofile(modpath .. "/commands.lua") +dofile(modpath .. "/aliases.lua") + -- Custom dofile(modpath .. "/money.lua") dofile(modpath .. "/safe_box.lua") diff --git a/lib/intllib.lua b/lib/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/lib/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext diff --git a/locale/en.mo b/locale/en.mo new file mode 100644 index 0000000..9a33865 Binary files /dev/null and b/locale/en.mo differ diff --git a/locale/en.po b/locale/en.po new file mode 100644 index 0000000..5da670d --- /dev/null +++ b/locale/en.po @@ -0,0 +1,112 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-04 22:22-0300\n" +"PO-Revision-Date: 2020-04-04 22:25-0300\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" + +#: atm.lua +msgid "Automatic Teller Machine" +msgstr "Automatic Teller Machine" + +#: atm.lua +msgid "You can deposit or withdraw @1" +msgstr "You can deposit or withdraw @1" + +#: atm.lua +msgid "Withdraw" +msgstr "Withdraw" + +#: atm.lua +msgid "Deposit" +msgstr "Deposit" + +#: atm.lua +msgid "Crowded inventory." +msgstr "Crowded inventory." + +#: atm.lua +msgid "Account balance is insufficient." +msgstr "Account balance is insufficient." + +#: atm.lua +msgid "You cashed out @1." +msgstr "You cashed out @1." + +#: commands.lua +msgid "Accounts manager" +msgstr "Accounts manager" + +#: commands.lua +msgid "[ | ]" +msgstr "[ | ]" + +#: commands.lua +msgid "Manage accounts" +msgstr "Manage accounts" + +#: commands.lua +msgid "Your account" +msgstr "Your account" + +#: commands.lua +msgid "Account not exist." +msgstr "Account not exist." + +#: commands.lua +msgid "@1 account" +msgstr "@1 account" + +#: commands.lua +msgid "Ivalid value type '@1'." +msgstr "Ivalid value type '@1'." + +#: commands.lua +msgid "Invalid operation. '@1' is not numeric value." +msgstr "Invalid operation. '@1' is not numeric value." + +#: commands.lua +msgid "Subtracted value. New balance is @1." +msgstr "Subtracted value. New balance is @1." + +#: commands.lua +msgid "Added value. New balance is @1." +msgstr "Added value. New balance is @1." + +#: commands.lua +msgid "Setted value. New value is @1." +msgstr "Setted value. New value is @1." + +#: money.lua +msgid "Macro money" +msgstr "Macro money" + +#: money.lua +msgid "Macro" +msgstr "Macro" + +#: money.lua +msgid "Suitcase of Macros" +msgstr "Suitcase of Macros" + +#: safe_box.lua +msgid "Safe Box" +msgstr "Safe Box" + +#~ msgid "Insufficient balance for this operation." +#~ msgstr "Insufficient balance for this operation." + +#~ msgid "You have enough money in your inventory." +#~ msgstr "You have enough money in your inventory." diff --git a/locale/en.po~ b/locale/en.po~ new file mode 100644 index 0000000..237a394 --- /dev/null +++ b/locale/en.po~ @@ -0,0 +1,106 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-04 21:27-0300\n" +"PO-Revision-Date: 2020-04-04 21:28-0300\n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Last-Translator: \n" +"Language-Team: \n" +"X-Generator: Poedit 2.0.6\n" + +#: atm.lua +msgid "Automatic Teller Machine" +msgstr "Automatic Teller Machine" + +#: atm.lua +msgid "You can deposit or withdraw @1" +msgstr "You can deposit or withdraw @1" + +#: atm.lua +msgid "Withdraw" +msgstr "Withdraw" + +#: atm.lua +msgid "Deposit" +msgstr "Deposit" + +#: atm.lua +msgid "Crowded inventory." +msgstr "Crowded inventory." + +#: atm.lua +msgid "Insufficient balance for this operation." +msgstr "Insufficient balance for this operation." + +#: atm.lua +msgid "You have enough money in your inventory." +msgstr "You have enough money in your inventory." + +#: commands.lua +msgid "Accounts manager" +msgstr "Accounts manager" + +#: commands.lua +msgid "[ | ]" +msgstr "[ | ]" + +#: commands.lua +msgid "Manage accounts" +msgstr "Manage accounts" + +#: commands.lua +msgid "Your account" +msgstr "Your account" + +#: commands.lua +msgid "Account not exist." +msgstr "Account not exist." + +#: commands.lua +msgid "@1 account" +msgstr "@1 account" + +#: commands.lua +msgid "Ivalid value type '@1'." +msgstr "Ivalid value type '@1'." + +#: commands.lua +msgid "Invalid operation. '@1' is not numeric value." +msgstr "Invalid operation. '@1' is not numeric value." + +#: commands.lua +msgid "Subtracted value. New balance is @1." +msgstr "Subtracted value. New balance is @1." + +#: commands.lua +msgid "Added value. New balance is @1." +msgstr "Added value. New balance is @1." + +#: commands.lua +msgid "Setted value. New value is @1." +msgstr "Setted value. New value is @1." + +#: money.lua +msgid "Macro money" +msgstr "Macro money" + +#: money.lua +msgid "Macro" +msgstr "Macro" + +#: money.lua +msgid "Suitcase of Macros" +msgstr "Suitcase of Macros" + +#: safe_box.lua +msgid "Safe Box" +msgstr "Safe Box" diff --git a/locale/macromoney.en.tr b/locale/macromoney.en.tr new file mode 100644 index 0000000..04695a4 --- /dev/null +++ b/locale/macromoney.en.tr @@ -0,0 +1,24 @@ +### Arquivo gerado por macromoney apartir de en.po +# textdomain: macromoney +Manage accounts=Manage accounts +Setted value. New value is @1.=Setted value. New value is @1. +Automatic Teller Machine=Automatic Teller Machine +You can deposit or withdraw @1=You can deposit or withdraw @1 +Withdraw=Withdraw +Macro money=Macro money +You cashed out @1.=You cashed out @1. +Subtracted value. New balance is @1.=Subtracted value. New balance is @1. +Your account=Your account +Account balance is insufficient.=Account balance is insufficient. +Macro=Macro +Deposit=Deposit +[ | ]=[ | ] +Account not exist.=Account not exist. +Crowded inventory.=Crowded inventory. +Ivalid value type '@1'.=Ivalid value type '@1'. +@1 account=@1 account +Invalid operation. '@1' is not numeric value.=Invalid operation. '@1' is not numeric value. +Accounts manager=Accounts manager +Suitcase of Macros=Suitcase of Macros +Added value. New balance is @1.=Added value. New balance is @1. +Safe Box=Safe Box diff --git a/locale/macromoney.pt.tr b/locale/macromoney.pt.tr new file mode 100644 index 0000000..72569df --- /dev/null +++ b/locale/macromoney.pt.tr @@ -0,0 +1,24 @@ +### Arquivo gerado por macromoney apartir de pt.po +# textdomain: macromoney +Manage accounts=Gerenciar contas +Setted value. New value is @1.=Valor definido. O novo saldo é @1. +Automatic Teller Machine=Caixa de Autoatendimento +You can deposit or withdraw @1=Você pode depositar ou sacar @1 +Withdraw=Sacar +Macro money=Dinheiro Macro +You cashed out @1.=Você sacou @1. +Subtracted value. New balance is @1.=Valor subtraído. Novo saldo é @1. +Your account=Sua conta +Account balance is insufficient.=O saldo da conta é insuficiente. +Macro=Macro +Deposit=Depositar +[ | ]=[ | ] +Account not exist.=Conta inexistente. +Crowded inventory.=Inventário lotado. +Ivalid value type '@1'.=Tipo de valor inválido '@1'. +@1 account=Conta @1 +Invalid operation. '@1' is not numeric value.=Operação inválida. '@1' não é um valor numérico. +Accounts manager=Gerenciador de contas +Suitcase of Macros=Maleta de Macros +Added value. New balance is @1.=Valor adicionado. Novo saldo é @1. +Safe Box=Cofre diff --git a/locale/pt.mo b/locale/pt.mo new file mode 100644 index 0000000..8e9912c Binary files /dev/null and b/locale/pt.mo differ diff --git a/locale/pt.po b/locale/pt.po new file mode 100644 index 0000000..fd9f50c --- /dev/null +++ b/locale/pt.po @@ -0,0 +1,112 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-04 22:22-0300\n" +"PO-Revision-Date: 2020-04-04 22:23-0300\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" + +#: atm.lua +msgid "Automatic Teller Machine" +msgstr "Caixa de Autoatendimento" + +#: atm.lua +msgid "You can deposit or withdraw @1" +msgstr "Você pode depositar ou sacar @1" + +#: atm.lua +msgid "Withdraw" +msgstr "Sacar" + +#: atm.lua +msgid "Deposit" +msgstr "Depositar" + +#: atm.lua +msgid "Crowded inventory." +msgstr "Inventário lotado." + +#: atm.lua +msgid "Account balance is insufficient." +msgstr "O saldo da conta é insuficiente." + +#: atm.lua +msgid "You cashed out @1." +msgstr "Você sacou @1." + +#: commands.lua +msgid "Accounts manager" +msgstr "Gerenciador de contas" + +#: commands.lua +msgid "[ | ]" +msgstr "[ | ]" + +#: commands.lua +msgid "Manage accounts" +msgstr "Gerenciar contas" + +#: commands.lua +msgid "Your account" +msgstr "Sua conta" + +#: commands.lua +msgid "Account not exist." +msgstr "Conta inexistente." + +#: commands.lua +msgid "@1 account" +msgstr "Conta @1" + +#: commands.lua +msgid "Ivalid value type '@1'." +msgstr "Tipo de valor inválido '@1'." + +#: commands.lua +msgid "Invalid operation. '@1' is not numeric value." +msgstr "Operação inválida. '@1' não é um valor numérico." + +#: commands.lua +msgid "Subtracted value. New balance is @1." +msgstr "Valor subtraído. Novo saldo é @1." + +#: commands.lua +msgid "Added value. New balance is @1." +msgstr "Valor adicionado. Novo saldo é @1." + +#: commands.lua +msgid "Setted value. New value is @1." +msgstr "Valor definido. O novo saldo é @1." + +#: money.lua +msgid "Macro money" +msgstr "Dinheiro Macro" + +#: money.lua +msgid "Macro" +msgstr "Macro" + +#: money.lua +msgid "Suitcase of Macros" +msgstr "Maleta de Macros" + +#: safe_box.lua +msgid "Safe Box" +msgstr "Cofre" + +#~ msgid "Insufficient balance for this operation." +#~ msgstr "Saldo insuficiente para essa operação." + +#~ msgid "You have enough money in your inventory." +#~ msgstr "Você não tem dinheiro suficiente em seu inventário." diff --git a/locale/pt.po~ b/locale/pt.po~ new file mode 100644 index 0000000..359782d --- /dev/null +++ b/locale/pt.po~ @@ -0,0 +1,106 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-04 21:27-0300\n" +"PO-Revision-Date: 2020-04-04 21:37-0300\n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Last-Translator: \n" +"Language-Team: \n" +"X-Generator: Poedit 2.0.6\n" + +#: atm.lua +msgid "Automatic Teller Machine" +msgstr "Caixa de Autoatendimento" + +#: atm.lua +msgid "You can deposit or withdraw @1" +msgstr "Você pode depositar ou sacar @1" + +#: atm.lua +msgid "Withdraw" +msgstr "Sacar" + +#: atm.lua +msgid "Deposit" +msgstr "Depositar" + +#: atm.lua +msgid "Crowded inventory." +msgstr "Inventário lotado." + +#: atm.lua +msgid "Insufficient balance for this operation." +msgstr "Saldo insuficiente para essa operação." + +#: atm.lua +msgid "You have enough money in your inventory." +msgstr "Você não tem dinheiro suficiente em seu inventário." + +#: commands.lua +msgid "Accounts manager" +msgstr "Gerenciador de contas" + +#: commands.lua +msgid "[ | ]" +msgstr "[ | ]" + +#: commands.lua +msgid "Manage accounts" +msgstr "Gerenciar contas" + +#: commands.lua +msgid "Your account" +msgstr "Sua conta" + +#: commands.lua +msgid "Account not exist." +msgstr "Conta inexistente." + +#: commands.lua +msgid "@1 account" +msgstr "Conta @1" + +#: commands.lua +msgid "Ivalid value type '@1'." +msgstr "Tipo de valor inválido '@1'." + +#: commands.lua +msgid "Invalid operation. '@1' is not numeric value." +msgstr "Operação inválida. '@1' não é um valor numérico." + +#: commands.lua +msgid "Subtracted value. New balance is @1." +msgstr "Valor subtraído. Novo saldo é @1." + +#: commands.lua +msgid "Added value. New balance is @1." +msgstr "Valor adicionado. Novo saldo é @1." + +#: commands.lua +msgid "Setted value. New value is @1." +msgstr "Valor definido. O novo saldo é @1." + +#: money.lua +msgid "Macro money" +msgstr "Dinheiro Macro" + +#: money.lua +msgid "Macro" +msgstr "Macro" + +#: money.lua +msgid "Suitcase of Macros" +msgstr "Maleta de Macros" + +#: safe_box.lua +msgid "Safe Box" +msgstr "Cofre" diff --git a/locale/pt_BR.po b/locale/pt_BR.po new file mode 100644 index 0000000..fd9f50c --- /dev/null +++ b/locale/pt_BR.po @@ -0,0 +1,112 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-04 22:22-0300\n" +"PO-Revision-Date: 2020-04-04 22:23-0300\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" + +#: atm.lua +msgid "Automatic Teller Machine" +msgstr "Caixa de Autoatendimento" + +#: atm.lua +msgid "You can deposit or withdraw @1" +msgstr "Você pode depositar ou sacar @1" + +#: atm.lua +msgid "Withdraw" +msgstr "Sacar" + +#: atm.lua +msgid "Deposit" +msgstr "Depositar" + +#: atm.lua +msgid "Crowded inventory." +msgstr "Inventário lotado." + +#: atm.lua +msgid "Account balance is insufficient." +msgstr "O saldo da conta é insuficiente." + +#: atm.lua +msgid "You cashed out @1." +msgstr "Você sacou @1." + +#: commands.lua +msgid "Accounts manager" +msgstr "Gerenciador de contas" + +#: commands.lua +msgid "[ | ]" +msgstr "[ | ]" + +#: commands.lua +msgid "Manage accounts" +msgstr "Gerenciar contas" + +#: commands.lua +msgid "Your account" +msgstr "Sua conta" + +#: commands.lua +msgid "Account not exist." +msgstr "Conta inexistente." + +#: commands.lua +msgid "@1 account" +msgstr "Conta @1" + +#: commands.lua +msgid "Ivalid value type '@1'." +msgstr "Tipo de valor inválido '@1'." + +#: commands.lua +msgid "Invalid operation. '@1' is not numeric value." +msgstr "Operação inválida. '@1' não é um valor numérico." + +#: commands.lua +msgid "Subtracted value. New balance is @1." +msgstr "Valor subtraído. Novo saldo é @1." + +#: commands.lua +msgid "Added value. New balance is @1." +msgstr "Valor adicionado. Novo saldo é @1." + +#: commands.lua +msgid "Setted value. New value is @1." +msgstr "Valor definido. O novo saldo é @1." + +#: money.lua +msgid "Macro money" +msgstr "Dinheiro Macro" + +#: money.lua +msgid "Macro" +msgstr "Macro" + +#: money.lua +msgid "Suitcase of Macros" +msgstr "Maleta de Macros" + +#: safe_box.lua +msgid "Safe Box" +msgstr "Cofre" + +#~ msgid "Insufficient balance for this operation." +#~ msgstr "Saldo insuficiente para essa operação." + +#~ msgid "You have enough money in your inventory." +#~ msgstr "Você não tem dinheiro suficiente em seu inventário." diff --git a/locale/pt_PT.po b/locale/pt_PT.po new file mode 100644 index 0000000..fd9f50c --- /dev/null +++ b/locale/pt_PT.po @@ -0,0 +1,112 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-04 22:22-0300\n" +"PO-Revision-Date: 2020-04-04 22:23-0300\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" + +#: atm.lua +msgid "Automatic Teller Machine" +msgstr "Caixa de Autoatendimento" + +#: atm.lua +msgid "You can deposit or withdraw @1" +msgstr "Você pode depositar ou sacar @1" + +#: atm.lua +msgid "Withdraw" +msgstr "Sacar" + +#: atm.lua +msgid "Deposit" +msgstr "Depositar" + +#: atm.lua +msgid "Crowded inventory." +msgstr "Inventário lotado." + +#: atm.lua +msgid "Account balance is insufficient." +msgstr "O saldo da conta é insuficiente." + +#: atm.lua +msgid "You cashed out @1." +msgstr "Você sacou @1." + +#: commands.lua +msgid "Accounts manager" +msgstr "Gerenciador de contas" + +#: commands.lua +msgid "[ | ]" +msgstr "[ | ]" + +#: commands.lua +msgid "Manage accounts" +msgstr "Gerenciar contas" + +#: commands.lua +msgid "Your account" +msgstr "Sua conta" + +#: commands.lua +msgid "Account not exist." +msgstr "Conta inexistente." + +#: commands.lua +msgid "@1 account" +msgstr "Conta @1" + +#: commands.lua +msgid "Ivalid value type '@1'." +msgstr "Tipo de valor inválido '@1'." + +#: commands.lua +msgid "Invalid operation. '@1' is not numeric value." +msgstr "Operação inválida. '@1' não é um valor numérico." + +#: commands.lua +msgid "Subtracted value. New balance is @1." +msgstr "Valor subtraído. Novo saldo é @1." + +#: commands.lua +msgid "Added value. New balance is @1." +msgstr "Valor adicionado. Novo saldo é @1." + +#: commands.lua +msgid "Setted value. New value is @1." +msgstr "Valor definido. O novo saldo é @1." + +#: money.lua +msgid "Macro money" +msgstr "Dinheiro Macro" + +#: money.lua +msgid "Macro" +msgstr "Macro" + +#: money.lua +msgid "Suitcase of Macros" +msgstr "Maleta de Macros" + +#: safe_box.lua +msgid "Safe Box" +msgstr "Cofre" + +#~ msgid "Insufficient balance for this operation." +#~ msgstr "Saldo insuficiente para essa operação." + +#~ msgid "You have enough money in your inventory." +#~ msgstr "Você não tem dinheiro suficiente em seu inventário." diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..a637adb --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,106 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-04 22:24-0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: atm.lua +msgid "Automatic Teller Machine" +msgstr "" + +#: atm.lua +msgid "You can deposit or withdraw @1" +msgstr "" + +#: atm.lua +msgid "Withdraw" +msgstr "" + +#: atm.lua +msgid "Deposit" +msgstr "" + +#: atm.lua +msgid "Crowded inventory." +msgstr "" + +#: atm.lua +msgid "Account balance is insufficient." +msgstr "" + +#: atm.lua +msgid "You cashed out @1." +msgstr "" + +#: commands.lua +msgid "Accounts manager" +msgstr "" + +#: commands.lua +msgid "[ | ]" +msgstr "" + +#: commands.lua +msgid "Manage accounts" +msgstr "" + +#: commands.lua +msgid "Your account" +msgstr "" + +#: commands.lua +msgid "Account not exist." +msgstr "" + +#: commands.lua +msgid "@1 account" +msgstr "" + +#: commands.lua +msgid "Ivalid value type '@1'." +msgstr "" + +#: commands.lua +msgid "Invalid operation. '@1' is not numeric value." +msgstr "" + +#: commands.lua +msgid "Subtracted value. New balance is @1." +msgstr "" + +#: commands.lua +msgid "Added value. New balance is @1." +msgstr "" + +#: commands.lua +msgid "Setted value. New value is @1." +msgstr "" + +#: money.lua +msgid "Macro money" +msgstr "" + +#: money.lua +msgid "Macro" +msgstr "" + +#: money.lua +msgid "Suitcase of Macros" +msgstr "" + +#: safe_box.lua +msgid "Safe Box" +msgstr "" diff --git a/locale/translate files b/locale/translate files new file mode 100644 index 0000000..cd37473 --- /dev/null +++ b/locale/translate files @@ -0,0 +1 @@ +atm.lua commands.lua money.lua safe_box.lua diff --git a/money.lua b/money.lua index 57f0ac9..25d9ebe 100644 --- a/money.lua +++ b/money.lua @@ -1,18 +1,18 @@ --[[ - Mod Macromoney para Minetest - Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + Mod Minemacro for Minetest + Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine) - Recebeste uma cópia da GNU Lesser General - Public License junto com esse software, - se não, veja em . + You should have received a copy of the GNU General Public License + along with this program. If not, see . Macros - ]] +local S = macromoney.S + -- Register macro money macromoney.register_value("macromoney:money", { - description = "Macro money", + description = S("Macro money"), specimen_prefix = "M¢", value_type = "number", initial_value = 0, @@ -21,22 +21,21 @@ macromoney.register_value("macromoney:money", { -- Macro minetest.register_craftitem("macromoney:macro", { - description = "Macro", + description = S("Macro"), inventory_image = "macromoney_macro.png", stack_max = 100, }) --- Maleta de Macros -minetest.register_craftitem("macromoney:maleta_de_macros", { - description = "Maleta de Macros", - inventory_image = "macromoney_maleta_de_macros.png", +-- Suitcase of Macros +minetest.register_craftitem("macromoney:suitcase_of_macros", { + description = S("Suitcase of Macros"), + inventory_image = "macromoney_suitcase_of_macros.png", stack_max = 5, }) --- Maleta de Macros minetest.register_craft({ output = "macromoney:macro 100", recipe = { - {"macromoney:maleta_de_macros"}, + {"macromoney:suitcase_of_macros"}, } }) diff --git a/safe_box.lua b/safe_box.lua index d74a825..adf3539 100644 --- a/safe_box.lua +++ b/safe_box.lua @@ -1,15 +1,15 @@ --[[ - Mod Macromoney para Minetest - Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + Mod Minemacro for Minetest + Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine) - Recebeste uma cópia da GNU Lesser General - Public License junto com esse software, - se não, veja em . - - Cofre + You should have received a copy of the GNU General Public License + along with this program. If not, see . + Safe Box ]] +local S = macromoney.S + function default.get_safe_formspec(pos) local spos = pos.x .. "," .. pos.y .. "," ..pos.z local formspec = @@ -27,7 +27,7 @@ local function has_safe_privilege(meta, player) end minetest.register_node("macromoney:safe_box", { - description = "Safe Box", + description = S("Safe Box"), paramtype = "light", paramtype2 = "facedir", tiles = {"macromoney_safe_box_side.png", diff --git a/textures/macromoney_suitcase_of_macros.png b/textures/macromoney_suitcase_of_macros.png new file mode 100644 index 0000000..176f5fd Binary files /dev/null and b/textures/macromoney_suitcase_of_macros.png differ diff --git a/tools/xgettext.bat b/tools/xgettext.bat new file mode 100644 index 0000000..18403db --- /dev/null +++ b/tools/xgettext.bat @@ -0,0 +1,33 @@ +@echo off +setlocal + +set me=%~n0 + +rem # Uncomment the following line if gettext is not in your PATH. +rem # Value must be absolute and end in a backslash. +rem set gtprefix=C:\path\to\gettext\bin\ + +if "%1" == "" ( + echo Usage: %me% FILE... 1>&2 + exit 1 +) + +set xgettext=%gtprefix%xgettext.exe +set msgmerge=%gtprefix%msgmerge.exe + +md locale > nul 2>&1 +echo Generating template... 1>&2 +echo %xgettext% --from-code=UTF-8 -kS -kNS:1,2 -k_ -o locale/template.pot %* +%xgettext% --from-code=UTF-8 -kS -kNS:1,2 -k_ -o locale/template.pot %* +if %ERRORLEVEL% neq 0 goto done + +cd locale + +for %%f in (*.po) do ( + echo Updating %%f... 1>&2 + %msgmerge% --update %%f template.pot +) + +echo DONE! 1>&2 + +:done diff --git a/tools/xgettext.sh b/tools/xgettext.sh new file mode 100755 index 0000000..1504f42 --- /dev/null +++ b/tools/xgettext.sh @@ -0,0 +1,27 @@ +#! /bin/bash + +me=$(basename "${BASH_SOURCE[0]}"); + +if [[ $# -lt 1 ]]; then + echo "Usage: $me FILE..." >&2; + exit 1; +fi + +mkdir -p locale; +echo "Generating template..." >&2; +xgettext --from-code=UTF-8 \ + --keyword=S \ + --keyword=NS:1,2 \ + --keyword=N_ \ + --add-comments='Translators:' \ + --add-location=file \ + -o locale/template.pot \ + "$@" \ + || exit; + +find locale -name '*.po' -type f | while read -r file; do + echo "Updating $file..." >&2; + msgmerge --update "$file" locale/template.pot; +done + +echo "DONE!" >&2; diff --git a/translator.lua b/translator.lua new file mode 100644 index 0000000..7999c99 --- /dev/null +++ b/translator.lua @@ -0,0 +1,176 @@ +--[[ + Mod Macromoney for Minetest + Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine) + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Translator + ]] + +-- Modpath +local modpath = minetest.get_modpath("macromoney") + +-- Tradução intllib +macromoney.intllib = {} +macromoney.intllib.S, macromoney.intllib.NS = dofile(modpath.."/lib/intllib.lua") + +-- Configura tradutor opicional +macromoney.S = macromoney.intllib.S +macromoney.NS = macromoney.intllib.NS + +-- +-- Ajustes devido ao bug de tradutor ler apenas traduzir do ingles +-- + +-- Strings para repassar textos em ingles +local pt_to_en = {} + +-- Gera arquivos de tradução macromoney.*.tr +do + local file_to_tb = function(file) + local msgid = nil + local msgstr = nil + local tb = {} + for line in io.lines(file) do + + -- Iniciando 'msgid' + if string.sub(line, 1, 5) == "msgid" then + + -- Escrever no catalogo a anterior + if msgid ~= nil and msgstr ~= nil then + if msgid ~= "" then + tb[msgid] = msgstr + end + msgid = nil + msgstr = nil + end + + if line == "msgid \"\"" then + msgid = "" + else + msgid = string.sub(line, 8, (string.len(line)-1)) + end + + -- Continuando 'msgid' + elseif string.sub(line, 1, 1) == "\"" and msgstr == nil and msgid ~= nil then + msgid = msgid .. string.sub(line, 2, (string.len(line)-1)) + + -- Iniciando 'msgstr' + elseif string.sub(line, 1, 6) == "msgstr" then + + if line == "msgstr \"\"" then + msgstr = "" + else + msgstr = string.sub(line, 9, (string.len(line)-1)) + end + + -- Continuando 'msgstr' + elseif string.sub(line, 1, 1) == "\"" and msgstr ~= nil then + msgstr = msgstr .. string.sub(line, 2, (string.len(line)-1)) + + end + + + end + + -- Escrever ultima + if msgid ~= nil and msgstr ~= nil then + if msgid ~= "" then + tb[msgid] = msgstr + end + msgid = nil + msgstr = nil + end + + return tb + end + + -- Pegar strings principais en-pt para realizar as trocas + pt_to_en = file_to_tb(modpath.."/locale/en.po") + + --minetest.log("error", "pt_to_en = "..dump(pt_to_en)) + + local list = minetest.get_dir_list(modpath.."/locale") + for _,file in ipairs(list) do + + if string.match(file, "~") == nil then + + -- Traduções ".po" + if string.match(file, ".pot") == nil and string.match(file, ".po") then + + local lang_code = string.gsub(file, ".po", "") + + local pt_to_lang = file_to_tb(modpath.."/locale/"..file) + + -- tabela desejada + local en_to_lang = {} + for pt,en in pairs(pt_to_en) do + en_to_lang[en] = pt_to_lang[pt] + end + + -- Novo arquivo + local new_file = "### Arquivo gerado por macromoney apartir de "..file.."\n# textdomain: macromoney\n" + for en,lang in pairs(en_to_lang) do + new_file = new_file .. en .. "=" .. lang .. "\n" + end + -- Escrever arquivo + local saida = io.open(modpath.."/locale/macromoney."..lang_code..".tr", "w") + saida:write(new_file) + io.close(saida) + end + end + end +end + +-- Ajuste para repassar termos em ingles +local s +if minetest.get_translator ~= nil then + s = minetest.get_translator("macromoney") +else + s = macromoney.intllib.S +end + +macromoney.s = function(...) + local args = { ... } + if pt_to_en[args[1]] ~= nil then + return s(pt_to_en[args[1]], unpack(args, 2)) + end + minetest.log("error", "[macromoney] String "..dump(args[1]).." nao catalogada") + return s(...) +end + +-- Não troca string caso esteja trabalhando com intllib +if minetest.get_modpath("intllib") ~= nil + and minetest.get_translator == nil +then + macromoney.s = s +end + +macromoney.S = function(...) + local args = { ... } + if type(args[1]) == "table" then + local r = {} + for n,a in ipairs(args[1]) do + if n ~= 1 then -- Não traduz o primeiro + table.insert(r, macromoney.S(a)) + else + table.insert(r, a) + end + end + + return macromoney.s(unpack(r)) + + elseif type(args[1]) == "string" then + -- Não traduz caso faltem argumentos (devido strings ilustrativas) + return macromoney.s(...) + + else + return args[1] + end +end + +-- Função que retorna a string inalterada para passar pela checagem +macromoney.Sfake = function(s) return s end + +