Exemplo n.º 1
0
 function setup_2()
 {
     global $l10n_wiz_upgrade, $l10n_default_strings_lang, $l10n_default_strings_perm, $l10n_default_strings, $prefs;
     #
     #	First things first, try to set the installation langs...
     #
     $gbp_l10n_key = 'gbp_admin_library_languages';
     $l10n_wiz_upgrade = array();
     $prev_gbp_l10n_langs = array();
     if (isset($prefs[$gbp_l10n_key])) {
         $prev_gbp_l10n_langs = $prefs[$gbp_l10n_key];
     }
     $prev_l10n_langs = $this->parent->preferences['l10n-languages']['value'];
     if (!empty($prev_gbp_l10n_langs)) {
         #
         #	Expand all two digit codes...
         #
         $langs = array();
         foreach ($prev_gbp_l10n_langs as $lang) {
             $lang = trim($lang);
             $len = strlen($lang);
             if (2 === $len) {
                 $ok = MLPLanguageHandler::iso_639_langs($lang, 'valid_short');
                 if ($ok) {
                     $lang = MLPLanguageHandler::iso_639_langs($lang, 'short2long');
                 }
             } elseif (5 === $len) {
                 $ok = MLPLanguageHandler::iso_639_langs($lang, 'valid_long');
             }
             if ($ok) {
                 $langs[] = $lang;
             }
         }
         $l10n_wiz_upgrade = $langs;
         $languages = $langs;
         @safe_delete('txp_prefs', "`name`='{$gbp_l10n_key}'");
     } elseif (!empty($prev_l10n_langs)) {
         # reinstall, keep old language settings.
         $languages = $prev_l10n_langs;
     } else {
         # fresh install, use all currently installed languages.
         $languages = MLPLanguageHandler::get_installation_langs();
     }
     $this->set_preference('l10n-languages', $languages);
     $this->add_report_item(gTxt('l10n-setup_2_langs', array('{langs}' => join(', ', $languages))), true);
     #
     #	Reset the session variable (in case of a language switch and then a reinstall)...
     #
     @session_start();
     $temp = LANG;
     $tmp = substr($temp, 0, 2);
     if (!empty($temp)) {
         $_SESSION['l10n_admin_short_lang'] = $tmp;
         $_SESSION['l10n_admin_long_lang'] = $temp;
     }
     # Adds the strings this class needs. These lines makes them editable via the "plugins" string tab.
     $l10n_default_strings = array_merge($l10n_default_strings, $l10n_default_strings_perm);
     $ok = MLPStrings::insert_strings($this->parent->strings_prefix, $l10n_default_strings, $l10n_default_strings_lang, 'admin', 'l10n');
     $this->add_report_item(gTxt('l10n-setup_2_main'), $ok);
     #
     #	Also add any strings we can for other installation languages...
     #
     $langs = MLPLanguageHandler::get_installation_langs();
     if (empty($langs)) {
         return;
     }
     $tmp_lang = $l10n_default_strings_lang;
     $tmp_str_perm = $l10n_default_strings_perm;
     $tmp_str_def = $l10n_default_strings;
     foreach ($langs as $lang) {
         if ($lang === $tmp_lang) {
             continue;
         }
         $merged = array();
         $file_name = txpath . DS . 'lib' . DS . 'l10n_' . $lang . '_strings.php';
         if (is_readable($file_name)) {
             include_once $file_name;
             $merged = array_merge($l10n_default_strings, $l10n_default_strings_perm);
             MLPStrings::insert_strings($this->parent->strings_prefix, $merged, $l10n_default_strings_lang, 'admin', 'l10n', true);
         }
     }
     if (isset($merged)) {
         unset($merged);
     }
     #
     #	Restore values...
     #
     $l10n_default_strings_lang = $tmp_lang;
     $l10n_default_strings_perm = $tmp_str_perm;
     $l10n_default_strings = $tmp_str_def;
 }
Exemplo n.º 2
0
 function get_native_name_of_lang($code)
 {
     /*
     Returns the native name of the given language code.
     */
     return MLPLanguageHandler::iso_639_langs($code) ? MLPLanguageHandler::iso_639_langs($code) : MLPLanguageHandler::iso_639_langs('en');
 }
Exemplo n.º 3
0
 function _l10n_inject_lang_markers_cb($matches)
 {
     global $l10n_language, $l10n_replace_strings, $l10n_url_exclusions, $prefs;
     $debug = 0;
     #$debug = !$l10n_replace_strings['insert_blank'];
     $logfile = $prefs['tempdir'] . DS . 'l10n.log.txt';
     static $counter;
     if (!isset($counter)) {
         $counter = 0;
     }
     $counter += 1;
     $insert = 0;
     $result = $matches[0];
     $query = '';
     if (isset($prefs['l10n_language_marker_func']) and is_callable($prefs['l10n_language_marker_func'])) {
         $callback_language_marker = call_user_func($prefs['l10n_language_marker_func'], $l10n_language['long']);
     }
     if (!$callback_language_marker) {
         $callback_language_marker = $l10n_language['short'];
     }
     if ($debug) {
         error_log(n . n . 'Hit #' . $counter . ' : [' . $matches[0] . ']', 3, $logfile);
     }
     if (@$l10n_replace_strings['insert_blank'] && empty($matches[0])) {
         $insert = 1;
         if ($debug) {
             error_log(' ... Blank! ... INSERTING : /' . $callback_language_marker . '/', 3, $logfile);
         }
     } else {
         if ($debug) {
             error_log(' ... PARSING : ' . $matches[2], 3, $logfile);
         }
         $url = trim($matches[2], '/');
         $url = strtolower($url);
         $qs = strpos($url, '?');
         if ($qs !== false) {
             $url = substr($url, 0, $qs);
         }
         $r = array_map('urldecode', explode('/', $url));
         if (isset($prefs['l10n_detect_language_func']) and is_callable($prefs['l10n_detect_language_func'])) {
             $callback_detect_language = call_user_func($prefs['l10n_detect_language_func'], $req);
         }
         if (is_array($callback_detect_language) and isset($callback_detect_language['lang']) and isset($callback_detect_language['lang']['long'])) {
             $callback_detect_language = $callback_detect_language['lang']['long'];
         } else {
             $callback_detect_language = $r[0];
         }
         if ($debug) {
             error_log(n . t . '  -> ' . $callback_detect_language, 3, $logfile);
         }
         $excluded = in_array($r[0], $l10n_url_exclusions);
         if ($excluded) {
             if ($debug) {
                 error_log(' ... SKIPPING: this is an excluded section/area ', 3, $logfile);
             }
         } else {
             if (!@$l10n_replace_strings['insert_blank'] && empty($matches[1])) {
                 if ($debug) {
                     error_log(' ... SKIPPING: not a URL ', 3, $logfile);
                 }
             } elseif (empty($callback_detect_language) || !(MLPLanguageHandler::is_valid_short_code($callback_detect_language) && MLPLanguageHandler::iso_639_langs($callback_detect_language, 'valid_long'))) {
                 if ($debug) {
                     error_log(' ... INSERTING : ' . $callback_language_marker, 3, $logfile);
                 }
                 $insert = 1;
             } else {
                 if ($debug) {
                     error_log(' ... SKIPPING: language (' . $callback_detect_language . ') present ', 3, $logfile);
                 }
             }
         }
     }
     if ($insert) {
         $extra = '';
         if ($matches[2][0] !== '/') {
             $extra = '/';
         }
         $result = $l10n_replace_strings['start_rep'] . $matches[1] . '/' . $callback_language_marker . $extra . $matches[2] . $l10n_replace_strings['stop_rep'];
         if ($debug) {
             error_log(n . t . '  ->  ' . $result, 3, $logfile);
         }
     }
     return $result;
 }