Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unified directory for plugin translation files
#14
The function(s) would be:

Code:
function i18n_merge($plugin, $language=null) {
    global $i18n, $LANG;
    return i18n_merge_impl($plugin, $language ? $language : $LANG, $i18n);
  }

  function i18n_merge_impl($plugin, $lang, &$globali18n) {
    $i18n = array();
    if (!file_exists(GSPLUGINPATH.$plugin.'/lang/'.$lang.'.php')) return false;
    @include(GSPLUGINPATH.$plugin.'/lang/'.$lang.'.php');
    if (count($i18n) > 0) foreach ($i18n as $code => $text) {
      if (!array_key_exists($plugin.'/'.$code, $globali18n)) $globali18n[$plugin.'/'.$code] = $text;
    }
    return true;
  }

(the second function is a "private" function needed because the plugin's language file also sets $i18n).

BTW: it would be nice to have a function to determine if the plugin is included for the frontend or the admin backend, like:

Code:
function is_admin() {
  return basename($_SERVER['PHP_SELF']) != 'index.php';
}


Not sure, if this is the best way.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply


Messages In This Thread
unified directory for plugin translation files - by mvlcek - 2011-03-17, 02:33:20



Users browsing this thread: 5 Guest(s)