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


PHP I18n::translator方法代码示例

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


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

示例1: testParseContextOnSomeMessages

 /**
  * Test parsing a file with message context on some msgid values.
  *
  * This behavior is not ideal, but more thorough solutions
  * would break compatibility. Perhaps this is something we can
  * reconsider in 4.x
  *
  * @return void
  */
 public function testParseContextOnSomeMessages()
 {
     $parser = new PoFileParser();
     $file = APP . 'Locale' . DS . 'en' . DS . 'context.po';
     $messages = $parser->parse($file);
     I18n::translator('default', 'en_US', function () use($messages) {
         $package = new Package('default');
         $package->setMessages($messages);
         return $package;
     });
     $this->assertTextEquals('En cours', $messages['Pending']);
     $this->assertTextEquals('En resolved', $messages['Resolved']);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:22,代码来源:PoFileParserTest.php

示例2:

 /**
  * Returns correct plural form of message identified by $singular and $plural for count $count.
  * Allows you to override the current domain for a single message lookup.
  * The context is a unique identifier for the translations string that makes it unique
  * within the same domain.
  *
  * @param string $domain Domain.
  * @param string $context Context of the text.
  * @param string $singular Singular text to translate.
  * @param string $plural Plural text.
  * @param int $count Count.
  * @param mixed $args Array with arguments or multiple arguments in function.
  * @return string|null Plural form of translated string.
  * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#__dxn
  */
 function __dxn($domain, $context, $singular, $plural, $count, $args = null)
 {
     if (!$singular) {
         return null;
     }
     $arguments = func_num_args() === 6 ? (array) $args : array_slice(func_get_args(), 5);
     return I18n::translator($domain)->translate($plural, ['_count' => $count, '_singular' => $singular, '_context' => $context] + $arguments);
 }
开发者ID:nrother,项目名称:cakephp,代码行数:23,代码来源:functions.php

示例3: testFallbackTranslatorWithFactory

 /**
  * Tests that it is possible to register a generic translators factory for a domain
  * instead of having to create them manually
  *
  * @return void
  */
 public function testFallbackTranslatorWithFactory()
 {
     I18n::translator('default', 'fr_FR', function () {
         $package = new Package('default');
         $package->setMessages(['Dog' => 'Le bark']);
         return $package;
     });
     I18n::config('custom', function ($name, $locale) {
         $this->assertEquals('custom', $name);
         $package = new Package('default');
         $package->setMessages(['Cow' => 'Le moo']);
         return $package;
     });
     $translator = I18n::translator('custom', 'fr_FR');
     $this->assertEquals('Le moo', $translator->translate('Cow'));
     $this->assertEquals('Le bark', $translator->translate('Dog'));
 }
开发者ID:KarimaLadhani,项目名称:cakephp,代码行数:23,代码来源:I18nTest.php


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