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


PHP MO::import_from_reader方法代码示例

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


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

示例1: array

 function admin_init()
 {
     $options = get_option('polylang');
     if (version_compare($options['version'], POLYLANG_VERSION, '<')) {
         if (version_compare($options['version'], '0.4', '<')) {
             $options['hide_default'] = 0;
         }
         // option introduced in 0.4
         // translation model changed in V0.5
         if (version_compare($options['version'], '0.5', '<')) {
             $ids = get_posts(array('numberposts' => -1, 'fields' => 'ids', 'post_type' => 'any', 'post_status' => 'any'));
             $this->upgrade_translations('post', $ids);
             $ids = get_terms($this->taxonomies, array('get' => 'all', 'fields' => 'ids'));
             $this->upgrade_translations('term', $ids);
         }
         // translation model changed in V0.5
         // deleting the old one has been delayed in V0.6 (just in case...)
         if (version_compare($options['version'], '0.6', '<')) {
             $listlanguages = $this->get_languages_list();
             $ids = get_posts(array('numberposts' => -1, 'fields' => 'ids', 'post_type' => 'any', 'post_status' => 'any'));
             foreach ($ids as $id) {
                 foreach ($listlanguages as $lang) {
                     delete_post_meta($id, '_lang-' . $lang->slug);
                 }
             }
             $ids = get_terms($this->taxonomies, array('get' => 'all', 'fields' => 'ids'));
             foreach ($ids as $id) {
                 foreach ($listlanguages as $lang) {
                     delete_metadata('term', $id, '_lang-' . $lang->slug);
                 }
             }
         }
         if (version_compare($options['version'], '0.7', '<')) {
             $options['force_lang'] = 0;
         }
         // option introduced in 0.7
         // string translation storage model changed and option added in 0.8
         if (version_compare($options['version'], '0.8dev1', '<')) {
             if (function_exists('base64_decode')) {
                 $mo = new MO();
                 foreach ($this->get_languages_list() as $language) {
                     $reader = new POMO_StringReader(base64_decode(get_option('polylang_mo' . $language->term_id)));
                     $mo->import_from_reader($reader);
                     $this->mo_export($mo, $language);
                 }
             }
             $options['redirect_lang'] = 0;
             // option introduced in 0.8
         }
         if (version_compare($options['version'], '0.8.8', '<')) {
             flush_rewrite_rules();
         }
         // rewrite rules have been modified in 0.8.8
         if (version_compare($options['version'], '0.9', '<')) {
             $options['sync'] = defined('PLL_SYNC') && !PLL_SYNC ? 0 : 1;
         }
         // the option replaces PLL_SYNC in 0.9
         $options['version'] = POLYLANG_VERSION;
         update_option('polylang', $options);
     }
 }
开发者ID:uoyknaht,项目名称:kc,代码行数:61,代码来源:polylang.php

示例2: array

 function get_translations($language, $args = array())
 {
     global $wpdb;
     $translations = array();
     // defaults
     $defaults = array('types' => array('core'));
     extract($defaults);
     extract($args, EXTR_OVERWRITE);
     if (!class_exists('WP_Http')) {
         include_once ABSPATH . WPINC . '/class-http.php';
     }
     $client = new WP_Http();
     foreach ($types as $type) {
         if (isset($this->translation_files[$language][$type]['url'])) {
             $response = $client->request($this->translation_files[$language][$type]['url'], array('timeout' => 15));
             if (is_wp_error($response)) {
                 $err = __('Error getting the translation file. Please go back and try again.', 'wordpress-language');
                 if (isset($response->errors['http_request_failed'][0])) {
                     $err .= '<br />' . $response->errors['http_request_failed'][0];
                 }
                 echo '<div class="error"><p>' . $err . '</p></div>';
                 return false;
             }
             $mo = new MO();
             $pomo_reader = new POMO_StringReader($response['body']);
             $mo->import_from_reader($pomo_reader);
             foreach ($mo->entries as $key => $v) {
                 $tpairs = array();
                 $v->singular = str_replace("\n", '\\n', $v->singular);
                 $tpairs[] = array('string' => $v->singular, 'translation' => $v->translations[0], 'name' => !empty($v->context) ? $v->context . ': ' . $v->singular : md5($v->singular));
                 if ($v->is_plural) {
                     $v->plural = str_replace("\n", '\\n', $v->plural);
                     $tpairs[] = array('string' => $v->plural, 'translation' => !empty($v->translations[1]) ? $v->translations[1] : $v->translations[0], 'name' => !empty($v->context) ? $v->context . ': ' . $v->plural : md5($v->singular));
                 }
                 foreach ($tpairs as $pair) {
                     $existing_translation = $wpdb->get_var($wpdb->prepare("\n                            SELECT st.value \n                            FROM {$wpdb->prefix}icl_string_translations st\n                            JOIN {$wpdb->prefix}icl_strings s ON st.string_id = s.id\n                            WHERE s.context = %s AND s.name = %s AND st.language = %s \n                        ", self::CONTEXT, $pair['name'], $language));
                     if (empty($existing_translation)) {
                         $translations['new'][] = array('string' => $pair['string'], 'translation' => '', 'new' => $pair['translation'], 'name' => $pair['name']);
                     } else {
                         if (strcmp($existing_translation, $pair['translation']) !== 0) {
                             $translations['updated'][] = array('string' => $pair['string'], 'translation' => $existing_translation, 'new' => $pair['translation'], 'name' => $pair['name']);
                         }
                     }
                 }
             }
         }
     }
     return $translations;
 }
开发者ID:PHQ-Design,项目名称:souza-lima,代码行数:49,代码来源:auto-download-locales.php

示例3: load_translations_from_mo

 private function load_translations_from_mo($mo_file)
 {
     $translations = array();
     $mo = new MO();
     $pomo_reader = new POMO_CachedFileReader($mo_file);
     $mo->import_from_reader($pomo_reader);
     foreach ($mo->entries as $str => $v) {
         $str = str_replace("\n", '\\n', $v->singular);
         $translations[] = array('orig' => $str, 'trans' => $v->translations[0], 'context' => $v->context);
         if ($v->is_plural) {
             $str = str_replace("\n", '\\n', $v->plural);
             $translation = !empty($v->translations[1]) ? $v->translations[1] : $v->translations[0];
             $translations[] = array('orig' => $str, 'trans' => $translation, 'context' => $v->context);
         }
     }
     return $translations;
 }
开发者ID:crazyyy,项目名称:octagram,代码行数:17,代码来源:wpml-string-scanner.class.php


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