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


PHP Translator::addResource方法代码示例

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


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

示例1: testDefaultTranslationDomain

    public function testDefaultTranslationDomain()
    {
        $templates = array('index' => '
                {%- extends "base" %}

                {%- trans_default_domain "foo" %}

                {%- block content %}
                    {%- trans %}foo{% endtrans %}
                    {%- trans from "custom" %}foo{% endtrans %}
                    {{- "foo"|trans }}
                    {{- "foo"|trans({}, "custom") }}
                    {{- "foo"|transchoice(1) }}
                    {{- "foo"|transchoice(1, {}, "custom") }}
                {% endblock %}
            ', 'base' => '
                {%- block content "" %}
            ');
        $translator = new Translator('en', new MessageSelector());
        $translator->addLoader('array', new ArrayLoader());
        $translator->addResource('array', array('foo' => 'foo (messages)'), 'en');
        $translator->addResource('array', array('foo' => 'foo (custom)'), 'en', 'custom');
        $translator->addResource('array', array('foo' => 'foo (foo)'), 'en', 'foo');
        $template = $this->getTemplate($templates, $translator);
        $this->assertEquals('foo (foo)foo (custom)foo (foo)foo (custom)foo (foo)foo (custom)', trim($template->render(array())));
    }
开发者ID:nicodmf,项目名称:symfony,代码行数:26,代码来源:TranslationExtensionTest.php

示例2: register

 public function register(Container $app)
 {
     $app['translator'] = function ($app) {
         if (!isset($app['locale'])) {
             throw new \LogicException('You must define \'locale\' parameter or register the LocaleServiceProvider to use the TranslationServiceProvider');
         }
         $translator = new Translator($app['locale'], $app['translator.message_selector'], $app['translator.cache_dir'], $app['debug']);
         $translator->setFallbackLocales($app['locale_fallbacks']);
         $translator->addLoader('array', new ArrayLoader());
         $translator->addLoader('xliff', new XliffFileLoader());
         // Register default resources
         foreach ($app['translator.resources'] as $resource) {
             $translator->addResource($resource[0], $resource[1], $resource[2], $resource[3]);
         }
         foreach ($app['translator.domains'] as $domain => $data) {
             foreach ($data as $locale => $messages) {
                 $translator->addResource('array', $messages, $locale, $domain);
             }
         }
         return $translator;
     };
     $app['translator.listener'] = function ($app) {
         return new TranslatorListener($app['translator'], $app['request_stack']);
     };
     $app['translator.message_selector'] = function () {
         return new MessageSelector();
     };
     $app['translator.resources'] = $app->protect(function ($app) {
         return [];
     });
     $app['translator.domains'] = [];
     $app['locale_fallbacks'] = ['en'];
     $app['translator.cache_dir'] = null;
 }
开发者ID:speedwork,项目名称:provider,代码行数:34,代码来源:TranslationServiceProvider.php

示例3: execute

 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $i18nPath = dirname(dirname(dirname(dirname(dirname(__DIR__))))) . DIRECTORY_SEPARATOR . 'i18n.php';
     foreach (require $i18nPath as $lang => $messages) {
         $this->translator->addResource('array', $messages, $lang, 'output');
     }
 }
开发者ID:OverByThere,项目名称:Behat,代码行数:10,代码来源:GherkinTranslationsController.php

示例4: __construct

 public function __construct($language)
 {
     $this->translator = new Translator(null);
     $this->translator->addLoader('array', new ArrayLoader());
     $this->translator->addResource('array', array('Hello World' => 'Olá mundo'), 'pt');
     $this->translator->addResource('array', array('Hello World' => 'Hola Mundo'), 'es');
     $this->translator->setLocale($language);
 }
开发者ID:thpoiani,项目名称:flisol-2015,代码行数:8,代码来源:Dicionario.php

示例5: loadTranslator

/**
 * @param ContainerInterface $container
 * @return Translator
 */
function loadTranslator(ContainerInterface $container)
{
    $translator = new Translator('ru');
    $translator->addLoader('xlf', new XliffFileLoader());
    $translator->addResource('xlf', VENDOR_PATH . 'symfony/form/Resources/translations/validators.ru.xlf', 'ru', 'validators');
    $translator->addResource('xlf', VENDOR_PATH . 'symfony/validator/Resources/translations/validators.ru.xlf', 'ru', 'validators');
    $container->set('translator', $translator);
    return $translator;
}
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:13,代码来源:loadTranslator.php

示例6: setUp

 public function setUp()
 {
     $this->translator = new Translator("en_US");
     $this->translator->addLoader('array', new ArrayLoader());
     $this->translator->addResource('array', array('Hello %name%' => 'Ciao %name%'), 'it', 'dom');
     $loader = new \Twig_Loader_String();
     $this->twig = new \Twig_Environment($loader);
     $this->twig->addExtension(new TranslationExtension($this->translator));
     $this->twig->addExtension(new SafeTransExtension());
 }
开发者ID:arthens,项目名称:safe-translations,代码行数:10,代码来源:SafeTransTokenParserTest.php

示例7: getTranslator

 /**
  * Returns a Translator instance.
  *
  * @param string $locale
  *
  * @return Translator
  */
 public function getTranslator($locale)
 {
     $translator = new Translator($locale, new MessageSelector());
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array('sonata_template_box_media_gallery_block' => 'This is the default message'), 'en', 'SonataCoreBundle');
     $translator->addResource('array', array('sonata_template_box_media_gallery_block' => 'Ceci est le message par défaut'), 'fr', 'SonataCoreBundle');
     $translator->addResource('array', array('sonata_core_template_box_file_found_in' => 'This file can be found in'), 'en', 'SonataCoreBundle');
     $translator->addResource('array', array('sonata_core_template_box_file_found_in' => "Ce fichier peut être trouvé à l'emplacement"), 'fr', 'SonataCoreBundle');
     return $translator;
 }
开发者ID:emgiezet,项目名称:SonataCoreBundle,代码行数:17,代码来源:TemplateBoxNodeTest.php

示例8: createCollector

 private function createCollector()
 {
     $translator = new Translator('en');
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array('foo' => 'foo (en)'), 'en');
     $translator->addResource('array', array('bar' => 'bar (fr)'), 'fr');
     $translator->addResource('array', array('bar_ru' => 'bar (ru)'), 'ru');
     $collector = new DataCollectorTranslator($translator);
     return $collector;
 }
开发者ID:tolgabulca,项目名称:coremvc,代码行数:10,代码来源:DataCollectorTranslatorTest.php

示例9: setUp

 protected function setUp()
 {
     $translator = new Translator('en', new MessageSelector());
     $keywords = new SymfonyTranslationKeywords($translator);
     $parser = new Parser(new Lexer($keywords));
     $this->loader = new GherkinFileLoader($parser);
     $translator->addLoader('xliff', new XliffFileLoader());
     $translator->addResource('xliff', __DIR__ . '/../../../../i18n/en.xliff', 'gherkin');
     $translator->addResource('xliff', __DIR__ . '/../../../../i18n/ru.xliff', 'gherkin');
     $this->featuresPath = realpath(__DIR__ . '/../Fixtures/features');
 }
开发者ID:kingsj,项目名称:core,代码行数:11,代码来源:GherkinFileLoaderTest.php

示例10: build

 /**
  * Builds a translator
  * @return \Symfony\Component\Translation\TranslatorInterface
  */
 public function build()
 {
     $fixer = new VendorDirectoryFixer();
     // Set up the Translation component
     $translator = new Translator($this->locale);
     $pos = strpos($this->locale, '_');
     $file = 'validators.' . ($pos ? substr($this->locale, 0, $pos) : $this->locale) . '.xlf';
     $translator->addLoader('xlf', new XliffFileLoader());
     $translator->addResource('xlf', $fixer->getLocation('form', self::FORM_TRANSLATIONS_DIR . $file), $this->locale, self::TRANSLATION_DOMAIN);
     $translator->addResource('xlf', $fixer->getLocation('validator', self::VALIDATOR_TRANSLATIONS_DIR . $file), $this->locale, self::TRANSLATION_DOMAIN);
     return $translator;
 }
开发者ID:hostnet,项目名称:form-twig-bridge,代码行数:16,代码来源:TranslatorBuilder.php

示例11: testDomains

 /**
  * Test missing messages in different domains
  */
 public function testDomains()
 {
     $this->translator->addResource('array', ['m1' => 'Hello world', 'm2' => 'Testing message'], 'en_US', 'test');
     $this->translator->addResource('array', ['m1' => 'Ahoj světe', 'm2' => 'Testovací zpráva'], 'cs_CZ', 'test2');
     $missing = $this->validator->validate($this->translator, ['cs_CZ', 'en_US']);
     $this->assertEquals(2, count($missing['cs_CZ']));
     $this->assertContains('test.m1', $missing['cs_CZ']);
     $this->assertContains('test.m2', $missing['cs_CZ']);
     $this->assertEquals(2, count($missing['en_US']));
     $this->assertContains('test2.m1', $missing['en_US']);
     $this->assertContains('test2.m2', $missing['en_US']);
 }
开发者ID:ptacek,项目名称:TranslationValidator,代码行数:15,代码来源:ValidatorTest.php

示例12: register

 public function register(Container $app)
 {
     $app['translator'] = function ($app) {
         if (!isset($app['locale'])) {
             throw new \LogicException('You must define \'locale\' parameter or register the LocaleServiceProvider to use the TranslationServiceProvider');
         }
         $translator = new Translator($app['locale'], $app['translator.message_selector'], $app['translator.cache_dir'], $app['debug']);
         $translator->setFallbackLocales($app['locale_fallbacks']);
         $translator->addLoader('array', new ArrayLoader());
         $translator->addLoader('xliff', new XliffFileLoader());
         if (isset($app['validator'])) {
             $r = new \ReflectionClass('Symfony\\Component\\Validator\\Validation');
             $file = dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf';
             if (file_exists($file)) {
                 $translator->addResource('xliff', $file, $app['locale'], 'validators');
             }
         }
         if (isset($app['form.factory'])) {
             $r = new \ReflectionClass('Symfony\\Component\\Form\\Form');
             $file = dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf';
             if (file_exists($file)) {
                 $translator->addResource('xliff', $file, $app['locale'], 'validators');
             }
         }
         // Register default resources
         foreach ($app['translator.resources'] as $resource) {
             $translator->addResource($resource[0], $resource[1], $resource[2], $resource[3]);
         }
         foreach ($app['translator.domains'] as $domain => $data) {
             foreach ($data as $locale => $messages) {
                 $translator->addResource('array', $messages, $locale, $domain);
             }
         }
         return $translator;
     };
     if (isset($app['request_stack'])) {
         $app['translator.listener'] = function ($app) {
             return new TranslatorListener($app['translator'], $app['request_stack']);
         };
     }
     $app['translator.message_selector'] = function () {
         return new MessageSelector();
     };
     $app['translator.resources'] = $app->protect(function ($app) {
         return array();
     });
     $app['translator.domains'] = array();
     $app['locale_fallbacks'] = array('en');
     $app['translator.cache_dir'] = null;
 }
开发者ID:cordje,项目名称:Silex,代码行数:50,代码来源:TranslationServiceProvider.php

示例13: __construct

 /**
  * Block constructor.
  * @throws InvalidArgumentException
  */
 private function __construct()
 {
     self::$translator = new Translator('en', new MessageSelector());
     self::$translator->addLoader('php', new PhpFileLoader());
     foreach (glob(__DIR__ . '/../../locales/messages.*.php') as $file) {
         if (preg_match('/\\.([\\w-]+)\\.php$/', basename($file), $fileLocaleMatch)) {
             /** @noinspection ExceptionsAnnotatingAndHandlingInspection */
             self::$translator->addResource('php', $file, $fileLocaleMatch[1]);
         }
     }
     self::configureLocale();
     // Reconfigure locale if it was changed.
     EventListener::$global->on('rentalhost.validation::option.set.locale', [self::class, 'configureLocale']);
 }
开发者ID:VanillaPackage,项目名称:vanilla-validation,代码行数:18,代码来源:ValidationLocalize.php

示例14: setUp

 protected function setUp(array $install = array(), $language = 'en')
 {
     $translation = new Translator('en_EN', new MessageSelector());
     $translation->setFallbackLocales(array('en'));
     $translation->addLoader('yaml', new YamlFileLoader());
     $translation->addResource('yaml', __DIR__ . '/../../../../../locales/en.yml', 'en');
     $translation->addResource('yaml', __DIR__ . '/../../../../../locales/de.yml', 'de');
     $command = new InstallCommand();
     $command->setInstalls($install)->setTranslator($translation);
     $console = new Application();
     $console->add($command);
     $command = $console->find('api:install');
     $this->command = new CommandTester($command);
     $this->command->execute(array('command' => $command->getName(), 'language' => $language));
 }
开发者ID:dimug,项目名称:api,代码行数:15,代码来源:InstallCommandTest.php

示例15: setUp

 protected function setUp($dir = '', array $options = array())
 {
     $translation = new Translator('en_EN', new MessageSelector());
     $translation->setFallbackLocales(array('en'));
     $translation->addLoader('yaml', new YamlFileLoader());
     $translation->addResource('yaml', __DIR__ . '/../../../../../locales/en.yml', 'en');
     $translation->addResource('yaml', __DIR__ . '/../../../../../locales/de.yml', 'de');
     $command = new ValidateCommand();
     $command->setConfigDir($dir)->setTranslator($translation);
     $console = new Application();
     $console->add($command);
     $command = $console->find('api:validate');
     $this->command = new CommandTester($command);
     $this->command->execute(array_merge(array('command' => $command->getName()), $options));
 }
开发者ID:dimug,项目名称:api,代码行数:15,代码来源:ValidateCommandTest.php


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