本文整理汇总了PHP中Zend\I18n\Translator\Translator::addTranslationFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::addTranslationFile方法的具体用法?PHP Translator::addTranslationFile怎么用?PHP Translator::addTranslationFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\I18n\Translator\Translator
的用法示例。
在下文中一共展示了Translator::addTranslationFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->testFilesDir = __DIR__ . '/../_files';
$this->translator = new Translator();
$this->translator->addTranslationFile('phparray', $this->testFilesDir . '/tokens.en.php', 'route', 'en');
$this->translator->addTranslationFile('phparray', $this->testFilesDir . '/tokens.de.php', 'route', 'de');
$this->fooRoute = ['type' => 'Segment', 'options' => ['route' => '/:locale'], 'child_routes' => ['index' => ['type' => 'Segment', 'options' => ['route' => '/{homepage}']]]];
}
示例2: testTranslate
public function testTranslate()
{
$loader = new TestLoader();
$loader->textDomain = new TextDomain(array('foo' => 'bar'));
$this->translator->getPluginManager()->setService('test', $loader);
$this->translator->addTranslationFile('test', null);
$this->assertEquals('bar', $this->translator->translate('foo'));
}
示例3: getTranslator
/**
* Get translator object.
*
* @return \Zend\I18n\Translator\Translator
*/
public function getTranslator()
{
if (null === $this->translator) {
$this->translator = clone $this->getServiceLocator()->get('Translator');
$this->translator->addTranslationFile('ExtendedIni', APPLICATION_PATH . '/languages/native.ini', 'default', 'native');
$this->translator->setLocale('native');
}
return $this->translator;
}
示例4: testTranslatePlurals
public function testTranslatePlurals()
{
$this->translator->setLocale('en_EN');
$this->translator->addTranslationFile('phparray', $this->testFilesDir . '/translation_en.php', 'default', 'en_EN');
$pl0 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 1);
$pl1 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 2);
$pl2 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 10);
$this->assertEquals('Message 5 (en) Plural 0', $pl0);
$this->assertEquals('Message 5 (en) Plural 1', $pl1);
$this->assertEquals('Message 5 (en) Plural 2', $pl2);
}
示例5: __invoke
/**
* @param $str
* @param pt_BR $locale
* @return string
*/
public function __invoke($str, $locale = 'pt_BR', $typeTranslate = 'PhpArray', $pathFileTranslate = null)
{
$translator = new Translator();
if (!empty($pathFileTranslate)) {
$translator->addTranslationFile($typeTranslate, $pathFileTranslate, 'default', $locale);
}
return $translator->translate($str, $locale);
}
示例6: getTranslator
/**
* @return Translator
*/
public function getTranslator()
{
$translator = new Translator();
$translator->setLocale('en-US');
$enLoader = $this->getMock('Zend\\I18n\\Translator\\Loader\\FileLoaderInterface');
$deLoader = $this->getMock('Zend\\I18n\\Translator\\Loader\\FileLoaderInterface');
$domainLoader = $this->getMock('Zend\\I18n\\Translator\\Loader\\FileLoaderInterface');
$enLoader->expects($this->any())->method('load')->willReturn(new TextDomain(['fw' => 'framework']));
$deLoader->expects($this->any())->method('load')->willReturn(new TextDomain(['fw' => 'baukasten']));
$domainLoader->expects($this->any())->method('load')->willReturn(new TextDomain(['fw' => 'fw-alternative']));
$translator->getPluginManager()->setService('test-en', $enLoader);
$translator->getPluginManager()->setService('test-de', $deLoader);
$translator->getPluginManager()->setService('test-domain', $domainLoader);
$translator->addTranslationFile('test-en', null, 'default', 'en-US');
$translator->addTranslationFile('test-de', null, 'default', 'de-DE');
$translator->addTranslationFile('test-domain', null, 'alternative', 'en-US');
return $translator;
}
示例7: routeProvider
public static function routeProvider()
{
$translator = new Translator();
$translator->setLocale('en-US');
$enLoader = new TestLoader();
$deLoader = new TestLoader();
$domainLoader = new TestLoader();
$enLoader->textDomain = new TextDomain(array('fw' => 'framework'));
$deLoader->textDomain = new TextDomain(array('fw' => 'baukasten'));
$domainLoader->textDomain = new TextDomain(array('fw' => 'fw-alternative'));
$translator->getPluginManager()->setService('test-en', $enLoader);
$translator->getPluginManager()->setService('test-de', $deLoader);
$translator->getPluginManager()->setService('test-domain', $domainLoader);
$translator->addTranslationFile('test-en', null, 'default', 'en-US');
$translator->addTranslationFile('test-de', null, 'default', 'de-DE');
$translator->addTranslationFile('test-domain', null, 'alternative', 'en-US');
return array('simple-match' => array(new Segment('/:foo'), '/bar', null, array('foo' => 'bar')), 'no-match-without-leading-slash' => array(new Segment(':foo'), '/bar/', null, null), 'no-match-with-trailing-slash' => array(new Segment('/:foo'), '/bar/', null, null), 'offset-skips-beginning' => array(new Segment(':foo'), '/bar', 1, array('foo' => 'bar')), 'offset-enables-partial-matching' => array(new Segment('/:foo'), '/bar/baz', 0, array('foo' => 'bar')), 'match-overrides-default' => array(new Segment('/:foo', array(), array('foo' => 'baz')), '/bar', null, array('foo' => 'bar')), 'constraints-prevent-match' => array(new Segment('/:foo', array('foo' => '\\d+')), '/bar', null, null), 'constraints-allow-match' => array(new Segment('/:foo', array('foo' => '\\d+')), '/123', null, array('foo' => '123')), 'constraints-override-non-standard-delimiter' => array(new Segment('/:foo{-}/bar', array('foo' => '[^/]+')), '/foo-bar/bar', null, array('foo' => 'foo-bar')), 'constraints-with-parantheses-dont-break-parameter-map' => array(new Segment('/:foo/:bar', array('foo' => '(bar)')), '/bar/baz', null, array('foo' => 'bar', 'bar' => 'baz')), 'simple-match-with-optional-parameter' => array(new Segment('/[:foo]', array(), array('foo' => 'bar')), '/', null, array('foo' => 'bar')), 'optional-parameter-is-ignored' => array(new Segment('/:foo[/:bar]'), '/bar', null, array('foo' => 'bar')), 'optional-parameter-is-provided-with-default' => array(new Segment('/:foo[/:bar]', array(), array('bar' => 'baz')), '/bar', null, array('foo' => 'bar', 'bar' => 'baz')), 'optional-parameter-is-consumed' => array(new Segment('/:foo[/:bar]'), '/bar/baz', null, array('foo' => 'bar', 'bar' => 'baz')), 'optional-group-is-discared-with-missing-parameter' => array(new Segment('/:foo[/:bar/:baz]', array(), array('bar' => 'baz')), '/bar', null, array('foo' => 'bar', 'bar' => 'baz')), 'optional-group-within-optional-group-is-ignored' => array(new Segment('/:foo[/:bar[/:baz]]', array(), array('bar' => 'baz', 'baz' => 'bat')), '/bar', null, array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'bat')), 'non-standard-delimiter-before-parameter' => array(new Segment('/foo-:bar'), '/foo-baz', null, array('bar' => 'baz')), 'non-standard-delimiter-between-parameters' => array(new Segment('/:foo{-}-:bar'), '/bar-baz', null, array('foo' => 'bar', 'bar' => 'baz')), 'non-standard-delimiter-before-optional-parameter' => array(new Segment('/:foo{-/}[-:bar]/:baz'), '/bar-baz/bat', null, array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'bat')), 'non-standard-delimiter-before-ignored-optional-parameter' => array(new Segment('/:foo{-/}[-:bar]/:baz'), '/bar/bat', null, array('foo' => 'bar', 'baz' => 'bat')), 'parameter-with-dash-in-name' => array(new Segment('/:foo-bar'), '/baz', null, array('foo-bar' => 'baz')), 'url-encoded-parameters-are-decoded' => array(new Segment('/:foo'), '/foo%20bar', null, array('foo' => 'foo bar')), 'urlencode-flaws-corrected' => array(new Segment('/:foo'), "/!\$&'()*,-.:;=@_~+", null, array('foo' => "!\$&'()*,-.:;=@_~+")), 'empty-matches-are-replaced-with-defaults' => array(new Segment('/foo[/:bar]/baz-:baz', array(), array('bar' => 'bar')), '/foo/baz-baz', null, array('bar' => 'bar', 'baz' => 'baz')), 'translate-with-default-locale' => array(new Segment('/{fw}', array(), array()), '/framework', null, array(), array('translator' => $translator)), 'translate-with-specific-locale' => array(new Segment('/{fw}', array(), array()), '/baukasten', null, array(), array('translator' => $translator, 'locale' => 'de-DE')), 'translate-uses-message-id-as-fallback' => array(new Segment('/{fw}', array(), array()), '/fw', null, array(), array('translator' => $translator, 'locale' => 'fr-FR')), 'translate-with-specific-text-domain' => array(new Segment('/{fw}', array(), array()), '/fw-alternative', null, array(), array('translator' => $translator, 'text_domain' => 'alternative')));
}
示例8: testTranslatorSingleValue
public function testTranslatorSingleValue()
{
$translator = new Translator();
$translator->addTranslationFile('phparray', $this->translatorFile);
$processor = new TranslatorProcessor($translator);
$this->assertEquals('ein Hund', $processor->processValue('one dog'));
}
示例9: testCanTranslateTitle
public function testCanTranslateTitle()
{
$loader = new TestAsset\ArrayTranslator();
$loader->translations = array('Message_1' => 'Message 1 (en)');
$translator = new Translator();
$translator->getPluginManager()->setService('default', $loader);
$translator->addTranslationFile('default', null);
$this->helper->setTranslatorEnabled(true);
$this->helper->setTranslator($translator);
$this->helper->__invoke('Message_1');
$this->assertEquals('<title>Message 1 (en)</title>', $this->helper->toString());
}
示例10: testMaximumErrorMessageLength
public function testMaximumErrorMessageLength()
{
$this->assertEquals(-1, AbstractValidator::getMessageLength());
AbstractValidator::setMessageLength(10);
$this->assertEquals(10, AbstractValidator::getMessageLength());
$loader = new TestAsset\ArrayTranslator();
$loader->translations = array(Alpha::INVALID => 'This is the translated message for %value%');
$translator = new Translator\Translator();
$translator->getPluginManager()->setService('default', $loader);
$translator->addTranslationFile('default', null);
$this->validator->setTranslator($translator);
$this->assertFalse($this->validator->isValid(123));
$messages = $this->validator->getMessages();
$this->assertTrue(array_key_exists(Alpha::INVALID, $messages));
$this->assertEquals('This is...', $messages[Alpha::INVALID]);
}
示例11: addTextDomainTranslation
/**
* Adds text-domain language files
*
* @param TranslatorImpl $translator Translator Object
* @param Config $textDomains Text-domain configuration
*
* @return void
*/
protected function addTextDomainTranslation($translator, $textDomains)
{
// nothing to do if no text-domain is configured
if (!$textDomains instanceof Config) {
return;
}
$language = $translator->getLocale();
foreach ($textDomains as $textDomain) {
$langFile = $textDomain . '/' . $language . '.ini';
$translator->addTranslationFile('ExtendedIni', $langFile, $textDomain, $language);
}
}
示例12: testHostnameValidatorMessagesShouldBeTranslated
/**
* @group ZF-2861
*/
public function testHostnameValidatorMessagesShouldBeTranslated()
{
$hostnameValidator = new Hostname();
$translations = array(
'hostnameIpAddressNotAllowed' => 'hostnameIpAddressNotAllowed translation',
'hostnameUnknownTld' => 'hostnameUnknownTld translation',
'hostnameDashCharacter' => 'hostnameDashCharacter translation',
'hostnameInvalidHostnameSchema' => 'hostnameInvalidHostnameSchema translation',
'hostnameUndecipherableTld' => 'hostnameUndecipherableTld translation',
'hostnameInvalidHostname' => 'hostnameInvalidHostname translation',
'hostnameInvalidLocalName' => 'hostnameInvalidLocalName translation',
'hostnameLocalNameNotAllowed' => 'hostnameLocalNameNotAllowed translation',
);
$loader = new TestAsset\ArrayTranslator();
$loader->translations = $translations;
$translator = new Translator();
$translator->getPluginManager()->setService('test', $loader);
$translator->addTranslationFile('test', null);
$this->validator->setTranslator($translator)->setHostnameValidator($hostnameValidator);
$this->validator->isValid('_XX.!!3xx@0.239,512.777');
$messages = $hostnameValidator->getMessages();
$found = false;
foreach ($messages as $code => $message) {
if (array_key_exists($code, $translations)) {
$this->assertEquals($translations[$code], $message);
$found = true;
break;
}
}
$this->assertTrue($found);
}
示例13: testValidatorMessagesShouldBeTranslated
/**
* Test changed with ZF-6676, as IP check is only involved when IP patterns match
*
* @group ZF-2861
* @group ZF-6676
*/
public function testValidatorMessagesShouldBeTranslated()
{
$translations = array('hostnameInvalidLocalName' => 'this is the IP error message');
$loader = new TestAsset\ArrayTranslator();
$loader->translations = $translations;
$translator = new Translator();
$translator->getPluginManager()->setService('default', $loader);
$translator->addTranslationFile('default', null);
$this->validator->setTranslator($translator);
$this->validator->isValid('0.239,512.777');
$messages = $this->validator->getMessages();
$found = false;
foreach ($messages as $code => $message) {
if (array_key_exists($code, $translations)) {
$found = true;
break;
}
}
$this->assertTrue($found);
$this->assertEquals($translations[$code], $message);
}
示例14: addTranslations
/**
* Adds a translation file for a specific locale, or the default locale when none is provided.
*
* @param string $filename Name of the file to add.
* @param string|null $locale The locale to assign to, matches
* {@link http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ISO-639-1} and defaults to en (English).
* @param string $textDomain Translations may be divided into separate files / domains; this represents in
* which domain the translation should be.
*
* @api
*
* @return $this
*/
public function addTranslations($filename, $locale = self::DEFAULT_LOCALE, $textDomain = self::DEFAULT_DOMAIN)
{
parent::addTranslationFile(self::TRANSLATION_FILE_TYPE, $filename, $textDomain, $locale);
$this->messages = array();
return $this;
}
示例15: _getTranslatorWithTextDomain
/**
* Returns translator with text domain
*
* @return Translator
*/
protected function _getTranslatorWithTextDomain()
{
$loader1 = new TestAsset\ArrayTranslator();
$loader1->translations = array('Page 1' => 'TextDomain1 1', 'Page 1.1' => 'TextDomain1 1.1', 'Page 2' => 'TextDomain1 2', 'Page 2.3' => 'TextDomain1 2.3', 'Page 2.3.3' => 'TextDomain1 2.3.3', 'Page 2.3.3.1' => 'TextDomain1 2.3.3.1');
$loader2 = new TestAsset\ArrayTranslator();
$loader2->translations = array('Page 1' => 'TextDomain2 1', 'Page 1.1' => 'TextDomain2 1.1', 'Page 2' => 'TextDomain2 2', 'Page 2.3' => 'TextDomain2 2.3', 'Page 2.3.3' => 'TextDomain2 2.3.3', 'Page 2.3.3.1' => 'TextDomain2 2.3.3.1');
$translator = new Translator();
$translator->getPluginManager()->setService('default1', $loader1);
$translator->getPluginManager()->setService('default2', $loader2);
$translator->addTranslationFile('default1', null, 'ZendTest_1');
$translator->addTranslationFile('default2', null, 'ZendTest_2');
return $translator;
}