当前位置: 首页>>代码示例>>PHP>>正文


PHP MO::add_entry方法代码示例

本文整理汇总了PHP中MO::add_entry方法的典型用法代码示例。如果您正苦于以下问题:PHP MO::add_entry方法的具体用法?PHP MO::add_entry怎么用?PHP MO::add_entry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MO的用法示例。


在下文中一共展示了MO::add_entry方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

 function test_export_mo_file()
 {
     $entries = array();
     $entries[] = new Translation_Entry(array('singular' => 'pink', 'translations' => array('розов')));
     $no_translation_entry = new Translation_Entry(array('singular' => 'grey'));
     $entries[] = new Translation_Entry(array('singular' => 'green', 'plural' => 'greens', 'translations' => array('зелен', 'зелени')));
     $entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'color', 'translations' => array('червен')));
     $entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'bull', 'translations' => array('бик')));
     $entries[] = new Translation_Entry(array('singular' => 'maroon', 'plural' => 'maroons', 'context' => 'context', 'translations' => array('пурпурен', 'пурпурни')));
     $mo = new MO();
     $mo->set_header('Project-Id-Version', 'Baba Project 1.0');
     foreach ($entries as $entry) {
         $mo->add_entry($entry);
     }
     $mo->add_entry($no_translation_entry);
     $temp_fn = $this->temp_filename();
     $mo->export_to_file($temp_fn);
     $again = new MO();
     $again->import_from_file($temp_fn);
     $this->assertEquals(count($entries), count($again->entries));
     foreach ($entries as $entry) {
         $this->assertEquals($entry, $again->entries[$entry->key()]);
     }
 }
开发者ID:rmccue,项目名称:GlotPress,代码行数:24,代码来源:test_mo.php

示例2: isset

 /**
  * update language translate, catch request from ajax update translate string to po and mo file
  * @since 1.0
  */
 function save_language()
 {
     $selected_lang = $_POST['lang_name'];
     $langArr = $this->get_language_list();
     //file name invalid
     if ($selected_lang == '' || $selected_lang == null || $selected_lang == 'null' || !in_array($selected_lang, $langArr)) {
         wp_send_json(array('success' => false, 'msg' => __("Invalid file name!", ET_DOMAIN)));
         exit;
     }
     $singular = isset($_POST['singular']) ? $_POST['singular'] : array();
     $translation = isset($_POST['translations']) ? $_POST['translations'] : array();
     $context = isset($_POST['context']) ? $_POST['context'] : array();
     if (empty($singular) || empty($translation) || empty($context)) {
         wp_send_json(array('success' => true, 'msg' => __("There was no changes in your translation.", ET_DOMAIN)));
     }
     $mo = new MO();
     $po = new PO();
     $language_files = array('mo' => $mo, 'po' => $po);
     foreach ($language_files as $type => $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 <enginethemes@enginethemes.com>');
         // import language file from et_content/lang if exist
         if ($type == 'mo') {
             // mo file
             if (in_array($selected_lang, get_available_languages(THEME_LANGUAGE_PATH))) {
                 $mo->import_from_file(THEME_LANGUAGE_PATH . '/' . $selected_lang . '.mo');
             } else {
                 $mo->import_from_file(DEFAULT_LANGUAGE_PATH . '/' . $selected_lang . '.mo');
             }
         } else {
             // po file
             if (file_exists(THEME_LANGUAGE_PATH . '/' . $selected_lang . '.po')) {
                 $mo->import_from_file(THEME_LANGUAGE_PATH . '/' . $selected_lang . '.po');
             } elseif (file_exists(DEFAULT_LANGUAGE_PATH . '/' . $selected_lang . '.mo')) {
                 $temp = new MO();
                 $temp->import_from_file(DEFAULT_LANGUAGE_PATH . '/' . $selected_lang . '.mo');
                 $mo->entries = $temp->entries;
             } else {
                 $mo->import_from_file(DEFAULT_LANGUAGE_PATH . '/engine.po');
             }
         }
         foreach ($singular as $key => $value) {
             // if( $translation[$key] == "" && $type == 'mo' ) {
             // 	if(isset( $mo->entries[$value] ))
             // 		unset($mo->entries[$value]);
             // 	continue;
             // }
             if ($context[$key] != '') {
                 $mo->add_entry(new Translation_Entry(array('singular' => trim(stripcslashes($value), ''), 'context' => trim(stripcslashes($context[$key]), ''), 'translations' => array('0' => trim(stripcslashes($translation[$key]), '')))));
             } else {
                 $mo->add_entry(new Translation_Entry(array('singular' => trim(stripcslashes($value), ''), 'translations' => array('0' => trim(stripcslashes($translation[$key]), '')))));
             }
         }
         $mo->export_to_file(THEME_LANGUAGE_PATH . '/' . $selected_lang . '.' . $type);
     }
     wp_send_json(array('success' => true, 'msg' => __("Translation saved! ", ET_DOMAIN)));
 }
开发者ID:rinodung,项目名称:wp-question,代码行数:68,代码来源:class-ae-languages.php

示例3: array

 function test_export_should_not_include_empty_translations()
 {
     $entries = array();
     $mo = new MO();
     $mo->add_entry(array('singular' => 'baba', 'translations' => array('', '')));
     $temp_fn = $this->temp_filename();
     $mo->export_to_file($temp_fn);
     $again = new MO();
     $again->import_from_file($temp_fn);
     $this->assertEquals(0, count($again->entries));
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:11,代码来源:mo.php

示例4: dpa_override_i18n

/**
 * 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;
    }
}
开发者ID:nxtclass,项目名称:NXTClass,代码行数:22,代码来源:achievements-core.php

示例5: MO

 function mo_import($lang)
 {
     $mo = new MO();
     if ($strings = get_option('polylang_mo' . $lang->term_id)) {
         foreach ($strings as $msg) {
             $mo->add_entry($mo->make_entry($msg[0], $msg[1]));
         }
     }
     return $mo;
 }
开发者ID:uoyknaht,项目名称:kc,代码行数:10,代码来源:base.php

示例6: array


//.........这里部分代码省略.........
                     // update the default language option if necessary
                     if ($options['default_lang'] == $old_slug) {
                         $options['default_lang'] = $_POST['slug'];
                         update_option('polylang', $options);
                     }
                 }
                 // and finally update the language itself
                 $args = array('name' => $_POST['name'], 'slug' => $_POST['slug'], 'description' => $_POST['description'], 'term_group' => $_POST['term_group']);
                 wp_update_term($lang_id, 'language', $args);
                 update_metadata('term', $lang_id, '_rtl', $_POST['rtl']);
                 flush_rewrite_rules();
                 // refresh rewrite rules
             }
             wp_redirect('admin.php?page=mlang' . ($error ? '&error=' . $error : ''));
             // to refresh the page (possible thanks to the $_GET['noheader']=true)
             exit;
             break;
         case 'nav-menus':
             check_admin_referer('nav-menus-lang', '_wpnonce_nav-menus-lang');
             $menu_lang = $_POST['menu-lang'];
             foreach ($locations as $location => $description) {
                 foreach ($this->get_switcher_options('menu') as $key => $str) {
                     $menu_lang[$location][$key] = isset($menu_lang[$location][$key]) ? 1 : 0;
                 }
             }
             update_option('polylang_nav_menus', $menu_lang);
             break;
         case 'string-translation':
             check_admin_referer('string-translation', '_wpnonce_string-translation');
             $strings = $this->get_strings();
             foreach ($this->get_languages_list() as $language) {
                 $mo = $this->mo_import($language);
                 foreach ($_POST['translation'][$language->name] as $key => $translation) {
                     $mo->add_entry($mo->make_entry($strings[$key]['string'], stripslashes($translation)));
                 }
                 $mo->add_entry($mo->make_entry('', ''));
                 // empty string translation, just in case
                 // clean database
                 if (isset($_POST['clean']) && $_POST['clean']) {
                     $new_mo = new MO();
                     foreach ($strings as $string) {
                         $new_mo->add_entry($mo->make_entry($string['string'], $mo->translate($string['string'])));
                     }
                 }
                 $this->mo_export(isset($new_mo) ? $new_mo : $mo, $language);
             }
             // to refresh the page (possible thanks to the $_GET['noheader']=true)
             wp_redirect('admin.php?page=mlang&tab=strings' . (isset($_GET['paged']) ? '&paged=' . $_GET['paged'] : ''));
             exit;
             break;
         case 'options':
             check_admin_referer('options-lang', '_wpnonce_options-lang');
             $options['default_lang'] = $_POST['default_lang'];
             if (isset($_POST['force_lang'])) {
                 $options['force_lang'] = $_POST['force_lang'];
             }
             if (isset($_POST['rewrite'])) {
                 $options['rewrite'] = $_POST['rewrite'];
             }
             foreach (array('browser', 'hide_default', 'redirect_lang', 'sync') as $key) {
                 $options[$key] = isset($_POST[$key]) ? 1 : 0;
             }
             update_option('polylang', $options);
             // refresh rewrite rules in case rewrite or hide_default options have been modified
             // it seems useless to refresh permastruct here
             flush_rewrite_rules();
开发者ID:uoyknaht,项目名称:kc,代码行数:67,代码来源:admin.php


注:本文中的MO::add_entry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。