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


PHP Translator::translate方法代码示例

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


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

示例1: testDoubleReroutingForTranslations

 /**
  * @group ZF-2736
  */
 public function testDoubleReroutingForTranslations()
 {
     $translate = new Translator\Translator(array('adapter' => Translator\Translator::AN_ARRAY, 'content' => __DIR__ . '/Adapter/_files/testarray/', 'locale' => 'auto', 'scan' => Translator\Translator::LOCALE_FILENAME, 'ignore' => array('.', 'ignoreme', 'LC_TEST'), 'route' => array('ja' => 'en_US', 'en_US' => 'ja')));
     $translate2 = new Translator\Translator(array('adapter' => Translator\Translator::AN_CSV, 'content' => __DIR__ . '/Adapter/_files/translation_en.csv', 'locale' => 'en_US'));
     $translate->addTranslation($translate2);
     $langs = $translate->getList();
     $this->assertFalse(array_key_exists('de_DE', $langs));
     $this->assertTrue(array_key_exists('ja', $langs));
     $this->assertTrue(array_key_exists('en_US', $langs));
     $this->assertEquals('Message 5 (en)', $translate->translate('Message 5', 'ja'));
     $this->assertEquals('Message 5 (en)', $translate->translate('Message 5', 'ja'));
 }
开发者ID:,项目名称:,代码行数:15,代码来源:

示例2: testRoutingOnHttpHeader

    /**
     * @group ZF-10911
     */
    public function testRoutingOnHttpHeader()
    {
        $translate = new Translator\Translator(
            array(
                'adapter'   => Translator\Translator::AN_ARRAY,
                'content'   => __DIR__ . '/Adapter/_files/testarray/',
                'locale'    => 'auto',
                'scan'      => Translator\Translator::LOCALE_FILENAME,
                'ignore'    => array('.', 'ignoreme', 'LC_OTHER'),
                // needed because browser settings can not be simulated in phpunit
                'route'     => array('ja' => 'de_AT', 'de_AT' => 'de_DE', 'de_DE' => 'en_US'),
                'routeHttp' => true,
            )
        );

        $translate2 = new Translator\Translator(
            array(
                'adapter' => Translator\Translator::AN_CSV,
                'content' => __DIR__ . '/Adapter/_files/translation_en.csv',
                'locale'  => 'en_US',
            )
        );

        $translate->addTranslation($translate2);

        $langs = $translate->getList();
        $this->assertFalse(array_key_exists('de_AT', $langs));
        $this->assertTrue(array_key_exists('ja', $langs));
        $this->assertTrue(array_key_exists('en_US', $langs));
        $this->assertEquals('Message 5 (en)', $translate->translate('Message 5', 'ja'));
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:34,代码来源:TranslatorTest.php

示例3: processValue

 /**
  * Process a single value
  *
  * @param $value
  * @return mixed
  */
 public function processValue($value)
 {
     return $this->translator->translate($value, $this->locale);
 }
开发者ID:necrogami,项目名称:zf2,代码行数:10,代码来源:Translator.php

示例4: testGettingPluralsUsingOwnRule

 /**
  * Tests getting plurals from lowered locale
  */
 public function testGettingPluralsUsingOwnRule()
 {
     $lang = new Translator\Translator(Translator\Translator::AN_ARRAY, array('singular' => array('plural_0 (en)', 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), 'plural' => ''), 'en');
     $lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'en_US');
     $lang->setLocale('en_US');
     Translator\Plural::setPlural(array($this, 'customPlural'), 'en_US');
     $this->assertEquals('plural_1 (en)', $lang->translate(array('singular', 'plural', 1)));
     $this->assertEquals('plural_1 (en)', $lang->plural('singular', 'plural', 1));
     $this->assertEquals('plural_1 (en)', $lang->translate(array('singular', 'plural', 0)));
     $this->assertEquals('plural_1 (en)', $lang->plural('singular', 'plural', 0));
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:14,代码来源:TranslateTest.php


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