Merge e5636432aa
into 7b818cb4af
This commit is contained in:
commit
b05a554b47
|
@ -0,0 +1,136 @@
|
||||||
|
|
||||||
|
# Biblioteca de Internacionalización para Minetest
|
||||||
|
|
||||||
|
Por Diego Martínez (kaeza).
|
||||||
|
Lanzada bajo WTFPL.
|
||||||
|
|
||||||
|
Éste mod es un intento de proveer soporte para internacionalización para otros mods
|
||||||
|
(lo cual Minetest carece actualmente).
|
||||||
|
|
||||||
|
## Cómo usar
|
||||||
|
|
||||||
|
### Para usuarios finales
|
||||||
|
|
||||||
|
Para usar éste mod, simplemente [instálalo](http://wiki.minetest.net/Installing_Mods)
|
||||||
|
y habilítalo en la interfaz.
|
||||||
|
|
||||||
|
Éste mod intenta detectar el idioma del usuario, pero ya que no existe una solución
|
||||||
|
portable para hacerlo, éste intenta varias alternativas, y utiliza la primera
|
||||||
|
encontrada:
|
||||||
|
|
||||||
|
* Opción `language` en `minetest.conf`.
|
||||||
|
* Si ésta no está definida, usa la variable de entorno `LANG` (ésta está
|
||||||
|
siempre definida en SOs como Unix).
|
||||||
|
* Si todo falla, usa `en` (lo cual básicamente significa textos sin traducir).
|
||||||
|
|
||||||
|
En todo caso, el resultado final debe ser el In any case, the end result should be the
|
||||||
|
[Código de Idioma ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
||||||
|
del idioma deseado. Tenga en cuenta tambien que (de momento) solo los dos primeros
|
||||||
|
caracteres son usados, así que por ejemplo, las opciones `de_DE.UTF-8`, `de_DE`,
|
||||||
|
y `de` son iguales.
|
||||||
|
|
||||||
|
Algunos códigos comúnes: `es` para Español, `pt` para Portugués, `fr` para Francés,
|
||||||
|
`it` para Italiano, `de` para Aleman.
|
||||||
|
|
||||||
|
### Para desarrolladores
|
||||||
|
|
||||||
|
Para habilitar funcionalidad en tu mod, copia el siguiente fragmento de código y pégalo
|
||||||
|
al comienzo de tus archivos fuente:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||||
|
local S
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
S = intllib.Getter()
|
||||||
|
else
|
||||||
|
-- Si no requieres patrones de reemplazo (@1, @2, etc) usa ésto:
|
||||||
|
S = function(s) return s end
|
||||||
|
|
||||||
|
-- Si requieres patrones de reemplazo, pero no escapes, usa ésto:
|
||||||
|
S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
|
||||||
|
|
||||||
|
-- Usa ésto si necesitas funcionalidad completa:
|
||||||
|
S = function(s,a,...)if a==nil then return s end a={a,...}return s:gsub("(@?)@(%(?)(%d+)(%)?)",function(e,o,n,c)if e==""then return a[tonumber(n)]..(o==""and c or"")else return"@"..o..n..c end end) end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Tambien necesitarás depender opcionalmente de intllib. Para hacerlo, añade `intllib?`
|
||||||
|
a tu archivo `depends.txt`. Ten en cuenta tambien que si intllib no está instalado,
|
||||||
|
la función `S` es definida para regresar la cadena sin cambios. Ésto se hace para
|
||||||
|
evitar la necesidad de llenar tu código con montones de `if`s (o similar) para verificar
|
||||||
|
que la biblioteca está instalada.
|
||||||
|
|
||||||
|
Luego, para cada cadena de texto a traducir en tu código, usa la función `S`
|
||||||
|
(definida en el fragmento de arriba) para regresar la cadena traducida. Por ejemplo:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
minetest.register_node("mimod:minodo", {
|
||||||
|
-- Cadena simple:
|
||||||
|
description = S("My Fabulous Node"),
|
||||||
|
-- Cadena con patrones de reemplazo:
|
||||||
|
description = S("@1 Car", "Blue"),
|
||||||
|
-- ...
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Nota: Las cadenas en el código fuente por lo general deben estar en ingles ya que
|
||||||
|
es el idioma que más se habla. Es perfectamente posible especificar las cadenas
|
||||||
|
fuente en español y proveer una traducción al ingles, pero no se recomienda.
|
||||||
|
|
||||||
|
Luego, crea un directorio llamado `locale` dentro del directorio de tu mod, y crea
|
||||||
|
un archivo "plantilla" (llamado `template.txt` por lo general) con todas las cadenas
|
||||||
|
a traducir (ver *Formato de archivo de traducciones* más abajo). Los traductores
|
||||||
|
traducirán las cadenas en éste archivo para agregar idiomas a tu mod.
|
||||||
|
|
||||||
|
### Para traductores
|
||||||
|
|
||||||
|
Para traducir un mod que tenga soporte para intllib al idioma deseado, copia el
|
||||||
|
archivo `locale/template.txt` a `locale/IDIOMA.txt` (donde `IDIOMA` es el
|
||||||
|
[Código de Idioma ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
||||||
|
de tu idioma (`es` para español).
|
||||||
|
|
||||||
|
Abre el archivo en tu editor favorito, y traduce cada línea colocando el texto
|
||||||
|
traducido luego del signo de igualdad.
|
||||||
|
|
||||||
|
Ver *Formato de archivo de traducciones* más abajo.
|
||||||
|
|
||||||
|
## Formato de archivo de traducciones
|
||||||
|
|
||||||
|
He aquí un ejemplo de archivo de idioma para el español (`es.txt`):
|
||||||
|
|
||||||
|
```cfg
|
||||||
|
# Un comentario.
|
||||||
|
# Otro comentario.
|
||||||
|
Ésta línea es ignorada porque no tiene un signo de igualdad.
|
||||||
|
Hello, World! = Hola, Mundo!
|
||||||
|
String with\nnewlines = Cadena con\nsaltos de linea
|
||||||
|
String with an \= equals sign = Cadena con un signo de \= igualdad
|
||||||
|
```
|
||||||
|
|
||||||
|
Archivos de idioma (o traducción) son archivos de texto sin formato que consisten de
|
||||||
|
líneas con el formato `texto fuente = texto traducido`. El archivo debe ubicarse en el
|
||||||
|
subdirectorio `locale` del mod, y su nombre debe ser las dos letras del
|
||||||
|
[Código de Idioma ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
||||||
|
del lenguaje al cual se desea traducir.
|
||||||
|
|
||||||
|
Los archivos deben usar la codificación UTF-8.
|
||||||
|
|
||||||
|
Las líneas que comienzan en el símbolo numeral (`#`) son comentarios y son ignoradas
|
||||||
|
por el lector. Tenga en cuenta que los comentarios terminan al final de la línea;
|
||||||
|
no hay soporte para comentarios multilínea. Las líneas que no contengan un signo
|
||||||
|
de igualdad (`=`) tambien son ignoradas.
|
||||||
|
|
||||||
|
## Palabras finales
|
||||||
|
|
||||||
|
Gracias por leer hasta aquí.
|
||||||
|
Si tienes algún comentario/sugerencia, por favor publica en el
|
||||||
|
[tema en los foros](https://forum.minetest.net/viewtopic.php?id=4929). Para
|
||||||
|
reportar errores, usa el [rastreador](https://github.com/minetest-mods/intllib/issues/new)
|
||||||
|
en Github.
|
||||||
|
|
||||||
|
¡Que se hagan las traducciones! :P
|
||||||
|
|
||||||
|
\--
|
||||||
|
|
||||||
|
Suyo,
|
||||||
|
Kaeza
|
16
gettext.lua
16
gettext.lua
|
@ -209,9 +209,19 @@ local function load_catalog(filename)
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.load_catalogs(path)
|
function M.load_catalogs(path, first_lang)
|
||||||
local langs = intllib.get_detected_languages()
|
|
||||||
|
-- add selected first lang
|
||||||
|
if first_lang then
|
||||||
|
langs = {}
|
||||||
|
table.insert(langs, first_lang)
|
||||||
|
for _, lang in ipairs(intllib.get_detected_languages()) do
|
||||||
|
langs[#langs+1] = lang
|
||||||
|
end
|
||||||
|
else
|
||||||
|
langs = intllib.get_detected_languages()
|
||||||
|
end
|
||||||
|
|
||||||
local cats = { }
|
local cats = { }
|
||||||
for _, lang in ipairs(langs) do
|
for _, lang in ipairs(langs) do
|
||||||
local cat = load_catalog(path.."/"..lang..".po")
|
local cat = load_catalog(path.."/"..lang..".po")
|
||||||
|
|
11
init.lua
11
init.lua
|
@ -178,8 +178,15 @@ function intllib.make_gettext_pair(modname)
|
||||||
or getter(msgid))
|
or getter(msgid))
|
||||||
return do_replacements(msgstr, ...)
|
return do_replacements(msgstr, ...)
|
||||||
end
|
end
|
||||||
gettext_getters[modname] = { gettext_func, ngettext_func }
|
-- Get string of Selected language
|
||||||
return gettext_func, ngettext_func
|
local function sgettext_func(lang, msgid, ...)
|
||||||
|
local scatalogs = gettext.load_catalogs(localedir, lang)
|
||||||
|
local msgstr = (catgettext(scatalogs, msgid)
|
||||||
|
or getter(msgid))
|
||||||
|
return do_replacements(msgstr, ...)
|
||||||
|
end
|
||||||
|
gettext_getters[modname] = { gettext_func, ngettext_func, sgettext_func }
|
||||||
|
return gettext_func, ngettext_func, sgettext_func
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
-- Load support for intllib.
|
-- Load support for intllib.
|
||||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local S, NS = dofile(MP.."/intllib.lua")
|
local S, NS, SS = dofile(MP.."/intllib.lua")
|
||||||
|
|
||||||
local use_count = 0
|
local use_count = 0
|
||||||
|
|
||||||
|
@ -26,3 +26,8 @@ minetest.register_craftitem("intltest:test", {
|
||||||
minetest.chat_send_player(user:get_player_name(), message)
|
minetest.chat_send_player(user:get_player_name(), message)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.log("action", "(nil)"..SS(nil, "Test: @1 @2", SS(nil, "Blue"), SS(nil, "Car")))
|
||||||
|
minetest.log("action", "(es) "..SS("es", "Test: @1 @2", SS("es", "Blue"), SS("es", "Car")))
|
||||||
|
minetest.log("action", "(pt) "..SS("pt", "Test: @1 @2", SS("pt", "Blue"), SS("pt", "Car")))
|
||||||
|
minetest.log("action", "(de) "..SS("de", "Test: @1 @2", SS("de", "Blue"), SS("de", "Car")))
|
||||||
|
|
|
@ -1,3 +1,47 @@
|
||||||
|
|
||||||
-- This file should be replaced by `intllib/lib/intllib.lua`.
|
-- Fallback functions for when `intllib` is not installed.
|
||||||
return dofile(minetest.get_modpath("intllib").."/lib/intllib.lua")
|
-- 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, sgettext
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
if intllib.make_gettext_pair then
|
||||||
|
-- New method using gettext.
|
||||||
|
gettext, ngettext, sgettext = 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
|
||||||
|
|
||||||
|
sgettext = sgettext or gettext
|
||||||
|
|
||||||
|
return gettext, ngettext, sgettext
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
# I18N Test Mod.
|
||||||
|
# Copyright (C) 2013-2017 Diego Martínez <kaeza@users.sf.net>
|
||||||
|
# This file is distributed under the same license as the intllib mod.
|
||||||
|
# Diego Martínez <kaeza@users.sf.net>, 2013-2017.
|
||||||
|
# Diego Martnez <kaeza@users.sf.net>, 2017.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: I18N Test Mod 0.1.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2017-02-25 20:40-0300\n"
|
||||||
|
"PO-Revision-Date: 2017-07-13 13:36-0300\n"
|
||||||
|
"Last-Translator: Diego Martnez <kaeza@users.sf.net>\n"
|
||||||
|
"Language-Team: Spanish\n"
|
||||||
|
"Language: es\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Generator: Gtranslator 2.91.7\n"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "Hello, world!"
|
||||||
|
msgstr "Hallo Welt!"
|
||||||
|
|
||||||
|
#. Translators: @1 is color, @2 is object.
|
||||||
|
#: init.lua
|
||||||
|
msgid "Blue"
|
||||||
|
msgstr "Blau"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "Car"
|
||||||
|
msgstr "Auto"
|
||||||
|
|
||||||
|
#. Translators: @1 is color, @2 is object.
|
||||||
|
#: init.lua
|
||||||
|
msgid "Test: @1 @2"
|
||||||
|
msgstr "Test: @2 @1"
|
||||||
|
|
||||||
|
#. Translators: @1 is use count.
|
||||||
|
#: init.lua
|
||||||
|
msgid "Item has been used @1 time."
|
||||||
|
msgid_plural "Item has been used @1 times."
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
|
@ -0,0 +1,45 @@
|
||||||
|
# I18N Test Mod.
|
||||||
|
# Copyright (C) 2013-2017 Diego Martínez <kaeza@users.sf.net>
|
||||||
|
# This file is distributed under the same license as the intllib mod.
|
||||||
|
# Diego Martínez <kaeza@users.sf.net>, 2013-2017.
|
||||||
|
# Diego Martnez <kaeza@users.sf.net>, 2017.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: I18N Test Mod 0.1.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2017-02-25 20:40-0300\n"
|
||||||
|
"PO-Revision-Date: 2017-07-13 13:35-0300\n"
|
||||||
|
"Last-Translator: Diego Martnez <kaeza@users.sf.net>\n"
|
||||||
|
"Language-Team: Spanish\n"
|
||||||
|
"Language: es\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Generator: Gtranslator 2.91.7\n"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "Hello, world!"
|
||||||
|
msgstr "Ola, mundo!"
|
||||||
|
|
||||||
|
#. Translators: @1 is color, @2 is object.
|
||||||
|
#: init.lua
|
||||||
|
msgid "Blue"
|
||||||
|
msgstr "Azul"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "Car"
|
||||||
|
msgstr "Carro"
|
||||||
|
|
||||||
|
#. Translators: @1 is color, @2 is object.
|
||||||
|
#: init.lua
|
||||||
|
msgid "Test: @1 @2"
|
||||||
|
msgstr "Teste: @2 @1"
|
||||||
|
|
||||||
|
#. Translators: @1 is use count.
|
||||||
|
#: init.lua
|
||||||
|
msgid "Item has been used @1 time."
|
||||||
|
msgid_plural "Item has been used @1 times."
|
||||||
|
msgstr[0] "Esse objeto foi usado @1 vez."
|
||||||
|
msgstr[1] "Esse objeto foi usado @2 vezes."
|
|
@ -21,11 +21,11 @@ local function format(str, ...)
|
||||||
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
|
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
|
||||||
end
|
end
|
||||||
|
|
||||||
local gettext, ngettext
|
local gettext, ngettext, sgettext
|
||||||
if minetest.get_modpath("intllib") then
|
if minetest.get_modpath("intllib") then
|
||||||
if intllib.make_gettext_pair then
|
if intllib.make_gettext_pair then
|
||||||
-- New method using gettext.
|
-- New method using gettext.
|
||||||
gettext, ngettext = intllib.make_gettext_pair()
|
gettext, ngettext, sgettext = intllib.make_gettext_pair()
|
||||||
else
|
else
|
||||||
-- Old method using text files.
|
-- Old method using text files.
|
||||||
gettext = intllib.Getter()
|
gettext = intllib.Getter()
|
||||||
|
@ -42,4 +42,6 @@ ngettext = ngettext or function(msgid, msgid_plural, n, ...)
|
||||||
return format(n==1 and msgid or msgid_plural, ...)
|
return format(n==1 and msgid or msgid_plural, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
return gettext, ngettext
|
sgettext = sgettext or gettext
|
||||||
|
|
||||||
|
return gettext, ngettext, sgettext
|
||||||
|
|
Loading…
Reference in New Issue