示例#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;
 }
示例#2
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;
}
示例#3
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;
}
示例#4
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;
 }
示例#5
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;
}
示例#6
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;
}
示例#8
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;
 }
示例#9
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;
}
 /**
  * @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;
 }
示例#11
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;
}
示例#12
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);
         }
     }
 }
/**
 * 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;
}
示例#14
0
/**
 * Replaces a string in the internationalisation table with a custom value.
 *
 * @global object $l10n List of domain translated string (gettext_reader) objects
 * @param string $find Text to find in the table
 * @param string $replace Replacement text
 * @since 2.0
 */
function dpa_override_i18n($find, $replace)
{
    global $l10n;
    if (isset($l10n['buddypress']) && isset($l10n['buddypress']->entries[$find])) {
        $l10n['buddypress']->entries[$find]->translations[0] = $replace;
    } else {
        $mo = new MO();
        $mo->add_entry(array('singular' => $find, 'translations' => array($replace)));
        if (isset($l10n['buddypress'])) {
            $mo->merge_with($l10n['buddypress']);
        }
        $l10n['buddypress'] = $mo;
    }
}
示例#15
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;
}