2015-10-02, 14:17:24
(2015-10-02, 06:24:03)ghoscik Wrote: When do this variable [$language] get set? Seems like really late that's why I can't access its value...
The variable $language is not yet set, when the plugin is loaded. Only after all plugins are loaded - just before the page is rendered - the plugin can determine the page and set the variable.
The solution is to lazily load the translations:
PHP Code:
...
$translation_initialized = false;
function get_translation($field) {
global $pluginName, $language, $translation_initialized;
if (!$translation_initialized) {
i18n_merge($pluginName) || i18n_merge($pluginName, $language);
$translation_initialized = true;
}
return i18n($pluginName . '/' . $field);
}
?>