2011-01-25, 07:05:41
ccagle8 Wrote:Zegnåt Wrote:I feel like we will need a way to have language files per plugin. We can come up with good ways to extend $il8n but people that want it in their own language will still need to dive into the core plugin code to change the strings…not if the plugin developers include a language file with their plugin.
The I18N plugin already includes its own language files exactly like GetSimple itself, however, the strings are added with the plugin name as prefix:
Code:
i18n_add_texts($i18n);
function i18n_add_texts(&$globali18n) {
global $LANG;
$i18n = array();
@include(GSPLUGINPATH.'i18n/lang/'.$LANG.'.php');
if (count($i18n) == 0) @include(GSPLUGINPATH.'i18n/lang/en_US.php');
foreach ($i18n as $code => $text) $globali18n['i18n/'.$code] = $text;
}
I suppose a similar functionality could be implemented in a core function:
Code:
function add_texts($directory, $prefix) {
global $i18n, $LANG;
call _add_texts($i18n, $LANG, $directory, $prefix);
}
// needed to avoid name clash between global and local $i18n - or save global one before
function _add_texts(&$globali18n, $LANG, $directory, $prefix) {
$i18n = array();
@include(GSPLUGINPATH.$directory.'/'.$LANG.'.php');
if (count($i18n) == 0) @include(GSPLUGINPATH.$directory.'/en_US.php');
foreach ($i18n as $code => $text) $globali18n[$prefix.'/'.$code] = $text;
}