示例#1
0
文件: Api.php 项目: kmvan/poil10n
 public function filterOverrideLoadTextdomain($override, $domain, $mofile)
 {
     global $l10n;
     $key = md5($mofile);
     $data = $this->getCacheFileContent($key);
     $mo = new \MO();
     if (!$data) {
         if (is_file($mofile) && $mo->import_from_file($mofile)) {
             $data = ['entries' => $mo->entries, 'headers' => $mo->headers];
             $this->setCacheFileContent($key, $data);
         } else {
             return false;
         }
     } else {
         if (isset($data['entries'])) {
             $mo->entries = $data['entries'];
         }
         if (isset($data['headers'])) {
             $mo->headers = $data['headers'];
         }
     }
     if (isset($l10n[$domain])) {
         $mo->merge_with($l10n[$domain]);
     }
     $l10n[$domain] =& $mo;
     return true;
 }
 public function getMo($locale)
 {
     if (file_exists($file = $this->getMoFile($locale))) {
         $mo = new \MO();
         $mo->import_from_file($file);
         return $mo;
     }
     return false;
 }
示例#3
0
文件: app.php 项目: akirk/GlotPress
function &load_translations($mo_filename)
{
    if (is_readable($mo_filename)) {
        $translations = new MO();
        $translations->import_from_file($mo_filename);
    } else {
        $translations = new Translations();
    }
    return $translations;
}
示例#4
0
文件: i18n.php 项目: pf5512/phpstudy
function __i18n_load_db_mo( $lang, $mofile )
{
    global $__i18n;
    if ( ! is_readable($mofile) ) return false;
    $mo = new MO();
    if ( ! $mo->import_from_file($mofile) ) return false;
    if ( isset($__i18n[$lang]) )
    {
        $mo->merge_with($__i18n[$lang]);
    }
    $__i18n[$lang] = &$mo;
    return true;
}
示例#5
0
文件: l10n.php 项目: rmccue/GlotPress
function load_textdomain($domain, $mofile)
{
    global $l10n;
    if (!is_readable($mofile)) {
        return;
    }
    $mo = new MO();
    $mo->import_from_file($mofile);
    if (isset($l10n[$domain])) {
        $mo->merge_with($l10n[$domain]);
    }
    $l10n[$domain] =& $mo;
}
示例#6
0
 static function load_textdomain($domain, $mofile)
 {
     if (!is_readable($mofile)) {
         return false;
     }
     $mo = new MO();
     if (!$mo->import_from_file($mofile)) {
         return false;
     }
     if (isset(self::$l10n[$domain])) {
         $mo->merge_with(self::$l10n[$domain]);
     }
     self::$l10n[$domain] =& $mo;
     return true;
 }
示例#7
0
文件: i18n.php 项目: ydhl/yangzie
function load_textdomain($domain, $mofile)
{
    $l10n = get_i18n_cache();
    if (!is_readable($mofile)) {
        return false;
    }
    $mo = new MO();
    if (!$mo->import_from_file($mofile)) {
        return false;
    }
    if (isset($l10n[$domain])) {
        $mo->merge_with($l10n[$domain]);
    }
    $l10n[$domain] =& $mo;
    set_i18n_cache($l10n);
    return true;
}
示例#8
0
/**
 * Load a .mo file into the text domain $domain.
 *
 * If the text domain already exists, the translations will be merged. If both
 * sets have the same string, the translation from the original value will be taken.
 *
 * On success, the .mo file will be placed in the $l10n global by $domain
 * and will be a MO object.
 *
 * @param    string     $domain Text domain. Unique identifier for retrieving translated strings.
 * @param    string     $mofile Path to the .mo file.
 *
 * @return   boolean    True on success, false on failure.
 *
 * Inspired from Luna <http://getluna.org>
 */
function translate($mofile, $domain = 'featherbb', $language = false)
{
    global $l10n;
    if (!$language) {
        $mofile = ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/' . $mofile . '.mo';
    } else {
        $mofile = ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . $language . '/' . $mofile . '.mo';
    }
    if (!is_readable($mofile)) {
        return false;
    }
    $mo = new MO();
    if (!$mo->import_from_file($mofile)) {
        return false;
    }
    if (isset($l10n[$domain])) {
        $mo->merge_with($l10n[$domain]);
    }
    $l10n[$domain] =& $mo;
    return true;
}
function load_textdomain($domain, $mofile)
{
    global $l10n;
    $plugin_override = apply_filters('override_load_textdomain', false, $domain, $mofile);
    if (true == $plugin_override) {
        return true;
    }
    do_action('load_textdomain', $domain, $mofile);
    $mofile = apply_filters('load_textdomain_mofile', $mofile, $domain);
    if (!is_readable($mofile)) {
        return false;
    }
    $mo = new MO();
    if (!$mo->import_from_file($mofile)) {
        return false;
    }
    if (isset($l10n[$domain])) {
        $mo->merge_with($l10n[$domain]);
    }
    $l10n[$domain] =& $mo;
    return true;
}
示例#10
0
 private function get_translations_for_domain($domain = "default")
 {
     if ($this->entries != null) {
         return true;
     }
     $mo = new MO();
     $current_language = JFactory::getLanguage();
     $mo_file = JPATH_COMPONENT . DIRECTORY_SEPARATOR . "language" . DIRECTORY_SEPARATOR . $domain . "-" . $current_language->getTag() . ".mo";
     if (!file_exists($mo_file)) {
         $mo_file = JPATH_COMPONENT . DIRECTORY_SEPARATOR . "language" . DIRECTORY_SEPARATOR . $domain . "-" . str_replace("-", "_", $current_language->getTag()) . ".mo";
         if (!file_exists($mo_file)) {
             return false;
         }
     }
     if (!$mo->import_from_file($mo_file)) {
         return false;
     }
     if (!isset($lang[$domain])) {
         $lang[$domain] = $mo;
     }
     $this->merge_with($lang[$domain]);
 }
示例#11
0
 function get_translation_from_woocommerce_mo_file($string, $language, $return_original = true)
 {
     global $sitepress;
     $original_string = $string;
     if (!isset($this->translations_from_mo_file[$original_string][$language])) {
         if (!isset($this->translations_from_mo_file[$original_string])) {
             $this->translations_from_mo_file[$original_string] = array();
         }
         if (!isset($this->mo_files[$language])) {
             $mo = new MO();
             $mo_file = WP_LANG_DIR . '/plugins/woocommerce-' . $sitepress->get_locale($language) . '.mo';
             if (!file_exists($mo_file)) {
                 return $return_original ? $string : null;
             }
             $mo->import_from_file($mo_file);
             $this->mo_files[$language] =& $mo->entries;
         }
         if (in_array($string, array('product', 'product-category', 'product-tag'))) {
             $string = 'slug' . chr(4) . $string;
         }
         if (isset($this->mo_files[$language][$string])) {
             $this->translations_from_mo_file[$original_string][$language] = $this->mo_files[$language][$string]->translations[0];
         } else {
             $this->translations_from_mo_file[$original_string][$language] = $return_original ? $original_string : null;
         }
     }
     return $this->translations_from_mo_file[$original_string][$language];
 }
 /**
  * @param bool   $override Whether to override the .mo file loading. Default false.
  * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
  * @param string $file     Path to the MO file.
  * @return bool
  */
 function _override_load_textdomain_filter($override, $domain, $file)
 {
     global $l10n;
     if (!is_readable($file)) {
         return false;
     }
     $mo = new MO();
     if (!$mo->import_from_file($file)) {
         return false;
     }
     if (isset($l10n[$domain])) {
         $mo->merge_with($l10n[$domain]);
     }
     $l10n[$domain] =& $mo;
     return true;
 }
示例#13
0
 function test_load_pot_file()
 {
     $mo = new MO();
     $this->assertEquals(false, $mo->import_from_file(DIR_TESTDATA . '/pomo/mo.pot'));
 }
 function get_translation_from_woocommerce_mo_file($string, $language)
 {
     global $sitepress;
     $mo = new MO();
     $mo_file = WP_LANG_DIR . '/plugins/woocommerce-' . $sitepress->get_locale($language) . '.mo';
     if (!file_exists($mo_file)) {
         return $string;
     }
     $mo->import_from_file($mo_file);
     $translations = $mo->entries;
     if (in_array($string, array('product', 'product-category', 'product-tag'))) {
         $string = 'slug' . chr(4) . $string;
     }
     if (isset($translations[$string])) {
         return $translations[$string]->translations[0];
     }
     return $string;
 }
 /**
  * load any enqueued locales as localisations on the main script
  */
 public function justInTimeLocalisation()
 {
     if (!empty($this->locales)) {
         $domain = 'flexible-map';
         $i18n = array();
         // map old two-character language-only locales that now need to target language_country translations
         $upgradeMap = array('bg' => 'bg_BG', 'cs' => 'cs_CZ', 'da' => 'da_DK', 'de' => 'de_DE', 'es' => 'es_ES', 'fa' => 'fa_IR', 'fr' => 'fr_FR', 'gl' => 'gl_ES', 'he' => 'he_IL', 'hi' => 'hi_IN', 'hu' => 'hu_HU', 'id' => 'id_ID', 'is' => 'is_IS', 'it' => 'it_IT', 'ko' => 'ko_KR', 'lt' => 'lt_LT', 'mk' => 'mk_MK', 'ms' => 'ms_MY', 'mt' => 'mt_MT', 'nb' => 'nb_NO', 'nl' => 'nl_NL', 'pl' => 'pl_PL', 'pt' => 'pt_PT', 'ro' => 'ro_RO', 'ru' => 'ru_RU', 'sk' => 'sk_SK', 'sl' => 'sl_SL', 'sr' => 'sr_RS', 'sv' => 'sv_SE', 'ta' => 'ta_IN', 'tr' => 'tr_TR', 'zh' => 'zh_CN');
         foreach (array_keys($this->locales) as $locale) {
             // check for specific locale first, e.g. 'zh-CN', then for generic locale, e.g. 'zh'
             foreach (array($locale, substr($locale, 0, 2)) as $locale) {
                 if (isset($upgradeMap[$locale])) {
                     // upgrade old two-character language-only locales
                     $moLocale = $upgradeMap[$locale];
                 } else {
                     // revert locale name to WordPress locale name as used in .mo files
                     $moLocale = strtr($locale, '-', '_');
                 }
                 // compose full path to .mo file
                 $mofile = sprintf('%slanguages/%s-%s.mo', FLXMAP_PLUGIN_ROOT, $domain, $moLocale);
                 if (is_readable($mofile)) {
                     $mo = new MO();
                     if ($mo->import_from_file($mofile)) {
                         // pull all translation strings into a simplified format for our script
                         // TODO: handle plurals (not yet needed, don't have any)
                         $strings = array();
                         foreach ($mo->entries as $original => $translation) {
                             $strings[$original] = $translation->translations[0];
                         }
                         $i18n[$locale] = $strings;
                         break;
                     }
                 }
             }
         }
         if (!empty($i18n)) {
             wp_localize_script('flxmap', 'flxmap', array('i18n' => $i18n));
         }
     }
 }
 function translate_category_base($termlink, $term, $taxonomy)
 {
     global $sitepress_settings, $sitepress, $wp_rewrite, $wpdb, $woocommerce;
     static $no_recursion_flag;
     // handles product categories, product tags and attributes
     $wc_taxonomies = wc_get_attribute_taxonomies();
     foreach ($wc_taxonomies as $k => $v) {
         $wc_taxonomies_wc_format[] = 'pa_' . $v->attribute_name;
     }
     if (($taxonomy == 'product_cat' || $taxonomy == 'product_tag' || !empty($wc_taxonomies_wc_format) && in_array($taxonomy, $wc_taxonomies_wc_format)) && !$no_recursion_flag) {
         $cache_key = 'termlink#' . $taxonomy . '#' . $term->term_id;
         if ($link = wp_cache_get($cache_key, 'terms')) {
             $termlink = $link;
         } else {
             $no_recursion_flag = false;
             $strings_language = $sitepress_settings['st']['strings_language'];
             $term_language = $sitepress->get_element_language_details($term->term_taxonomy_id, 'tax_' . $taxonomy);
             if (!empty($term_language)) {
                 $permalinks = get_option('woocommerce_permalinks');
                 $base = $taxonomy == 'product_tag' ? $permalinks['tag_base'] : ($taxonomy == 'product_cat' ? $permalinks['category_base'] : $permalinks['attribute_base']);
                 if ($base === '') {
                     // handle exception - default woocommerce category and tag bases used
                     // get translation from WooCommerce mo files?
                     $base_sl = $taxonomy == 'product_tag' ? 'product-tag' : 'product-category';
                     // strings language
                     if ($term_language->language_code == $strings_language) {
                         $base = _x($base_sl, 'slug', 'woocommerce');
                         $base_translated = $base_sl;
                     } else {
                         $base = _x($base_sl, 'slug', 'woocommerce');
                         $mo_file = $woocommerce->plugin_path() . '/i18n/languages/woocommerce-' . $sitepress->get_locale($term_language->language_code) . '.mo';
                         if (file_exists($mo_file)) {
                             $mo = new MO();
                             $mo->import_from_file($mo_file);
                             $base_translated = $mo->translate($base_sl, 'slug');
                         } else {
                             $base_translated = $base_sl;
                         }
                     }
                 } else {
                     $string_identifier = $taxonomy == 'product_tag' || $taxonomy == 'product_cat' ? $taxonomy : 'attribute';
                     //
                     if ($term_language->language_code != $strings_language) {
                         $base_translated = $wpdb->get_var("\n                                            SELECT t.value \n                                            FROM {$wpdb->prefix}icl_strings s    \n                                            JOIN {$wpdb->prefix}icl_string_translations t ON t.string_id = s.id\n                                            WHERE s.value='" . esc_sql($base) . "' \n                                                AND s.language = '{$strings_language}' \n                                                AND s.name LIKE 'Url {$string_identifier} slug:%' \n                                                AND t.language = '{$term_language->language_code}'\n                            ");
                     } else {
                         $base_translated = $base;
                     }
                 }
                 if (!empty($base_translated) && $base_translated != $base) {
                     $buff = $wp_rewrite->extra_permastructs[$taxonomy]['struct'];
                     $wp_rewrite->extra_permastructs[$taxonomy]['struct'] = str_replace($base, $base_translated, $wp_rewrite->extra_permastructs[$taxonomy]['struct']);
                     $no_recursion_flag = true;
                     $termlink = get_term_link($term, $taxonomy);
                     $wp_rewrite->extra_permastructs[$taxonomy]['struct'] = $buff;
                 }
             }
             $no_recursion_flag = false;
             wp_cache_add($cache_key, $termlink, 'terms', 0);
         }
     }
     return $termlink;
 }
示例#17
0
/**
 * Load a .mo file into the text domain $domain.
 *
 * If the text domain already exists, the translations will be merged. If both
 * sets have the same string, the translation from the original value will be taken.
 *
 * On success, the .mo file will be placed in the $l10n global by $domain
 * and will be a MO object.
 *
 * @since 1.5.0
 *
 * @global array $l10n
 *
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
 * @param string $mofile Path to the .mo file.
 * @return bool True on success, false on failure.
 */
function load_textdomain($domain, $mofile)
{
    global $l10n;
    /**
     * Filter text domain and/or MO file path for loading translations.
     *
     * @since 2.9.0
     *
     * @param bool   $override Whether to override the text domain. Default false.
     * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
     * @param string $mofile   Path to the MO file.
     */
    $plugin_override = apply_filters('override_load_textdomain', false, $domain, $mofile);
    if (true == $plugin_override) {
        return true;
    }
    /**
     * Fires before the MO translation file is loaded.
     *
     * @since 2.9.0
     *
     * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     * @param string $mofile Path to the .mo file.
     */
    do_action('load_textdomain', $domain, $mofile);
    /**
     * Filter MO file path for loading translations for a specific text domain.
     *
     * @since 2.9.0
     *
     * @param string $mofile Path to the MO file.
     * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     */
    $mofile = apply_filters('load_textdomain_mofile', $mofile, $domain);
    if (!is_readable($mofile)) {
        return false;
    }
    $mo = new MO();
    if (!$mo->import_from_file($mofile)) {
        return false;
    }
    if (isset($l10n[$domain])) {
        $mo->merge_with($l10n[$domain]);
    }
    $l10n[$domain] =& $mo;
    return true;
}
示例#18
0
 /**
  * Loads MO file into the list of domains
  *
  * If the domain already exists, the inclusion will fail. If the
  * MO file is not readable, the inclusion will fail.
  *
  * @since 1.0
  * @uses CacheFileReader Reads the MO file
  * @uses gettext_reader Allows for retrieving translated strings
  *
  * @param string $domain Unique identifier for retrieving translated strings
  * @param string $mofile Path to the .mo file
  * @return bool Successfulness of loading textdomain
  */
 public static function load($domain, $mofile)
 {
     if (!is_readable($mofile)) {
         return;
     }
     $mo = new MO();
     $mo->import_from_file($mofile);
     if (isset(self::$translations[$domain])) {
         $mo->merge_with(self::$translations[$domain]);
     }
     self::$translations[$domain] =& $mo;
 }
/**
 * Load a collection of `.mo` files into the text domain $domain.
 *
 * If the text domain already exists, the translations will be merged. If both
 * sets have the same string, the translation from the original value will be taken.
 *
 * On success, the `.mo` files are placed in the $pll_l10n global by $domain
 * and will be a MO object.
 *
 * @param   string  $domain  Text domain. Unique identifier for retrieving translated strings.
 * @return  bool             True on success, false on failure.
 *
 * @package WordPress\Skeleton\Polylang
 * @see     WordPress\load_textdomain
 */
function pll_load_textdomain($domain)
{
    global $polylang, $pll_domains, $pll_l10n;
    if (!is_object($polylang)) {
        return false;
    }
    if (empty($pll_domains[$domain])) {
        return false;
    }
    $pll_domain = $pll_domains[$domain];
    $languages_list = $polylang->model->get_languages_list();
    foreach ($languages_list as $language) {
        $locale = $language->locale;
        $mo = new MO();
        foreach ($pll_domain as $dirname => $basename) {
            $mofile = $dirname . '/' . sprintf($basename, $locale);
            if (!is_readable($mofile)) {
                continue;
            }
            if (!$mo->import_from_file($mofile)) {
                continue;
            }
            if (isset($pll_l10n[$domain][$language->slug])) {
                $mo->merge_with($pll_l10n[$domain][$language->slug]);
            }
            $pll_l10n[$domain][$language->slug] = $mo;
        }
    }
    return true;
}
示例#20
0
 /**
  * Import MO file in class PO
  *
  *
  * @since 1.0.2 - only WP >= 2.8.4
  * @updated 1.0.5 - for wpmu
  * @param lang
  * @param $mofile since 1.0.5
  */
 function pomo_import_MO($lang = "", $mofile = "", $local = false)
 {
     $mo = new MO();
     if ($mofile == "" && $local == true) {
         $mofile = $this->get_template_directory . $this->xili_settings['langs_folder'] . '/' . 'local-' . $lang . '.mo';
     } else {
         if ('' == $mofile) {
             $mofile = $this->get_template_directory . $this->xili_settings['langs_folder'] . '/' . $lang . '.mo';
         }
     }
     if (file_exists($mofile)) {
         if (!$mo->import_from_file($mofile)) {
             return false;
         } else {
             return $mo;
         }
     } else {
         return false;
     }
 }
示例#21
0
function dem_l10n_options()
{
    echo demenu();
    __dem_polls_preview();
    ?>
	<div class="local-n">
		<form method="POST" action="">
			<?php 
    // получим все переводы из файлов
    $strs = array();
    foreach (glob(DEMOC_PATH . '*') as $file) {
        if (is_dir($file)) {
            continue;
        }
        if (!preg_match('~\\.php$~', basename($file))) {
            continue;
        }
        preg_match_all('~__dem\\(\\s?[\'"](.*?)[\'"]\\s?\\)~', file_get_contents($file), $match);
        if ($match[1]) {
            $strs = array_merge($strs, $match[1]);
        }
    }
    $strs = array_unique($strs);
    // выводим таблицу
    // отпарсим английский перевод из файла
    $mofile = DEMOC_PATH . DEM_LANG_DIRNAME . '/en_US.mo';
    $en_US = new MO();
    $en_US->import_from_file($mofile);
    $en_US = $en_US->entries;
    $i = 0;
    $_l10n = get_option('democracy_l10n');
    echo '<table class="wp-list-table widefat fixed posts">
			<thead>
				<tr>
					<th>' . __('Оригинал', 'dem') . '</th>
					<th>' . __('Ваш вариант', 'dem') . '</th>
				</tr>
			</thead>
			<tbody id="the-list">
			';
    foreach ($strs as $str) {
        $i++;
        $en_str = $en_US[$str]->translations[0];
        echo '
				<tr class="' . ($i % 2 ? 'alternate' : '') . '">
					<td>' . (get_locale() == 'ru_RU' ? $str : $en_str) . '</td>
					<td><textarea style="width:100%;height:50px;" name="l10n[' . esc_attr($str) . ']">' . (@$_l10n[$str] ?: __dem($str)) . '</textarea></td>
				</tr>';
    }
    echo '<tbody>
			</table>';
    ?>
			<p>
				<input class="button-primary" type="submit" name="dem_save_l10n" value="<?php 
    _e('Сохранить тексты', 'dem');
    ?>
">
				<input class="button" type="submit" name="dem_reset_l10n" value="<?php 
    _e('Сбростиь на начальные', 'dem');
    ?>
">
			</p>
		</form>
	</div>
	<?php 
}
示例#22
0
 /**
  * Load a Text Domain
  * @author Howard <*****@*****.**>
  * @static
  * @global array $l10n
  * @param string $domain
  * @param string $mofile
  * @return boolean
  */
 public static function load_textdomain($domain, $mofile)
 {
     global $l10n;
     unset($l10n[$domain]);
     if (!is_readable($mofile)) {
         return false;
     }
     $mo = new MO();
     if (!$mo->import_from_file($mofile)) {
         return false;
     }
     $l10n[$domain] =& $mo;
     return true;
 }
示例#23
0
 function test_load_pot_file()
 {
     $mo = new MO();
     $this->assertEquals(false, $mo->import_from_file('data/mo.pot'));
 }
示例#24
0
ob_end_flush();
flush();
// set memory limit to the same as WP.
if (function_exists('memory_get_usage') && inbytes(@ini_get('memory_limit')) < inbytes($STATIC['WP']['MEMORY_LIMIT'])) {
    @ini_set('memory_limit', $STATIC['WP']['MEMORY_LIMIT']);
}
//check existing Logfile
if (empty($STATIC) or !is_file($STATIC['LOGFILE'])) {
    delete_working_file();
    die('No logfile found!');
}
//load translation
if (is_file(dirname(__FILE__) . '/../lang/backwpup-' . $STATIC['WP']['WPLANG'] . '.mo')) {
    require $STATIC['WP']['ABSPATH'] . $STATIC['WP']['WPINC'] . '/pomo/mo.php';
    $TRANSLATE = new MO();
    $TRANSLATE->import_from_file(dirname(__FILE__) . '/../lang/backwpup-' . $STATIC['WP']['WPLANG'] . '.mo');
} else {
    require $STATIC['WP']['ABSPATH'] . $STATIC['WP']['WPINC'] . '/pomo/translations.php';
    $TRANSLATE = new NOOP_Translations();
}
//set ticks
declare (ticks=1);
//set timezone
date_default_timezone_set('UTC');
// set charakter encoding
if (!@mb_internal_encoding($STATIC['WP']['CHARSET'])) {
    mb_internal_encoding('UTF-8');
}
//set function for PHP user defineid error handling
set_error_handler('joberrorhandler', E_ALL | E_STRICT);
//Get type and check job runs
示例#25
0
/**
 * Load a .mo file into the text domain $domain.
 *
 * If the text domain already exists, the translations will be merged. If both
 * sets have the same string, the translation from the original value will be taken.
 *
 * On success, the .mo file will be placed in the $l10n global by $domain
 * and will be a MO object.
 *
 * @since 1.5.0
 *
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
 * @param string $mofile Path to the .mo file.
 * @return bool True on success, false on failure.
 */
function load_textdomain($domain, $mofile)
{
    global $l10n;
    $plugin_override = false;
    if (true == $plugin_override) {
        return true;
    }
    if (!is_readable($mofile)) {
        return false;
    }
    $mo = new MO();
    if (!$mo->import_from_file($mofile)) {
        return false;
    }
    if (isset($l10n[$domain])) {
        $mo->merge_with($l10n[$domain]);
    }
    $l10n[$domain] =& $mo;
    return true;
}
示例#26
0
 /**
  * change language : if language file not exist return false
  * if language file not in THEME_LANGUAGE_PATH copy it from DEFAULT_LANG to THEME_LANGUAGE_PATH
  * @since 1.0
  */
 function change_language()
 {
     $lang = $_REQUEST['lang_name'];
     if (!in_array($lang, $this->get_language_list())) {
         wp_send_json(array('success' => false));
     }
     if (!in_array($lang, get_available_languages(THEME_LANGUAGE_PATH))) {
         $mo = new MO();
         $mo->set_header('Project-Id-Version', THEME_NAME . 'v' . ET_VERSION);
         $mo->set_header('Report-Msgid-Bugs-To', ET_URL);
         $mo->set_header('MO-Creation-Date', gmdate('Y-m-d H:i:s+00:00'));
         $mo->set_header('MIME-Version', '1.0');
         $mo->set_header('Content-Type', 'text/plain; charset=UTF-8');
         $mo->set_header('Content-Transfer-Encoding', '8bit');
         $mo->set_header('MO-Revision-Date', '2010-MO-DA HO:MI+ZONE');
         $mo->set_header('Last-Translator', 'JOB <EMAIL@ADDRESS>');
         $mo->set_header('Language-Team', 'ENGINETHEMES.COM <*****@*****.**>');
         $mo->import_from_file(DEFAULT_LANGUAGE_PATH . '/' . $lang . '.mo');
         $mo->export_to_file(THEME_LANGUAGE_PATH . '/' . $lang . '.mo');
     }
     $this->set_site_language($lang);
     wp_send_json(array('success' => true, 'data' => array('ID' => $lang, 'lang_name' => $lang)));
 }
示例#27
0
文件: init.php 项目: renlong567/43168
 public function language($langid = 'default')
 {
     if (!function_exists('gettext')) {
         $this->language_status = 'user';
         $mofile = $this->dir_root . 'langs/' . $langid . '/LC_MESSAGES/' . $this->app_id . '.mo';
         if (!is_readable($mofile)) {
             return false;
         }
         include $this->dir_phpok . 'libs/pomo/mo.php';
         $this->lang = new NOOP_Translations();
         $mo = new MO();
         if (!$mo->import_from_file($mofile)) {
             return false;
         }
         $mo->merge_with($this->lang);
         $this->lang =& $mo;
     } else {
         $this->language_status = 'gettext';
         if ($langid != 'default' && $langid != 'cn') {
             putenv('LANG=' . $langid);
             setlocale(LC_ALL, $langid);
             bindtextdomain($this->app_id, $this->dir_root . 'langs');
             textdomain($this->app_id);
         } else {
             putenv('LANG=zh_CN');
             setlocale(LC_ALL, 'zh_CN');
             bindtextdomain($this->app_id, $this->dir_root . 'langs');
             textdomain($this->app_id);
         }
     }
 }
示例#28
0
function icl_st_load_translations_from_mo($mo_file)
{
    $translations = array();
    $mo = new MO();
    $mo->import_from_file($mo_file);
    foreach ($mo->entries as $str => $v) {
        $str = str_replace("\n", '\\n', $str);
        $translations[$str] = $v->translations[0];
    }
    return $translations;
}
示例#29
0
/**
 * Loads a MO file into the domain $domain.
 *
 * If the domain already exists, the translations will be merged. If both
 * sets have the same string, the translation from the original value will be taken.
 *
 * On success, the .mo file will be placed in the $yourls_l10n global by $domain
 * and will be a MO object.
 *
 * @since 1.6
 * @uses $yourls_l10n Gets list of domain translated string objects
 *
 * @param string $domain Unique identifier for retrieving translated strings
 * @param string $mofile Path to the .mo file
 * @return bool True on success, false on failure
 */
function yourls_load_textdomain($domain, $mofile)
{
    global $yourls_l10n;
    $plugin_override = yourls_apply_filter('override_load_textdomain', false, $domain, $mofile);
    if (true == $plugin_override) {
        return true;
    }
    yourls_do_action('load_textdomain', $domain, $mofile);
    $mofile = yourls_apply_filter('load_textdomain_mofile', $mofile, $domain);
    if (!is_readable($mofile)) {
        trigger_error('Cannot read file ' . str_replace(YOURLS_ABSPATH . '/', '', $mofile) . '.' . ' Make sure there is a language file installed. More info: http://yourls.org/translations');
        return false;
    }
    $mo = new MO();
    if (!$mo->import_from_file($mofile)) {
        return false;
    }
    if (isset($yourls_l10n[$domain])) {
        $mo->merge_with($yourls_l10n[$domain]);
    }
    $yourls_l10n[$domain] =& $mo;
    return true;
}