Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unified directory for plugin translation files
#5
As I'm currently consolidating my plugins and making them translateable, I've created common functions which provide the above functionality - not fully tested yet:

Code:
<?php
// these functions should be in the GetSimple Core:
if (!function_exists('is_admin')) {
  function is_admin() {
    return basename($_SERVER['PHP_SELF']) != 'index.php';
  }
}

if (!function_exists('load_i18n')) {

  $i18n_plugins_loaded = array();  

  function load_i18n($plugin, $language=null, $default_language=null) {
    global $i18n, $LANG, $i18n_plugins_loaded;
    if (in_array($plugin, $i18n_plugins_loaded)) return;
    if (!$language) $language = $LANG;
    if (!$default_language) $default_language = 'en_US';
    $langs = array($language);
    $pos = strpos($language,'_');
    if ($pos !== false) {
      $lang = substr($language, 0, $pos);
      if (!in_array($lang, $langs)) $langs[] = $lang;
    }
    if (!in_array($default_language, $langs)) $langs[] = $default_language;
    foreach ($langs as $lang) load_i18n_impl($plugin, $lang, $i18n);
    $i18n_plugins_loaded[] = $plugin;
  }

  function load_i18n_impl($plugin, $lang, &$globali18n) {
    $i18n = array();
    //@include(GSPLUGINPATH.'lang/'.$plugin.'_'.$lang.'.php');
    @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;
    }
  }
}

I think these functions should be included in the Core. They can be used, if the plugin developer adheres to the standards - here the language files are expected in plugins/<plugin>/lang/<lang>.php (but that can be changed).

BTW: Is there a reason to have translation files as code as opposed to property files (like standard for Java)?

Code:
PAGES=View Pages
DELETE_PAGE=Delete this page
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-16, 06:05:48



Users browsing this thread: 1 Guest(s)