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


PHP Translations类代码示例

本文整理汇总了PHP中Translations的典型用法代码示例。如果您正苦于以下问题:PHP Translations类的具体用法?PHP Translations怎么用?PHP Translations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: read_translations_from_file

 public function read_translations_from_file($file_name, $project = null)
 {
     if (is_null($project)) {
         return false;
     }
     $translations = $this->read_originals_from_file($file_name);
     if (!$translations) {
         return false;
     }
     $originals = GP::$original->by_project_id($project->id);
     $new_translations = new Translations();
     foreach ($translations->entries as $key => $entry) {
         // we have been using read_originals_from_file to parse the file
         // so we need to swap singular and translation
         if ($entry->context == $entry->singular) {
             $entry->translations = array();
         } else {
             $entry->translations = array($entry->singular);
         }
         $entry->singular = null;
         foreach ($originals as $original) {
             if ($original->context == $entry->context) {
                 $entry->singular = $original->singular;
                 break;
             }
         }
         if (!$entry->singular) {
             error_log(sprintf(__('Missing context %s in project #%d', 'glotpress'), $entry->context, $project->id));
             continue;
         }
         $new_translations->add_entry($entry);
     }
     return $new_translations;
 }
开发者ID:chantalcoolsma,项目名称:GlotPress-WP,代码行数:34,代码来源:format.php

示例2: create_translations_with

 function create_translations_with($entries)
 {
     $translations = new Translations();
     foreach ($entries as $entry) {
         $translations->add_entry($entry);
     }
     return $translations;
 }
开发者ID:ramiy,项目名称:GlotPress-WP,代码行数:8,代码来源:test_thing_original.php

示例3: import

 function import($translations)
 {
     $this->set_memory_limit('256M');
     if (!isset($this->project) || !$this->project) {
         $this->project = GP::$project->get($this->project_id);
     }
     $locale = GP_Locales::by_slug($this->locale);
     $user = wp_get_current_user();
     $current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes'));
     $current_translations = new Translations();
     foreach ($current_translations_list as $entry) {
         $current_translations->add_entry($entry);
     }
     unset($current_translations_list);
     $translations_added = 0;
     foreach ($translations->entries as $entry) {
         if (empty($entry->translations)) {
             continue;
         }
         $is_fuzzy = in_array('fuzzy', $entry->flags);
         if ($is_fuzzy && !apply_filters('gp_translation_set_import_fuzzy_translations', true, $entry, $translations)) {
             continue;
         }
         $create = false;
         if ($translated = $current_translations->translate_entry($entry)) {
             // we have the same string translated
             // create a new one if they don't match
             $entry->original_id = $translated->original_id;
             $translated_is_different = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations;
             $create = apply_filters('gp_translation_set_import_over_existing', $translated_is_different);
         } else {
             // we don't have the string translated, let's see if the original is there
             $original = GP::$original->by_project_id_and_entry($this->project->id, $entry, '+active');
             if ($original) {
                 $entry->original_id = $original->id;
                 $create = true;
             }
         }
         if ($create) {
             if ($user) {
                 $entry->user_id = $user->ID;
             }
             $entry->translation_set_id = $this->id;
             $entry->status = apply_filters('gp_translation_set_import_status', $is_fuzzy ? 'fuzzy' : 'current');
             // check for errors
             $translation = GP::$translation->create($entry);
             $translation->set_status($entry->status);
             $translations_added += 1;
         }
     }
     gp_clean_translation_set_cache($this->id);
     do_action('gp_translations_imported', $this->id);
     return $translations_added;
 }
开发者ID:akirk,项目名称:GlotPress,代码行数:54,代码来源:translation-set.php

示例4: test_translations_merge

 function test_translations_merge()
 {
     $host = new Translations();
     $host->add_entry(new Translation_Entry(array('singular' => 'pink')));
     $host->add_entry(new Translation_Entry(array('singular' => 'green')));
     $guest = new Translations();
     $guest->add_entry(new Translation_Entry(array('singular' => 'green')));
     $guest->add_entry(new Translation_Entry(array('singular' => 'red')));
     $host->merge_with($guest);
     $this->assertEquals(3, count($host->entries));
     $this->assertEquals(array(), array_diff(array('pink', 'green', 'red'), array_keys($host->entries)));
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:12,代码来源:mo.php

示例5: test_multiple_imports_multiple_singulars

 function test_multiple_imports_multiple_singulars()
 {
     $originals = array(array('singular' => 'Good morning'), array('singular' => 'Good evening'));
     $translations1 = new Translations();
     $translations1->add_entry(new Translation_Entry(array('singular' => $originals[0]['singular'], 'translations' => array('Guten Morgen'))));
     $translations2 = new Translations();
     $translations2->add_entry(new Translation_Entry(array('singular' => $originals[1]['singular'], 'translations' => array('Guten Abend'))));
     $this->_verify_multiple_imports($originals, array(array('status' => 'current', 'translations' => $translations1, 'counts' => array('all_count' => 2, 'current_count' => 1, 'untranslated_count' => 1, 'waiting_count' => 0)), array('status' => 'current', 'translations' => $translations2, 'counts' => array('all_count' => 2, 'current_count' => 2, 'untranslated_count' => 0, 'waiting_count' => 0))));
     $this->_verify_multiple_imports($originals, array(array('status' => 'current', 'translations' => $translations1, 'counts' => array('all_count' => 2, 'current_count' => 1, 'untranslated_count' => 1, 'waiting_count' => 0)), array('status' => 'waiting', 'translations' => $translations2, 'counts' => array('all_count' => 2, 'current_count' => 1, 'untranslated_count' => 1, 'waiting_count' => 1))));
     $this->_verify_multiple_imports($originals, array(array('status' => 'waiting', 'translations' => $translations1, 'counts' => array('all_count' => 2, 'current_count' => 0, 'untranslated_count' => 2, 'waiting_count' => 1)), array('status' => 'waiting', 'translations' => $translations2, 'counts' => array('all_count' => 2, 'current_count' => 0, 'untranslated_count' => 2, 'waiting_count' => 2))));
     $this->_verify_multiple_imports($originals, array(array('status' => 'waiting', 'translations' => $translations1, 'counts' => array('all_count' => 2, 'current_count' => 0, 'untranslated_count' => 2, 'waiting_count' => 1)), array('status' => 'current', 'translations' => $translations1, 'counts' => array('all_count' => 2, 'current_count' => 1, 'untranslated_count' => 1, 'waiting_count' => 0))));
 }
开发者ID:ramiy,项目名称:GlotPress-WP,代码行数:12,代码来源:test_import.php

示例6: test_filter_translation_set_import_over_existing

 function test_filter_translation_set_import_over_existing()
 {
     $set = $this->factory->translation_set->create_with_project_and_locale();
     $original = $this->factory->original->create(array('project_id' => $set->project->id, 'status' => '+active', 'singular' => 'A string'));
     $translation = $this->factory->translation->create(array('translation_set_id' => $set->id, 'original_id' => $original->id, 'translations' => array('baba'), 'status' => 'current'));
     $translations_for_import = new Translations();
     $translations_for_import->add_entry(array('singular' => 'A string', 'translations' => array('abab')));
     add_filter('translation_set_import_over_existing', '__return_false');
     $translations_added = $set->import($translations_for_import);
     remove_filter('translation_set_import_over_existing', '__return_false');
     $this->assertEquals($translations_added, 0);
 }
开发者ID:pedro-mendonca,项目名称:GlotPress-WP,代码行数:12,代码来源:test_thing_translation_set.php

示例7: setupGlobalVars

function setupGlobalVars($type, $opts = array())
{
    global $coach, $lng, $leagues, $divisions, $tours, $settings, $rules, $admin_menu;
    switch ($type) {
        case T_SETUP_GLOBAL_VARS__COMMON:
            $coach = isset($_SESSION['logged_in']) ? new Coach($_SESSION['coach_id']) : null;
            # Create global coach object.
            list($leagues, $divisions, $tours) = Coach::allowedNodeAccess(Coach::NODE_STRUCT__FLAT, is_object($coach) ? $coach->coach_id : false, $extraFields = array(T_NODE_TOURNAMENT => array('locked' => 'locked', 'type' => 'type', 'f_did' => 'f_did'), T_NODE_DIVISION => array('f_lid' => 'f_lid'), T_NODE_LEAGUE => array('tie_teams' => 'tie_teams')));
            setupGlobalVars(T_SETUP_GLOBAL_VARS__LOAD_LEAGUE_SETTINGS);
            $_LANGUAGE = is_object($coach) && isset($coach->settings['lang']) ? $coach->settings['lang'] : $settings['lang'];
            if (!is_object($lng)) {
                $lng = new Translations($_LANGUAGE);
            } else {
                $lng->setLanguage($_LANGUAGE);
            }
            break;
        case T_SETUP_GLOBAL_VARS__POST_LOAD_MODULES:
            $admin_menu = is_object($coach) ? $coach->getAdminMenu() : array();
            break;
        case T_SETUP_GLOBAL_VARS__LOAD_LEAGUE_SETTINGS:
            // Local league settings exist?
            $file = "localsettings/settings_ID.php";
            // Update selected node $_SESSION vars if node selector form submission made (will make HTMLOUT::getSelectedNodeLid(), below, catch the correct league straight as opposed to on second page reload).
            HTMLOUT::updateNodeSelectorLeagueVars();
            // Selected
            if (isset($opts['lid']) && is_numeric($opts['lid'])) {
                $id = $opts['lid'];
            } else {
                if ($_lid = HTMLOUT::getSelectedNodeLid()) {
                    $id = $_lid;
                } else {
                    if (is_object($coach) && isset($coach->settings['home_lid'])) {
                        $id = $coach->settings['home_lid'];
                    } else {
                        $id = isset($settings['default_visitor_league']) ? $settings['default_visitor_league'] : '';
                    }
                }
            }
            $settingsFile = str_replace("ID", $id, $file);
            if ($localsettings = file_exists($settingsFile) ? $settingsFile : false) {
                include $localsettings;
            } else {
                include str_replace("ID", 'none', $file);
                # Empty settings file.
            }
            break;
        case T_SETUP_GLOBAL_VARS__POST_COACH_LOGINOUT:
            setupGlobalVars(T_SETUP_GLOBAL_VARS__COMMON);
            setupGlobalVars(T_SETUP_GLOBAL_VARS__POST_LOAD_MODULES);
            break;
    }
}
开发者ID:nicholasmr,项目名称:obblm,代码行数:52,代码来源:misc_functions.php

示例8: find

 public static function find($id, $columns = array('*'))
 {
     if (is_array($id) && empty($id)) {
         return new Collection();
     }
     $instance = new static();
     $obj = $instance->newQuery()->find($id, $columns);
     if (is_array($id)) {
         $prop = new ReflectionProperty(get_class($obj), 'items');
     }
     $col = array();
     if (isset($prop->name)) {
         $prop->setAccessible(1);
         foreach ($prop->getValue($obj) as $k => $object) {
             $translation = Translations::find($object->table . "_" . $object->id . "_" . strtolower(Config::get('cms.currlang.code')));
             $object->setRawAttributes(json_decode($translation->translation, 1));
             $col[] = $object;
         }
         $prop->setValue($obj, $col);
     } else {
         $translation = Translations::find($obj->table . "_" . $obj->id . "_" . strtolower(Config::get('cms.currlang.code')));
         $obj->setRawAttributes(json_decode($translation->translation, 1));
         $seo = $obj->seo()->first();
         if (!is_null($seo)) {
             Config::set('cms.seo', $seo);
         }
     }
     //
     return $obj;
 }
开发者ID:basdog22,项目名称:laracms,代码行数:30,代码来源:Lara.php

示例9: import

 function import($translations)
 {
     @ini_set('memory_limit', '256M');
     if (!isset($this->project) || !$this->project) {
         $this->project = GP::$project->get($this->project_id);
     }
     $locale = GP_Locales::by_slug($this->locale);
     $current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes'));
     $current_translations = new Translations();
     foreach ($current_translations_list as $entry) {
         $current_translations->add_entry($entry);
     }
     unset($current_translations_list);
     $translations_added = 0;
     foreach ($translations->entries as $entry) {
         if (empty($entry->translations)) {
             continue;
         }
         if (in_array('fuzzy', $entry->flags)) {
             continue;
         }
         $create = false;
         if ($translated = $current_translations->translate_entry($entry)) {
             // we have the same string translated
             // create a new one if they don't match
             $entry->original_id = $translated->original_id;
             $create = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations;
         } else {
             // we don't have the string translated, let's see if the original is there
             $original = GP::$original->by_project_id_and_entry($this->project->id, $entry);
             if ($original) {
                 $entry->original_id = $original->id;
                 $create = true;
             }
         }
         if ($create) {
             $entry->translation_set_id = $this->id;
             $entry->status = 'current';
             // check for errors
             $translation = GP::$translation->create($entry);
             $translation->set_as_current();
             $translations_added += 1;
         }
     }
     wp_cache_delete($this->id, 'translation_set_status_breakdown');
     return $translations_added;
 }
开发者ID:rmccue,项目名称:GlotPress,代码行数:47,代码来源:translation-set.php

示例10: setUp

 /**
  * setUp
  */
 public function setUp()
 {
     parent::setUp();
     if (!CakePlugin::loaded('Translate')) {
         CakePlugin::load('Translate');
     }
     Translations::translateModels();
     $this->TranslateController = $this->generate('Translate.Translate', array('methods' => array('redirect'), 'components' => array('Auth' => array('user'), 'Session')));
     $this->TranslateController->Auth->staticExpects($this->any())->method('user')->will($this->returnCallback(array($this, 'authUserCallback')));
     $this->TranslateController->Security->Session = $this->getMock('CakeSession');
 }
开发者ID:saydulk,项目名称:croogo,代码行数:14,代码来源:TranslateControllerTest.php

示例11: test_filter_translation_set_import_fuzzy_translations

 /**
  * @ticket 512
  */
 function test_filter_translation_set_import_fuzzy_translations()
 {
     $set = $this->factory->translation_set->create_with_project_and_locale();
     $translations_for_import = new Translations();
     // Create 3 originals and 3 fuzzy translations
     for ($i = 0; $i < 3; $i++) {
         $this->factory->original->create(array('project_id' => $set->project->id, 'status' => '+active', 'singular' => "A string #{$i}"));
         $translations_for_import->add_entry(array('singular' => "A string #{$i}", 'translations' => array("A translated string #{$i}"), 'flags' => array('fuzzy')));
     }
     // Create 3 originals and 3 non-fuzzy translations
     for ($i = 0; $i < 3; $i++) {
         $this->factory->original->create(array('project_id' => $set->project->id, 'status' => '+active', 'singular' => "A second string #{$i}"));
         $translations_for_import->add_entry(array('singular' => "A second string #{$i}", 'translations' => array("A second translated string #{$i}")));
     }
     // Import 6 translations
     add_filter('gp_translation_set_import_fuzzy_translations', '__return_false');
     $translations_added = $set->import($translations_for_import);
     remove_filter('gp_translation_set_import_fuzzy_translations', '__return_false');
     // Expect only 3 imported translations, fuzzy translations are ignored.
     $this->assertEquals($translations_added, 3);
 }
开发者ID:akirk,项目名称:GlotPress,代码行数:24,代码来源:test_thing_translation_set.php

示例12: read_originals_from_file

 public function read_originals_from_file($file_name)
 {
     $errors = libxml_use_internal_errors(true);
     $data = simplexml_load_string(file_get_contents($file_name));
     libxml_use_internal_errors($errors);
     if (!is_object($data)) {
         return false;
     }
     $entries = new Translations();
     foreach ($data->string as $string) {
         if (isset($string['translatable']) && 'false' == $string['translatable']) {
             continue;
         }
         $entry = new Translation_Entry();
         $entry->context = (string) $string['name'];
         $entry->singular = $this->unescape((string) $string[0]);
         $entry->translations = array();
         if (isset($string['comment']) && $string['comment']) {
             $entry->extracted_comments = $string['comment'];
         }
         $entries->add_entry($entry);
     }
     foreach ($data->{'string-array'} as $string_array) {
         if (isset($string_array['translatable']) && 'false' == $string_array['translatable']) {
             continue;
         }
         $array_name = (string) $string_array['name'];
         $item_index = 0;
         foreach ($string_array->item as $item) {
             $entry = new Translation_Entry();
             $entry->context = $array_name . "[{$item_index}]";
             $entry->singular = $this->unescape($item[0]);
             $entry->translations = array();
             $entries->add_entry($entry);
             $item_index++;
         }
     }
     return $entries;
 }
开发者ID:Tucev,项目名称:Glot-O-Matic,代码行数:39,代码来源:format_android.php

示例13: read_originals_from_file

 public function read_originals_from_file($file_name)
 {
     $entries = new Translations();
     $file = file_get_contents($file_name);
     if (false === $file) {
         return false;
     }
     $file = mb_convert_encoding($file, 'UTF-8', 'UTF-16LE');
     $context = $comment = null;
     $lines = explode("\n", $file);
     foreach ($lines as $line) {
         if (is_null($context)) {
             if (preg_match('/^\\/\\*\\s*(.*)\\s*\\*\\/$/', $line, $matches)) {
                 $matches[1] = trim($matches[1]);
                 if ($matches[1] !== "No comment provided by engineer.") {
                     $comment = $matches[1];
                 } else {
                     $comment = null;
                 }
             } else {
                 if (preg_match('/^"(.*)" = "(.*)";$/', $line, $matches)) {
                     $entry = new Translation_Entry();
                     $entry->context = $this->unescape($matches[1]);
                     $entry->singular = $this->unescape($matches[2]);
                     if (!is_null($comment)) {
                         $entry->extracted_comments = $comment;
                         $comment = null;
                     }
                     $entry->translations = array();
                     $entries->add_entry($entry);
                 }
             }
         }
     }
     return $entries;
 }
开发者ID:chantalcoolsma,项目名称:GlotPress-WP,代码行数:36,代码来源:format_strings.php

示例14: read_originals_from_file

 public function read_originals_from_file($file_name)
 {
     $errors = libxml_use_internal_errors(true);
     $data = simplexml_load_string(file_get_contents($file_name));
     libxml_use_internal_errors($errors);
     if (!is_object($data)) {
         return false;
     }
     $entries = new Translations();
     foreach ($data->data as $string) {
         $entry = new Translation_Entry();
         if (isset($string['type']) && gp_in('System.Resources.ResXFileRef', (string) $string['type'])) {
             continue;
         }
         $entry->context = (string) $string['name'];
         $entry->singular = $this->unescape((string) $string->value);
         if (isset($string->comment) && $string->comment) {
             $entry->extracted_comments = (string) $string->comment;
         }
         $entry->translations = array();
         $entries->add_entry($entry);
     }
     return $entries;
 }
开发者ID:akirk,项目名称:GlotPress,代码行数:24,代码来源:format_resx.php

示例15: test_digit_and_merge

 function test_digit_and_merge()
 {
     $entry_digit_1 = new Translation_Entry(array('singular' => 1, 'translations' => array('1')));
     $entry_digit_2 = new Translation_Entry(array('singular' => 2, 'translations' => array('2')));
     $domain = new Translations();
     $domain->add_entry($entry_digit_1);
     $domain->add_entry($entry_digit_2);
     $dummy_translation = new Translations();
     $this->assertEquals('1', $domain->translate('1'));
     $domain->merge_with($dummy_translation);
     $this->assertEquals('1', $domain->translate('1'));
 }
开发者ID:pedro-mendonca,项目名称:GlotPress-WP,代码行数:12,代码来源:test_translations.php


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