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


PHP I18n::translate方法代码示例

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


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

示例1: testTranslationCaching

 function testTranslationCaching()
 {
     Configure::write('Config.language', 'cache_test_po');
     $i18n =& i18n::getInstance();
     // reset internally stored entries
     I18n::clear();
     Cache::clear(false, '_cake_core_');
     $lang = Configure::read('Config.language');
     #$i18n->l10n->locale;
     Cache::config('_cake_core_', Cache::config('default'));
     // make some calls to translate using different domains
     $this->assertEqual(I18n::translate('dom1.foo', false, 'dom1'), 'Dom 1 Foo');
     $this->assertEqual(I18n::translate('dom1.bar', false, 'dom1'), 'Dom 1 Bar');
     $this->assertEqual($i18n->__domains['dom1']['cache_test_po']['LC_MESSAGES']['dom1.foo'], 'Dom 1 Foo');
     // reset internally stored entries
     I18n::clear();
     // now only dom1 should be in cache
     $cachedDom1 = Cache::read('dom1_' . $lang, '_cake_core_');
     $this->assertEqual($cachedDom1['LC_MESSAGES']['dom1.foo'], 'Dom 1 Foo');
     $this->assertEqual($cachedDom1['LC_MESSAGES']['dom1.bar'], 'Dom 1 Bar');
     // dom2 not in cache
     $this->assertFalse(Cache::read('dom2_' . $lang, '_cake_core_'));
     // translate a item of dom2 (adds dom2 to cache)
     $this->assertEqual(I18n::translate('dom2.foo', false, 'dom2'), 'Dom 2 Foo');
     // verify dom2 was cached through manual read from cache
     $cachedDom2 = Cache::read('dom2_' . $lang, '_cake_core_');
     $this->assertEqual($cachedDom2['LC_MESSAGES']['dom2.foo'], 'Dom 2 Foo');
     $this->assertEqual($cachedDom2['LC_MESSAGES']['dom2.bar'], 'Dom 2 Bar');
     // modify cache entry manually to verify that dom1 entries now will be read from cache
     $cachedDom1['LC_MESSAGES']['dom1.foo'] = 'FOO';
     Cache::write('dom1_' . $lang, $cachedDom1, '_cake_core_');
     $this->assertEqual(I18n::translate('dom1.foo', false, 'dom1'), 'FOO');
 }
开发者ID:kevinmel2000,项目名称:Study-Buddy---CakePHP-Quiz-System,代码行数:33,代码来源:i18n.test.php

示例2: testPlural

 function testPlural()
 {
     $result = I18n::translate('chair', 'chairs', null, 5, 1, $this->dir);
     $this->assertEqual($result, 'chair');
     $result = I18n::translate('chair', 'chairs', null, 5, 2, $this->dir);
     $this->assertEqual($result, 'chairs');
     $data['count'] = 1;
     $result = I18n::translate('chair', 'chairs', null, 5, $data['count'], $this->dir);
     $this->assertEqual($result, 'chair');
     $data['count'] = 8;
     $result = I18n::translate('chair', 'chairs', null, 5, $data['count'], $this->dir);
     $this->assertEqual($result, 'chairs');
 }
开发者ID:kaz0636,项目名称:openflp,代码行数:13,代码来源:i18n.test.php

示例3: run

 public function run()
 {
     DB::table('navigations')->delete();
     $title1 = new I18n();
     $title1->i18n_type_id = I18nType::where('name', '=', 'title')->first()->id;
     $title1->save();
     $title1->translate('fr', 'Accueil');
     $title1->translate('en', 'Home');
     $title7 = new I18n();
     $title7->i18n_type_id = I18nType::where('name', '=', 'title')->first()->id;
     $title7->save();
     $title7->translate('fr', 'Contact');
     $title7->translate('en', 'Contact');
     DB::table('navigations')->insert(array(array('i18n_title' => $title1->id, 'parent_id' => 0, 'order' => 1, 'navigable_id' => 1, 'navigable_type' => 'Page'), array('i18n_title' => $title7->id, 'parent_id' => 0, 'order' => 2, 'navigable_id' => 2, 'navigable_type' => 'Page')));
     //Admin navigation group
     DB::table('admin_navigation_groups')->delete();
     $adminNav1 = I18n::add(array('fr' => 'Racine', 'en' => 'Root'), 'key', 'admin.admin_navigation_root');
     $adminNav2 = I18n::add(array('fr' => 'Gestion des contenus', 'en' => 'Content managment'), 'key', 'admin.admin_navigation_content');
     $adminNav3 = I18n::add(array('fr' => 'Gestion des utilisateurs', 'en' => 'User managment'), 'key', 'admin.admin_navigation_user');
     $adminNav4 = I18n::add(array('fr' => 'Traduction', 'en' => 'Translation'), 'key', 'admin.admin_navigation_translation');
     $adminNav5 = I18n::add(array('fr' => 'Option', 'en' => 'Option'), 'key', 'admin.admin_navigation_option');
     DB::table('admin_navigation_groups')->insert(array(array('i18n_title' => $adminNav1, 'parent_id' => 0, 'order' => 0, 'deletable' => false), array('i18n_title' => $adminNav2, 'parent_id' => 0, 'order' => 1, 'deletable' => true), array('i18n_title' => $adminNav3, 'parent_id' => 0, 'order' => 2, 'deletable' => true), array('i18n_title' => $adminNav4, 'parent_id' => 0, 'order' => 3, 'deletable' => true), array('i18n_title' => $adminNav5, 'parent_id' => 0, 'order' => 4, 'deletable' => true)));
 }
开发者ID:Metrakit,项目名称:dynamix,代码行数:23,代码来源:NavigationsTableSeeder.php

示例4: validate

 public function validate($rules = null)
 {
     $validator = new Validator();
     foreach ($this->rules as $rule) {
         $fields = explode(',', str_replace(' ', '', $rule[0]));
         foreach ($fields as $field) {
             count($rule) == 4 ? $validator->add($field, $rule[1], $rule[2], \I18n::translate($rule[3]), $this->label($field)) : $validator->add($field, $rule[1], [], \I18n::translate($rule[2]), $this->label($field));
         }
     }
     if (!$validator->validate($this->getAttributes())) {
         $messages = $validator->getMessages();
         foreach ($messages as $message) {
             foreach ($message as $error) {
                 $this->errors[] = (string) $error;
             }
         }
         return false;
     }
     return true;
 }
开发者ID:titaphp,项目名称:test-app,代码行数:20,代码来源:BaseModel.php

示例5: sort

 public function sort($title, $key = null, $options = array())
 {
     if (empty($key)) {
         $key = $this->Paginator->defaultModel() . '.' . $title;
         $title = preg_replace('/_id$/', '', $title);
         if (!class_exists('I18n')) {
             App::import('Core', 'i18n');
         }
         $title = I18n::translate(Inflector::humanize($title));
     }
     if (false === strpos($key, '.')) {
         $key = $this->Paginator->defaultModel() . '.' . $key;
     }
     $sortKey = $this->Paginator->sortKey();
     $sortDir = $this->Paginator->sortDir();
     if ($key === $sortKey) {
         $title .= $sortDir === 'asc' ? '<span class="asc">↑</span>' : '<span class="desc">↓</span>';
         $options = am($options, array('escape' => false));
     }
     return $this->Paginator->sort($title, $key, $options);
 }
开发者ID:slywalker,项目名称:vendors,代码行数:21,代码来源:app_paginator.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array();
     $tag_name_datas = array();
     foreach (Input::except('_token') as $k => $v) {
         if (strpos($k, 'tag_name_') !== false) {
             $rules[$k] = Config::get('validator.admin.tag.name');
             $tag_name_datas[mb_substr($k, strlen('tag_name_'), strlen($k) - strpos($k, 'tag_name_'))] = $v;
         }
     }
     //return var_dump($tag_name_datas);
     // Validate the inputs
     $validator = Validator::make(Input::except('_token'), $rules);
     if ($validator->passes()) {
         //create i18n key
         $i18n_name = new I18n();
         $i18n_name->i18n_type_id = I18nType::where('name', '=', 'tag')->first()->id;
         $i18n_name->save();
         foreach ($tag_name_datas as $locale => $value) {
             if (!$i18n_name->translate($locale, $value)) {
                 return Redirect::to('admin/tag')->with('error', Lang::get('admin.tag_save_fail'));
             }
         }
         $tag = new Tag();
         $tag->i18n_name = $i18n_name->id;
         // Was the blog post created?
         if ($tag->save()) {
             //track user
             parent::track('create', 'Tag', $tag->id);
             return Redirect::to('admin/tag')->with('success', Lang::get('admin.tag_save_success'));
         }
         // Redirect to the blog post create tag
         return Redirect::to('admin/tag/create')->with('error', Lang::get('admin.tag_save_fail'));
     }
     // Form validation failed
     return Redirect::to('admin/tag/create')->withInput()->withErrors($validator);
 }
开发者ID:Metrakit,项目名称:dynamix,代码行数:42,代码来源:AdminTagController.php

示例7:

<?php

include '../../lib/sfYaml/sfYaml.php';
include '../I18n.php';
echo "Testing English...\n\n";
$i18n = new I18n('../../translations', 'en');
echo "login.username: " . $i18n->translate('login.username') . "\n";
echo "dashboard.top_proofers: " . $i18n->translate('dashboard.top_proofers') . "\n";
echo "footer.text: " . $i18n->translate('footer.text') . "\n";
echo "\nTesting faux Spanish...\n\n";
$i18n = new I18n('../../translations', 'es');
echo "login.username: " . $i18n->translate('login.username') . "\n";
echo "dashboard.top_proofers: " . $i18n->translate('dashboard.top_proofers') . "\n";
echo "footer.text: " . $i18n->translate('footer.text') . "\n";
echo "\nTesting a key that doesn't exist...\n\n";
echo "supercalifragilisticexpialidocious: " . $i18n->translate('supercalifragilisticexpialidocious') . "\n";
开发者ID:hmmbug,项目名称:unbindery,代码行数:16,代码来源:i18n-test.php

示例8: _replaceTranslate

 /**
  * Replace translatable strings by their translated values.
  *
  * Examples:
  *  - [__]Translate this[/__]
  *  - [__d|domain]Translate this[/__d]
  *  - [__c|category]Translate this[/__c]
  *
  * @param string $str String to check and modify.
  * @return string Modified string.
  */
 protected function _replaceTranslate($str)
 {
     // [__]Text to translate[/__]
     if (preg_match_all('/\\[__\\](.*?)\\[\\/__\\]/i', $str, $matches)) {
         foreach ($matches[0] as $i => $find) {
             $str = str_replace($find, I18n::translate($matches[1][$i]), $str);
         }
     }
     // [__d|domain]Text to translate[/__d]
     if (preg_match_all('/\\[__d\\|(.+?)\\](.*?)\\[\\/__d\\]/i', $str, $matches)) {
         foreach ($matches[0] as $i => $find) {
             $str = str_replace($find, I18n::translate($matches[2][$i], null, $matches[1][$i]), $str);
         }
     }
     // [__c|category]Text to translate[/__c]
     if (preg_match_all('/\\[__c\\|(.+?)\\](.*?)\\[\\/__c\\]/i', $str, $matches)) {
         foreach ($matches[0] as $i => $find) {
             $str = str_replace($find, I18n::translate($matches[2][$i], null, null, $matches[1][$i]), $str);
         }
     }
     return $str;
 }
开发者ID:gourmet,项目名称:common,代码行数:33,代码来源:TableHelper.php

示例9: __xc

 /**
  * The category argument allows a specific category of the locale settings to be used for fetching a message.
  * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
  *
  * Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
  *
  * - LC_ALL       I18n::LC_ALL
  * - LC_COLLATE   I18n::LC_COLLATE
  * - LC_CTYPE     I18n::LC_CTYPE
  * - LC_MONETARY  I18n::LC_MONETARY
  * - LC_NUMERIC   I18n::LC_NUMERIC
  * - LC_TIME      I18n::LC_TIME
  * - LC_MESSAGES  I18n::LC_MESSAGES
  *
  * @param string $context  Context of the text
  * @param string $msg      String to translate
  * @param int    $category Category
  * @param mixed  $args     Array with arguments or multiple arguments in function, otherwise null.
  *
  * @return string translated string
  * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
  */
 function __xc($context, $msg, $category, $args = NULL)
 {
     if (!$msg) {
         return NULL;
     }
     App::uses('I18n', 'I18n');
     $translated = I18n::translate($msg, NULL, NULL, $category, NULL, NULL, $context);
     $arguments = func_get_args();
     return I18n::insertArgs($translated, array_slice($arguments, 3));
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:32,代码来源:basics.php

示例10: __t

function __t($_query = false, $_ordering = array('en', 'es', 'pt'))
{
    if (file_exists(__CONTROLLERS_DIR__ . 'I18n.php')) {
        require_once __CONTROLLERS_DIR__ . 'I18n.php';
        $_translator = new I18n($_ordering);
        if ($_query == false) {
            return 'Please insert a query';
        }
        return $_translator->translate($_query);
    } else {
        return 'ERROR - Class I18n not found';
    }
}
开发者ID:chroda,项目名称:lolcollector,代码行数:13,代码来源:functions.php

示例11: title

 /**
  * @return string
  */
 public function title()
 {
     return I18n::translate('common/script/' . strtolower($this->m_name));
 }
开发者ID:evalcodenet,项目名称:net.evalcode.components.i18n,代码行数:7,代码来源:script.php

示例12: printErrors

 function printErrors($includeSubPanels_ = true, $expandThreshold_ = 4)
 {
     $errors = $this->errors($includeSubPanels_);
     if (1 > ($count = $this->countErrors($includeSubPanels_))) {
         return;
     }
     // TODO Localize ...
     printf('
     <div class="ui_panel_errors">
       <div class="ui_panel_disclosure_header">
         <h2 class="title">%2$s (%3$s)</h2>
         <a href="javascript:void(0);" rel="%1$s-errors" class="ui_panel_disclosure_toggle%4$s">collapse</a>
       </div>', $this->id(), \html\escape(I18n::translate('ui/panel/errors/title')), $count, $count > $expandThreshold_ ? '' : ' expanded');
     printf('<ul id="%1$s-errors" class="ui_panel_errors">', $this->id());
     foreach ($errors as $panelId => $value) {
         if ($includeSubPanels_) {
             if (!($title = $value['panel']->title)) {
                 $title = $value['panel']->name;
             }
             printf('<li class="ui_panel_error_category"><label for="%1$s">%2$s</label><ul>', $value['panel']->id(), \html\escape($title));
         }
         foreach ($value['errors'] as $error) {
             printf('<li class="ui_panel_error"><label for="%1$s">%2$s</label></li>', $value['panel']->id(), \html\escape($error['message']));
         }
         if ($includeSubPanels_) {
             echo '</ul></li>';
         }
     }
     echo '</ul></div>';
 }
开发者ID:evalcodenet,项目名称:net.evalcode.components.ui,代码行数:30,代码来源:panel.php

示例13: time

<?php

Template::includeTemplate('Default', 'Head.php');
echo '<br>' . I18n::translate('no.layout.test', $var->culture) . '<br>';
echo time();
var_dump($var->var1);
var_dump($var->var2);
var_dump($var->var3);
var_dump($var->var4);
var_dump($var->var5, $var->var6);
var_dump($var->var7);
var_dump($var->var8);
var_dump($var->var9);
var_dump($var->var10);
开发者ID:suga,项目名称:Megiddo,代码行数:14,代码来源:index.php

示例14: __c

/**
 * The category argument allows a specific category of the locale settings to be used for fetching a message.
 * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
 *
 * Note that the category must be specified with a numeric value, instead of the constant name.  The values are:
 * LC_CTYPE     0
 * LC_NUMERIC   1
 * LC_TIME      2
 * LC_COLLATE   3
 * LC_MONETARY  4
 * LC_MESSAGES  5
 * LC_ALL       6
 *
 * @param string $msg String to translate
 * @param integer $category Category
 * @param string $return true to return, false to echo
 * @return translated string if $return is false string will be echoed
 */
function __c($msg, $category, $return = false)
{
    if (!class_exists('I18n')) {
        uses('i18n');
    }
    $calledFrom = debug_backtrace();
    $dir = dirname($calledFrom[0]['file']);
    unset($calledFrom);
    if ($return === false) {
        echo I18n::translate($msg, null, null, $category, null, $dir);
    } else {
        return I18n::translate($msg, null, null, $category, null, $dir);
    }
}
开发者ID:rhencke,项目名称:mozilla-cvs-history,代码行数:32,代码来源:basics.php

示例15: testTranslateEmptyDomain

 /**
  * Test that the '' domain causes exceptions.
  *
  * @expectedException CakeException
  * @return void
  */
 public function testTranslateEmptyDomain()
 {
     I18n::translate('Plural Rule 1', null, '');
 }
开发者ID:kuradakis,项目名称:cakephp-ex,代码行数:10,代码来源:I18nTest.php


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