Adição de sistema de tradução

master
BrunoMine 2018-07-10 12:16:16 -03:00
parent abb39a287f
commit a4ed90174b
17 changed files with 737 additions and 19 deletions

View File

@ -1 +1,2 @@
default
intllib?

View File

@ -1,6 +1,6 @@
--[[
Mod Bau_Coop para Minetest
Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine)
Copyright (C) 2018 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
@ -12,6 +12,9 @@
-- Tabela global
bau_coop = {}
-- Limite de acessos em um bau compartilhado
bau_coop.lim_acess = tonumber(minetest.setting_get("bau_coop_limite_acessos") or 10)
-- Notificador de Inicializador
local notificar = function(msg)
if minetest.setting_get("log_mods") then
@ -24,5 +27,6 @@ local modpath = minetest.get_modpath("bau_coop")
-- Carregar scripts
notificar("Carregando...")
dofile(modpath.."/tradutor.lua")
dofile(modpath.."/nodes.lua")
notificar("[OK]!")

45
lib/intllib.lua Normal file
View File

@ -0,0 +1,45 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- 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

17
locale/bau_coop.en.tr Normal file
View File

@ -0,0 +1,17 @@
### Arquivo gerado por bau_coop apartir de en.po
# textdomain: bau_coop
Shared Chest=Shared Chest
Limit of @1 players=Limit of @1 players
Add new player=Add new player
Return=Return
Player already registered=Player already registered
@1 now has access=@1 now has access
No specified name=No specified name
@1 lost access=@1 lost access
Add Access=Add Access
Players with access=Players with access
Access Denied=Access Denied
Remove Access=Remove Access
Shared Chest (@1)=Shared Chest (@1)
You can not remove yourself=You can not remove yourself
Only one remaining owner=Only one remaining owner

17
locale/bau_coop.pt.tr Normal file
View File

@ -0,0 +1,17 @@
### Arquivo gerado por bau_coop apartir de pt.po
# textdomain: bau_coop
Shared Chest=Bau Compartilhado
Limit of @1 players=Limite de @1 jogadores
Add new player=Adicionar novo jogador
Return=Voltar
Player already registered=Jogador ja registrado
@1 now has access=@1 agora tem acesso
No specified name=Nenhum nome especificado
@1 lost access=@1 perdeu o acesso
Add Access=Adicionar Acesso
Players with access=Jogadores com acesso
Access Denied=Acesso Negado
Remove Access=Remover Acesso
Shared Chest (@1)=Bau Compartilhado (@1)
You can not remove yourself=Nao pode remover a si mesmo
Only one remaining owner=Apenas um dono restante

BIN
locale/en.mo Normal file

Binary file not shown.

79
locale/en.po Normal file
View File

@ -0,0 +1,79 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-07-10 12:07-0300\n"
"PO-Revision-Date: 2018-07-10 12:07-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"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: nodes.lua
msgid "Acesso Negado"
msgstr "Access Denied"
#: nodes.lua
msgid "Bau Compartilhado"
msgstr "Shared Chest"
#: nodes.lua
msgid "Voltar"
msgstr "Return"
#: nodes.lua
msgid "Adicionar novo jogador"
msgstr "Add new player"
#: nodes.lua
msgid "Adicionar Acesso"
msgstr "Add Access"
#: nodes.lua
msgid "Jogadores com acesso"
msgstr "Players with access"
#: nodes.lua
msgid "Remover Acesso"
msgstr "Remove Access"
#: nodes.lua
msgid "Nenhum nome especificado"
msgstr "No specified name"
#: nodes.lua
msgid "Limite de @1 jogadores"
msgstr "Limit of @1 players"
#: nodes.lua
msgid "Jogador ja registrado"
msgstr "Player already registered"
#: nodes.lua
msgid "@1 agora tem acesso"
msgstr "@1 now has access"
#: nodes.lua
msgid "Nao pode remover a si mesmo"
msgstr "You can not remove yourself"
#: nodes.lua
msgid "Apenas um dono restante"
msgstr "Only one remaining owner"
#: nodes.lua
msgid "@1 perdeu o acesso"
msgstr "@1 lost access"
#: nodes.lua
msgid "Bau Compartilhado (@1)"
msgstr "Shared Chest (@1)"

75
locale/en.po~ Normal file
View File

@ -0,0 +1,75 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-07-10 11:55-0300\n"
"PO-Revision-Date: 2018-07-10 12:02-0300\n"
"Language-Team: \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"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: en\n"
#: nodes.lua
msgid "Acesso Negado"
msgstr "Access Denied"
#: nodes.lua
msgid "Bau Compartilhado"
msgstr "Shared Chest"
#: nodes.lua
msgid "Adicionar novo jogador"
msgstr "Add new player"
#: nodes.lua
msgid "Adicionar Acesso"
msgstr "Add Access"
#: nodes.lua
msgid "Jogadores com acesso"
msgstr "Players with access"
#: nodes.lua
msgid "Remover Acesso"
msgstr "Remove Access"
#: nodes.lua
msgid "Nenhum nome especificado"
msgstr "No specified name"
#: nodes.lua
msgid "Limite de @1 jogadores"
msgstr "Limit of @1 players"
#: nodes.lua
msgid "Jogador ja registrado"
msgstr "Player already registered"
#: nodes.lua
msgid "@1 agora tem acesso"
msgstr "@1 now has access"
#: nodes.lua
msgid "Nao pode remover a si mesmo"
msgstr "You can not remove yourself"
#: nodes.lua
msgid "Apenas um dono restante"
msgstr "Only one remaining owner"
#: nodes.lua
msgid "@1 perdeu o acesso"
msgstr "@1 lost access"
#: nodes.lua
msgid "Bau Compartilhado (@1)"
msgstr "Shared Chest (@1)"

BIN
locale/pt.mo Normal file

Binary file not shown.

79
locale/pt.po Normal file
View File

@ -0,0 +1,79 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-07-10 12:07-0300\n"
"PO-Revision-Date: 2018-07-10 12:07-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"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: nodes.lua
msgid "Acesso Negado"
msgstr "Acesso Negado"
#: nodes.lua
msgid "Bau Compartilhado"
msgstr "Bau Compartilhado"
#: nodes.lua
msgid "Voltar"
msgstr "Voltar"
#: nodes.lua
msgid "Adicionar novo jogador"
msgstr "Adicionar novo jogador"
#: nodes.lua
msgid "Adicionar Acesso"
msgstr "Adicionar Acesso"
#: nodes.lua
msgid "Jogadores com acesso"
msgstr "Jogadores com acesso"
#: nodes.lua
msgid "Remover Acesso"
msgstr "Remover Acesso"
#: nodes.lua
msgid "Nenhum nome especificado"
msgstr "Nenhum nome especificado"
#: nodes.lua
msgid "Limite de @1 jogadores"
msgstr "Limite de @1 jogadores"
#: nodes.lua
msgid "Jogador ja registrado"
msgstr "Jogador ja registrado"
#: nodes.lua
msgid "@1 agora tem acesso"
msgstr "@1 agora tem acesso"
#: nodes.lua
msgid "Nao pode remover a si mesmo"
msgstr "Nao pode remover a si mesmo"
#: nodes.lua
msgid "Apenas um dono restante"
msgstr "Apenas um dono restante"
#: nodes.lua
msgid "@1 perdeu o acesso"
msgstr "@1 perdeu o acesso"
#: nodes.lua
msgid "Bau Compartilhado (@1)"
msgstr "Bau Compartilhado (@1)"

75
locale/pt.po~ Normal file
View File

@ -0,0 +1,75 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-07-10 11:55-0300\n"
"PO-Revision-Date: 2018-07-10 11:56-0300\n"
"Language-Team: \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"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: pt\n"
#: nodes.lua
msgid "Acesso Negado"
msgstr "Acesso Negado"
#: nodes.lua
msgid "Bau Compartilhado"
msgstr "Bau Compartilhado"
#: nodes.lua
msgid "Adicionar novo jogador"
msgstr "Adicionar novo jogador"
#: nodes.lua
msgid "Adicionar Acesso"
msgstr "Adicionar Acesso"
#: nodes.lua
msgid "Jogadores com acesso"
msgstr "Jogadores com acesso"
#: nodes.lua
msgid "Remover Acesso"
msgstr "Remover Acesso"
#: nodes.lua
msgid "Nenhum nome especificado"
msgstr "Nenhum nome especificado"
#: nodes.lua
msgid "Limite de @1 jogadores"
msgstr "Limite de @1 jogadores"
#: nodes.lua
msgid "Jogador ja registrado"
msgstr "Jogador ja registrado"
#: nodes.lua
msgid "@1 agora tem acesso"
msgstr "@1 agora tem acesso"
#: nodes.lua
msgid "Nao pode remover a si mesmo"
msgstr "Nao pode remover a si mesmo"
#: nodes.lua
msgid "Apenas um dono restante"
msgstr "Apenas um dono restante"
#: nodes.lua
msgid "@1 perdeu o acesso"
msgstr "@1 perdeu o acesso"
#: nodes.lua
msgid "Bau Compartilhado (@1)"
msgstr "Bau Compartilhado (@1)"

78
locale/template.pot Normal file
View File

@ -0,0 +1,78 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-07-10 12:07-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: nodes.lua
msgid "Acesso Negado"
msgstr ""
#: nodes.lua
msgid "Bau Compartilhado"
msgstr ""
#: nodes.lua
msgid "Voltar"
msgstr ""
#: nodes.lua
msgid "Adicionar novo jogador"
msgstr ""
#: nodes.lua
msgid "Adicionar Acesso"
msgstr ""
#: nodes.lua
msgid "Jogadores com acesso"
msgstr ""
#: nodes.lua
msgid "Remover Acesso"
msgstr ""
#: nodes.lua
msgid "Nenhum nome especificado"
msgstr ""
#: nodes.lua
msgid "Limite de @1 jogadores"
msgstr ""
#: nodes.lua
msgid "Jogador ja registrado"
msgstr ""
#: nodes.lua
msgid "@1 agora tem acesso"
msgstr ""
#: nodes.lua
msgid "Nao pode remover a si mesmo"
msgstr ""
#: nodes.lua
msgid "Apenas um dono restante"
msgstr ""
#: nodes.lua
msgid "@1 perdeu o acesso"
msgstr ""
#: nodes.lua
msgid "Bau Compartilhado (@1)"
msgstr ""

View File

@ -9,6 +9,8 @@
Nodes
]]
-- Tradutor
local S = bau_coop.S
-- Variavel de acesso
local acessos = {}
@ -23,7 +25,7 @@ local formspec_acesso_negado = "size[7,2]"
.. default.gui_bg
.. default.gui_bg_img
.. "image[0,0;2,2;bau_coop_acesso.png]"
.. "label[2,0.75;"..core.colorize("#FF0000", "Acesso Negado").."]"
.. "label[2,0.75;"..core.colorize("#FF0000", S("Acesso Negado")).."]"
local function pegar_formspec_bau_compartilhado(pos)
@ -39,7 +41,7 @@ local function pegar_formspec_bau_compartilhado(pos)
"listring[nodemeta:" .. spos .. ";main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,5.85) ..
"label[0,0;Bau Compartilhado]" ..
"label[0,0;"..S("Bau Compartilhado").."]" ..
"image_button[7,0;1,1;bau_coop_acesso.png;controle_acesso;]"
return formspec
end
@ -58,15 +60,15 @@ local function pegar_formspec_painel_acesso(name, meta, msg, erro)
.. default.gui_bg
.. default.gui_bg_img
.. "image[0,0;2,2;bau_coop_acesso.png]"
.. "label[2,0;Bau Compartilhado]"
.. "button[6,0;2,1;voltar;Voltar]"
.. "label[2,0;"..S("Bau Compartilhado").."]"
.. "button[6,0;2,1;voltar;"..S("Voltar").."]"
-- Adicionar acesso
.. "field[0.3,2.8;4.8,1;novo_acesso;Adicionar novo jogador;]"
.. "button[5,2.49;3,1;adicionar;Adicionar Acesso]"
.. "field[0.3,2.8;4.8,1;novo_acesso;"..S("Adicionar novo jogador")..";]"
.. "button[5,2.49;3,1;adicionar;"..S("Adicionar Acesso").."]"
-- Remover acesso
.. "label[0,3.7;Jogadores com acesso]"
.. "label[0,3.7;"..S("Jogadores com acesso").."]"
.. "dropdown[0,4.125;5,1;nome_acesso;"..lista..";]"
.. "button[5,4;3,1;remover;Remover Acesso]"
.. "button[5,4;3,1;remover;"..S("Remover Acesso").."]"
if msg then
if erro then
@ -166,16 +168,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return minetest.show_formspec(
player:get_player_name(),
"bau_coop:bau_compartilhado",
pegar_formspec_painel_acesso(player:get_player_name(), meta, "Nenhum nome especificado", true)
pegar_formspec_painel_acesso(player:get_player_name(), meta, S("Nenhum nome especificado"), true)
)
end
-- Verificar se ja esta no limite de acessos
if table.maxn(donos) >= 10 then
if table.maxn(donos) >= bau_coop.lim_acess then
return minetest.show_formspec(
player:get_player_name(),
"bau_coop:bau_compartilhado",
pegar_formspec_painel_acesso(player:get_player_name(), meta, "Limite de 10 jogadores", true)
pegar_formspec_painel_acesso(player:get_player_name(), meta, S("Limite de @1 jogadores", bau_coop.lim_acess), true)
)
end
@ -185,7 +187,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return minetest.show_formspec(
player:get_player_name(),
"bau_coop:bau_compartilhado",
pegar_formspec_painel_acesso(player:get_player_name(), meta, "Jogador ja registrado", true)
pegar_formspec_painel_acesso(player:get_player_name(), meta, S("Jogador ja registrado"), true)
)
end
end
@ -200,7 +202,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return minetest.show_formspec(
player:get_player_name(),
"bau_coop:bau_compartilhado",
pegar_formspec_painel_acesso(player:get_player_name(), meta, fields.novo_acesso.." agora tem acesso")
pegar_formspec_painel_acesso(player:get_player_name(), meta, S("@1 agora tem acesso", fields.novo_acesso))
)
-- Remover acesso de um jogador
@ -212,7 +214,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return minetest.show_formspec(
player:get_player_name(),
"bau_coop:bau_compartilhado",
pegar_formspec_painel_acesso(player:get_player_name(), meta, "Nao pode remover a si mesmo", true)
pegar_formspec_painel_acesso(player:get_player_name(), meta, S("Nao pode remover a si mesmo"), true)
)
end
@ -221,7 +223,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return minetest.show_formspec(
player:get_player_name(),
"bau_coop:bau_compartilhado",
pegar_formspec_painel_acesso(player:get_player_name(), meta, "Apenas um dono restante", true)
pegar_formspec_painel_acesso(player:get_player_name(), meta, S("Apenas um dono restante"), true)
)
end
@ -250,7 +252,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return minetest.show_formspec(
player:get_player_name(),
"bau_coop:bau_compartilhado",
pegar_formspec_painel_acesso(player:get_player_name(), meta, fields.nome_acesso.." perdeu o acesso")
pegar_formspec_painel_acesso(player:get_player_name(), meta, S("@1 perdeu o acesso", fields.nome_acesso))
)
-- Voltar para a formspec normal do bau
@ -270,7 +272,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end)
minetest.register_node("bau_coop:bau_compartilhado", {
description = "Bau Compartilhado",
description = S("Bau Compartilhado"),
tiles = {
"default_chest_top.png",
"default_chest_top.png",
@ -289,7 +291,7 @@ minetest.register_node("bau_coop:bau_compartilhado", {
local meta = minetest.get_meta(pos)
meta:set_string("dono", placer:get_player_name())
meta:set_string("permitidos", minetest.serialize({placer:get_player_name()}))
meta:set_string("infotext", "Bau Compartilhado ("..placer:get_player_name()..")")
meta:set_string("infotext", S("Bau Compartilhado (@1)", placer:get_player_name()))
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)

9
settingtypes.txt Normal file
View File

@ -0,0 +1,9 @@
# Configurações aplicaveis para o menu gráfico
#Limite de acessos de jogadores em um mesmo bau compartilhado
#Limit of players in the same shared chest
bau_coop_limite_acessos (Limite de acessos) int 10 0

33
tools/xgettext.bat Normal file
View File

@ -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

27
tools/xgettext.sh Executable file
View File

@ -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;

177
tradutor.lua Normal file
View File

@ -0,0 +1,177 @@
--[[
Mod bau_coop para Minetest
Copyright (C) 2018 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Sistema de tradução
]]
-- Modpath
local modpath = minetest.get_modpath("bau_coop")
-- Tradução intllib
bau_coop.intllib = {}
bau_coop.intllib.S, bau_coop.intllib.NS = dofile(modpath.."/lib/intllib.lua")
-- Configura tradutor opicional
bau_coop.S = bau_coop.intllib.S
bau_coop.NS = bau_coop.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 bau_coop.*.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 bau_coop apartir de "..file.."\n# textdomain: bau_coop\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/bau_coop."..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("bau_coop")
else
s = bau_coop.intllib.S
end
bau_coop.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", "[bau_coop] 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
bau_coop.s = s
end
bau_coop.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, bau_coop.S(a))
else
table.insert(r, a)
end
end
return bau_coop.s(unpack(r))
elseif type(args[1]) == "string" then
-- Não traduz caso faltem argumentos (devido strings ilustrativas)
return bau_coop.s(...)
else
return args[1]
end
end
-- Função que retorna a string inalterada para passar pela checagem
bau_coop.Sfake = function(s) return s end