當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Translator\Translator類代碼示例

本文整理匯總了PHP中Zend\Translator\Translator的典型用法代碼示例。如果您正苦於以下問題:PHP Translator類的具體用法?PHP Translator怎麽用?PHP Translator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Translator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 /**
  * Setup test
  *
  * @return void
  */
 public function setUp()
 {
     // Backup server array
     $this->_server = $_SERVER;
     // Clean host env
     unset($_SERVER['HTTP_HOST'], $_SERVER['HTTPS'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
     // Set translator
     $translator = new Translator\Translator('arrayAdapter', array('foo' => 'en_foo', 'bar' => 'en_bar'), 'en');
     $translator->addTranslation(array('foo' => 'de_foo', 'bar' => 'de_bar'), 'de');
     $translator->setLocale('en');
     \Zend\Registry::set('Zend_Translate', $translator);
 }
開發者ID:bradley-holt,項目名稱:zf2,代碼行數:17,代碼來源:RouteTest.php

示例2: setDefaultTranslator

 /**
  * Set global default translator object
  *
  * @param  Translator\Translator|Translator\Adapter|null $translator
  * @return void
  */
 public static function setDefaultTranslator($translator = null)
 {
     if (null === $translator) {
         self::$_translatorDefault = null;
     } elseif ($translator instanceof Translator\Adapter\AbstractAdapter) {
         self::$_translatorDefault = $translator;
     } elseif ($translator instanceof Translator\Translator) {
         self::$_translatorDefault = $translator->getAdapter();
     } else {
         throw new Exception\InvalidArgumentException('Invalid translator specified');
     }
 }
開發者ID:rikaix,項目名稱:zf2,代碼行數:18,代碼來源:Form.php

示例3: testErrorMessagesFromProcessAjaxAreLocalizedWhenTranslateAdapterPresent

 public function testErrorMessagesFromProcessAjaxAreLocalizedWhenTranslateAdapterPresent()
 {
     $translations = (include __DIR__ . '/TestAsset/locale/array.php');
     $translate = new Translator('ArrayAdapter', $translations, 'en');
     $translate->setLocale('en');
     $this->form->addElements(array('foo' => array('type' => 'text', 'options' => array('required' => true, 'validators' => array('NotEmpty'))), 'bar' => array('type' => 'text', 'options' => array('required' => true, 'validators' => array('Digits')))))->setTranslator($translate);
     $data = array('foo' => '');
     $return = $this->form->processAjax($data);
     $messages = Json::decode($return, Json::TYPE_ARRAY);
     $this->assertTrue(is_array($messages));
     $this->assertTrue(isset($messages['foo']));
     $this->assertFalse(isset($messages['bar']));
     foreach ($messages['foo'] as $key => $message) {
         if (array_key_exists($key, $translations)) {
             $this->assertEquals($translations[$key], $message);
         } else {
             $this->fail('Translation for ' . $key . ' does not exist?');
         }
     }
 }
開發者ID:rafalwrzeszcz,項目名稱:zf2,代碼行數:20,代碼來源:FormTest.php

示例4: testRetrievingLabelRetrievesLabelWithTranslationAndPrefixAndSuffix

    public function testRetrievingLabelRetrievesLabelWithTranslationAndPrefixAndSuffix()
    {
        $translate = new Translator('ArrayAdapter', array('My Label' => 'Translation'), 'en');
        $translate->setLocale('en');

        $element = new Element('foo');
        $element->setView($this->getView())
                ->setLabel('My Label')
                ->setTranslator($translate);
        $this->decorator->setElement($element)
                        ->setOptions(array(
                            'optionalPrefix' => '> ',
                            'optionalSuffix' => ':',
                            'requiredPrefix' => '! ',
                            'requiredSuffix' => '*:',
                        ));
        $label = $this->decorator->getLabel();
        $this->assertEquals('> Translation:', $label);

        $element->setRequired(true);
        $label = $this->decorator->getLabel();
        $this->assertEquals('! Translation*:', $label);
    }
開發者ID:niallmccrudden,項目名稱:zf2,代碼行數:23,代碼來源:LabelTest.php

示例5: setTranslator

 /**
  * Sets a translation Adapter for translation
  *
  * @param  \Zend\Translator\Translator|\Zend\Translator\Translator_Adapter $translate Instance of \Zend\Translator\Translator
  * @throws \Zend\View\Exception When no or a false instance was set
  * @return \Zend\View\Helper\Translate
  */
 public function setTranslator($translate)
 {
     if ($translate instanceof \Zend\Translator\Adapter\Adapter) {
         $this->_translator = $translate;
     } else {
         if ($translate instanceof \Zend\Translator\Translator) {
             $this->_translator = $translate->getAdapter();
         } else {
             $e = new View\Exception('You must set an instance of Zend_Translate or Zend_Translate_Adapter');
             $e->setView($this->view);
             throw $e;
         }
     }
     return $this;
 }
開發者ID:navtis,項目名稱:xerxes-pazpar2,代碼行數:22,代碼來源:Translate.php

示例6: testSetCacheThroughOptions

 /**
  * ZF-9877
  */
 public function testSetCacheThroughOptions()
 {
     $cache = Cache\Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . '/../_files/'));
     $translate = new Translator\Translator(array('adapter' => Translator\Translator::AN_ARRAY, 'content' => array('msg1' => 'Message 1 (en)'), 'locale' => 'en', 'cache' => $cache));
     $return = Translator\Translator::getCache();
     $this->assertTrue($return instanceof Cache\Frontend);
     $this->assertTrue(Translator\Translator::hasCache());
 }
開發者ID:,項目名稱:,代碼行數:11,代碼來源:

示例7: testTranslatedMessagesCanContainVariableSubstitution

 /** ZF-2568 */
 public function testTranslatedMessagesCanContainVariableSubstitution()
 {
     $localeFile = __DIR__ . '/TestAsset/locale/array.php';
     $translations = (include $localeFile);
     $translations['notDigits'] .= ' "%value%"';
     $translator = new Translator('ArrayAdapter', $translations, 'en');
     $translator->setLocale('en');
     $this->element->setAllowEmpty(false)->setTranslator($translator)->addValidator('digits');
     $this->element->isValid('abc');
     $messages = $this->element->getMessages();
     $found = false;
     foreach ($messages as $key => $message) {
         if ($key == 'notDigits') {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'String Empty message not found: ' . var_export($messages, 1));
     $this->assertContains(' "abc"', $message);
     $this->assertContains('Translating the notDigits string', $message);
 }
開發者ID:bradley-holt,項目名稱:zf2,代碼行數:22,代碼來源:ElementTest.php

示例8: testMultiOptionsPassedToViewHelperAreTranslated

 public function testMultiOptionsPassedToViewHelperAreTranslated()
 {
     $element = new SelectElement('foo');
     $options = array('foo' => 'This Foo Will Not Be Displayed', 'bar' => 'This Bar Will Not Be Displayed', 'baz' => 'This Baz Will Not Be Displayed');
     $element->setMultiOptions($options);
     $translations = array('This Foo Will Not Be Displayed' => 'This is the Foo Value', 'This Bar Will Not Be Displayed' => 'This is the Bar Value', 'This Baz Will Not Be Displayed' => 'This is the Baz Value');
     $translate = new Translator('ArrayAdapter', $translations, 'en');
     $translate->setLocale('en');
     $element->setTranslator($translate);
     $test = $element->render($this->getView());
     foreach ($options as $key => $value) {
         $this->assertNotContains($value, $test);
         $this->assertContains($translations[$value], $test);
     }
 }
開發者ID:alab1001101,項目名稱:zf2,代碼行數:15,代碼來源:ViewHelperTest.php

示例9: setTranslator

 /**
  * Sets a translation Adapter for translation
  *
  * @param  Translation|TranslationAdapter $translator
  * @return Translator
  * @throws Exception\InvalidArgumentException When no or a false instance was set
  */
 public function setTranslator($translator)
 {
     if ($translator instanceof TranslationAdapter) {
         $this->translator = $translate;
     } else {
         if ($translator instanceof Translation) {
             $this->translator = $translator->getAdapter();
         } else {
             throw new Exception\InvalidArgumentException('You must set an instance of Zend\\Translator\\Translator or Zend\\Translator\\Adapter');
         }
     }
     return $this;
 }
開發者ID:nevvermind,項目名稱:zf2,代碼行數:20,代碼來源:Translator.php

示例10: setTranslator

 /**
  * Set translator object for localization
  *
  * @param  \Zend\Translator\Translator|null $translator
  * @return Zend_File_Transfer_Abstract
  */
 public function setTranslator($translator = null)
 {
     if (null === $translator) {
         $this->_translator = null;
     } elseif ($translator instanceof \Zend\Translator\Adapter\Adapter) {
         $this->_translator = $translator;
     } elseif ($translator instanceof \Zend\Translator\Translator) {
         $this->_translator = $translator->getAdapter();
     } else {
         throw new Transfer\Exception('Invalid translator specified');
     }
     return $this;
 }
開發者ID:heiglandreas,項目名稱:zf2,代碼行數:19,代碼來源:AbstractAdapter.php

示例11: testSetCacheFromCacheManager

 /**
  * @group ZF-10034
  */
 public function testSetCacheFromCacheManager()
 {
     $configCache = array('translate' => array('frontend' => array('name' => 'Core', 'options' => array('lifetime' => 120, 'automatic_serialization' => true)), 'backend' => array('name' => 'Black Hole')));
     $this->bootstrap->registerPluginResource('cachemanager', $configCache);
     $options = $this->_translationOptions;
     $options['cache'] = 'translate';
     $resource = new TranslateResource($options);
     $resource->setBootstrap($this->bootstrap);
     $resource->init();
     $this->assertType('Zend\\Cache\\Frontend\\Core', Translator::getCache());
     Translator::clearCache();
 }
開發者ID:rexmac,項目名稱:zf2,代碼行數:15,代碼來源:TranslateTest.php

示例12: 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'), '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:RomanShumkov,項目名稱:zf2,代碼行數:14,代碼來源:TranslatorTest.php

示例13: testOptGroupTranslationsShouldWorkAfterPopulatingElement

 /**
  * @group ZF-5568
  */
 public function testOptGroupTranslationsShouldWorkAfterPopulatingElement()
 {
     $translations = array('ThisIsTheLabel' => 'Optgroup label', 'ThisShouldNotShow' => 'Foo Value', 'ThisShouldNeverShow' => 'Bar Value');
     $translate = new Translator('ArrayAdapter', $translations, 'en');
     $translate->setLocale('en');
     $options = array('ThisIsTheLabel' => array('foovalue' => 'ThisShouldNotShow', 'barvalue' => 'ThisShouldNeverShow'));
     $this->element->setTranslator($translate)->addMultiOptions($options);
     $this->element->setValue('barValue');
     $html = $this->element->render($this->getView());
     $this->assertContains($translations['ThisIsTheLabel'], $html, $html);
 }
開發者ID:rexmac,項目名稱:zf2,代碼行數:14,代碼來源:MultiselectTest.php

示例14: testTranslationWithPercent

 /**
  * ZF-6724
  */
 public function testTranslationWithPercent()
 {
     $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', "two %1\$s" => "zwei %1\$s", "three %1\$s %2\$s" => "drei %1\$s %2\$s", 'vier%ig' => 'four%'), 'de');
     $trans->setLocale('de');
     $this->helper->setTranslator($trans);
     $this->assertEquals("four%", $this->helper->direct("vier%ig"));
     $this->assertEquals("zwei 100", $this->helper->direct("two %1\$s", "100"));
 }
開發者ID:,項目名稱:,代碼行數:11,代碼來源:

示例15: setTranslator

 /**
  * Set translator object
  *
  * @param  Translator\Translator|Translator\Adapter|null $translator
  * @return DisplayGroup
  */
 public function setTranslator($translator = null)
 {
     if (null === $translator || $translator instanceof Translator\Adapter\AbstractAdapter) {
         $this->_translator = $translator;
     } elseif ($translator instanceof Translator\Translator) {
         $this->_translator = $translator->getAdapter();
     } else {
         throw new Exception\InvalidArgumentException('Invalid translator specified');
     }
     return $this;
 }
開發者ID:bradley-holt,項目名稱:zf2,代碼行數:17,代碼來源:DisplayGroup.php


注:本文中的Zend\Translator\Translator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。