本文整理汇总了PHP中MO::import_from_file方法的典型用法代码示例。如果您正苦于以下问题:PHP MO::import_from_file方法的具体用法?PHP MO::import_from_file怎么用?PHP MO::import_from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MO
的用法示例。
在下文中一共展示了MO::import_from_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterOverrideLoadTextdomain
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: getMo
public function getMo($locale)
{
if (file_exists($file = $this->getMoFile($locale))) {
$mo = new \MO();
$mo->import_from_file($file);
return $mo;
}
return false;
}
示例3: MO
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: __i18n_load_db_mo
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: load_textdomain
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: MO
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: load_textdomain
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: translate
/**
* 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;
}
示例9: load_textdomain
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: get_translations_for_domain
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: array
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];
}
示例12: MO
/**
* @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: MO
function test_load_pot_file()
{
$mo = new MO();
$this->assertEquals(false, $mo->import_from_file(DIR_TESTDATA . '/pomo/mo.pot'));
}
示例14: MO
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;
}
示例15: justInTimeLocalisation
/**
* 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));
}
}
}