Path in the Gestor bibliotecas/lang.php
lang.php translates the messages of internal scripts: the database updater, the resource compiler, the plugin installer. It plays no part in translating the site or the admin panel, which use text variables (gestor_variaveis()) and the resources/<language>/ folder.
It is not in the library registry: the scripts include it with require_once.
How it works
-
When included, it sets
$GLOBALS['lang'](defaultpt-br) and loads$GLOBALS['dicionario']withcarregar_dicionario(). -
carregar_dicionario($lang = 'pt-br', $base = '')readsgestor/bibliotecas<base>/<lang>.json. That file does not exist in thebibliotecas/folder, so the default dictionary is always empty. -
set_lang($lang)changes the language and reloads the dictionary (empty, for the same reason). -
__t($key, $replacements = [])returns the translation or, without one, the key itself. Each replacement substitutes{name}and:name.
The real dictionaries live next to each script, which merges them after set_lang():
set_lang('pt-br');
$file = __DIR__ . '/lang/' . $GLOBALS['lang'] . '.json';
if (is_file($file)) {
$GLOBALS['dicionario'] = array_merge($GLOBALS['dicionario'], json_decode(file_get_contents($file), true));
}
echo __t('_compare_summary', ['tabela' => 'paginas', 'ins' => 3]);Existing folders: controladores/atualizacoes/lang/, controladores/plugins/lang/ and controladores/agents/arquitetura/lang/.
Pitfalls
-
The resource compiler (
atualizacao-dados-recursos.php) callsset_lang('pt-br')but does not merge itslang/folder: its messages come out as the raw key (_map_file_not_found). -
The
:namereplacement also hits prefixes: with['id' => 5],:identifierbecomes5entifier. Prefer{name}. -
The functions are declared inside
if (!function_exists(…)): if other code already defined__t(), this library's version is ignored.
Functions
Generated from gestor/bibliotecas/lang.php · 3 functions
carregar_dicionario
view source · line 25 ↗carregar_dicionario($lang = 'pt-br', $base = '')Parameters
$lang$base
__t
view source · line 68 ↗__t($key, $replacements = [])Parameters
$key$replacements
set_lang
view source · line 92 ↗set_lang($lang)Parameters
$lang