Internacionalización¶
Haz posible traducir la interfaz de tu sitio a cualquier idioma.
Si quiere colaborar en la traducción de Elgg a algún idioma, échele un ojo a la guía para colaboradores.
The default language is en
for English. Currently Elgg will always fall back to an English translation,
even if the site’s language is not English; this is a known bug.
Resumen¶
Las traducciones se almacenan en ficheros PHP dentro de la carpeta /languages
del complemento. Cada fichero corresponde a un idioma. El formato es /languages/<código del idioma>.php
donde <código del idioma>
es el código ISO 639-1 del idioma. Por ejemplo:
<?php // mod/example/languages/en.php
return [
'example:text' => 'Some example text',
];
To override an existing translation, include it in your plugin’s language file, and make sure your plugin is ordered later on the Admin > Plugins page:
<?php // mod/better_example/languages/en.php
return [
'example:text' => 'Some better text!',
];
Nota
Unless you are overriding core’s or another plugin’s language strings, it is good practice for the language keys to start with your plugin name. For example: yourplugin:success
, yourplugin:title
, etc. This helps avoid conflicts with other language keys.
API del lado del servidor¶
elgg_echo($clave, $argumentos, $idioma)
Imprimir la traducción de la clave al idioma actual.
Ejemplo:
echo elgg_echo('example:text');
También permite la substitución de variables mediante la sintaxis de sprintf
:
// 'welcome' => 'Welcome to %s, %s!'
echo elgg_echo('welcome', [
elgg_get_config('sitename'),
elgg_get_logged_in_user_entity()->name,
]);
Para especificar un idioma concreto al que traducir el texto indicado, use el tercer parámetro:
echo elgg_echo('welcome', [], $user->language);
To first test whether elgg_echo()
can find a translation:
$key = 'key:that:might:not:exist';
if (!elgg_language_key_exists($key)) {
$key = 'fallback:key';
}
echo elgg_echo($key);
Nota
Some APIs allow creating translations for new keys. Translators should always include an English
translation as a fallback. This makes elgg_language_key_exists($key)
a reliable way to predict
whether elgg_echo($key)
will succeed.
API de JavaScript¶
elgg.echo(key, args)
This function is like elgg_echo
in PHP.
Client-side translations are loaded asynchronously. Ensure translations are available by requiring the «elgg» AMD module:
define(function(require) {
var elgg = require("elgg");
alert(elgg.echo('my_key'));
});
Translations are also available after the init, system
JavaScript event.