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


PHP Translator::setFallbackLocale方法代码示例

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


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

示例1: register

 public function register(Application $app, array $options = array())
 {
     $translator = new Translator('en', new MessageSelector());
     $translator->setFallbackLocale('en');
     $translator->addLoader('array', new ArrayLoader());
     $translator->addLoader('xliff', new XliffFileLoader());
     return $translator;
 }
开发者ID:ubick,项目名称:glue,代码行数:8,代码来源:TranslationProvider.php

示例2: testTransWithFallbackLocale

 public function testTransWithFallbackLocale()
 {
     $translator = new Translator('fr_FR', new MessageSelector());
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array('foo' => 'foofoo'), 'en_US');
     $translator->addResource('array', array('bar' => 'foobar'), 'en');
     $translator->setFallbackLocale('en');
     $this->assertEquals('foobar', $translator->trans('bar'));
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:9,代码来源:TranslatorTest.php

示例3: testAddResourceAfterTrans

 public function testAddResourceAfterTrans()
 {
     $translator = new Translator('fr');
     $translator->addLoader('array', new ArrayLoader());
     $translator->setFallbackLocale(array('en'));
     $translator->addResource('array', array('foo' => 'foofoo'), 'en');
     $this->assertEquals('foofoo', $translator->trans('foo'));
     $translator->addResource('array', array('bar' => 'foobar'), 'en');
     $this->assertEquals('foobar', $translator->trans('bar'));
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:10,代码来源:TranslatorTest.php

示例4: createSymfonyTranslator

 /**
  * Create a new Symfony translator instance.
  *
  * @param  string  $default
  * @param  string  $fallback
  * @return Symfony\Component\Translation\Translator
  */
 protected function createSymfonyTranslator($default, $fallback)
 {
     $trans = new SymfonyTranslator($default);
     // After creating the translator instance we will set the fallback locale
     // as well as the array loader so that messages can be properly loaded
     // from the application. Then we're ready to get the language lines.
     $trans->setFallbackLocale($fallback);
     $trans->addLoader('array', new ArrayLoader());
     return $trans;
 }
开发者ID:defra91,项目名称:levecchiecredenze.it,代码行数:17,代码来源:Translator.php

示例5: testSetFallbackLocale

 public function testSetFallbackLocale()
 {
     $translator = new Translator('en', new MessageSelector());
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array('foo' => 'foofoo'), 'en');
     $translator->addResource('array', array('bar' => 'foobar'), 'fr');
     // force catalogue loading
     $translator->trans('bar');
     $translator->setFallbackLocale('fr');
     $this->assertEquals('foobar', $translator->trans('bar'));
 }
开发者ID:notbrain,项目名称:symfony,代码行数:11,代码来源:TranslatorTest.php

示例6: register

 public function register(Application $app)
 {
     $app['translator'] = $app->share(function ($app) {
         $translator = new Translator($app['locale'], $app['translator.message_selector']);
         $translator->setFallbackLocale($app['locale_fallback']);
         $translator->addLoader('array', new ArrayLoader());
         $translator->addLoader('xliff', new XliffFileLoader());
         foreach ($app['translator.domains'] as $domain => $data) {
             foreach ($data as $locale => $messages) {
                 $translator->addResource('array', $messages, $locale, $domain);
             }
         }
         return $translator;
     });
     $app['translator.message_selector'] = $app->share(function () {
         return new MessageSelector();
     });
     $app['translator.domains'] = array();
     $app['locale_fallback'] = 'en';
 }
开发者ID:ronnylt,项目名称:Silex,代码行数:20,代码来源:TranslationServiceProvider.php

示例7: register

 public function register(Application $app)
 {
     $app['translator'] = $app->share(function () use($app) {
         $translator = new Translator(isset($app['locale']) ? $app['locale'] : 'en', $app['translator.message_selector']);
         if (isset($app['locale_fallback'])) {
             $translator->setFallbackLocale($app['locale_fallback']);
         }
         $translator->addLoader('array', $app['translator.loader']);
         foreach ($app['translator.domains'] as $domain => $data) {
             foreach ($data as $locale => $messages) {
                 $translator->addResource('array', $messages, $locale, $domain);
             }
         }
         return $translator;
     });
     $app['translator.loader'] = $app->share(function () {
         return new ArrayLoader();
     });
     $app['translator.message_selector'] = $app->share(function () {
         return new MessageSelector();
     });
 }
开发者ID:nicodmf,项目名称:Silex,代码行数:22,代码来源:TranslationServiceProvider.php

示例8: register

 public function register(Application $app)
 {
     $app['translator'] = $app->share(function () use($app) {
         $translator = new Translator(isset($app['locale']) ? $app['locale'] : 'en', $app['translator.message_selector']);
         if (isset($app['locale_fallback'])) {
             $translator->setFallbackLocale($app['locale_fallback']);
         }
         $translator->addLoader('array', $app['translator.loader']);
         foreach ($app['translator.messages'] as $locale => $messages) {
             $translator->addResource('array', $messages, $locale);
         }
         return $translator;
     });
     $app['translator.loader'] = $app->share(function () {
         return new ArrayLoader();
     });
     $app['translator.message_selector'] = $app->share(function () {
         return new MessageSelector();
     });
     if (isset($app['translation.class_path'])) {
         $app['autoloader']->registerNamespace('Symfony\\Component\\Translation', $app['translation.class_path']);
     }
 }
开发者ID:nooks,项目名称:Silex,代码行数:23,代码来源:TranslationExtension.php

示例9: testTransChoiceFallbackWithNoTranslation

 public function testTransChoiceFallbackWithNoTranslation()
 {
     $translator = new Translator('ru', new MessageSelector());
     $translator->setFallbackLocale('en');
     $translator->addLoader('array', new ArrayLoader());
     // consistent behavior with Translator::trans(), which returns the string
     // unchanged if it can't be found
     $this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:9,代码来源:TranslatorTest.php

示例10: testTransChoiceFallbackWithNoTranslation

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testTransChoiceFallbackWithNoTranslation()
    {
        $translator = new Translator('ru', new MessageSelector());
        $translator->setFallbackLocale('en');
        $translator->addLoader('array', new ArrayLoader());

        $this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
    }
开发者ID:nattaphat,项目名称:hgis,代码行数:11,代码来源:TranslatorTest.php

示例11: getNonRedirectingHostMapRouter

 /**
  * Gets the translator required for checking the DoubleLocale tests (en_UK etc)
  */
 private function getNonRedirectingHostMapRouter($config = 'routing.yml')
 {
     $container = new Container();
     $container->set('routing.loader', new YamlFileLoader(new FileLocator(__DIR__ . '/Fixture')));
     $translator = new Translator('en_UK', new MessageSelector());
     $translator->setFallbackLocale('en');
     $translator->addLoader('yml', new TranslationLoader());
     $translator->addResource('yml', file_get_contents(__DIR__ . '/Fixture/routes.en_UK.yml'), 'en_UK', 'routes');
     $translator->addResource('yml', file_get_contents(__DIR__ . '/Fixture/routes.en_US.yml'), 'en_US', 'routes');
     $translator->addResource('yml', file_get_contents(__DIR__ . '/Fixture/routes.nl.yml'), 'nl', 'routes');
     $translator->addResource('yml', file_get_contents(__DIR__ . '/Fixture/routes.en.yml'), 'en', 'routes');
     $container->set('i18n_loader', new I18nLoader(new DefaultRouteExclusionStrategy(), new DefaultPatternGenerationStrategy('custom', $translator, array('en_UK', 'en_US', 'nl_NL', 'nl_BE'), sys_get_temp_dir(), 'routes', 'en_UK')));
     $router = new I18nRouter($container, $config);
     $router->setRedirectToHost(false);
     $router->setI18nLoaderId('i18n_loader');
     $router->setDefaultLocale('en_UK');
     $router->setHostMap(array('en_UK' => 'uk.test', 'en_US' => 'us.test', 'nl_NL' => 'nl.test', 'nl_BE' => 'be.test'));
     return $router;
 }
开发者ID:normandydeck1,项目名称:JMSI18nRoutingBundle,代码行数:22,代码来源:I18nRouterTest.php

示例12: getRouter

 private function getRouter($config = 'routing.yml', $translator = null)
 {
     $container = new Container();
     $container->set('routing.loader', new YamlFileLoader(new FileLocator(__DIR__ . '/Fixture')));
     if (null === $translator) {
         $translator = new Translator('en', new MessageSelector());
         $translator->setFallbackLocale('en');
         $translator->addLoader('yml', new TranslationLoader());
         $translator->addResource('yml', file_get_contents(__DIR__ . '/Fixture/routes.de.yml'), 'de', 'routes');
         $translator->addResource('yml', file_get_contents(__DIR__ . '/Fixture/routes.en.yml'), 'en', 'routes');
     }
     $container->set('i18n_loader', new I18nLoader($translator, array('en', 'de', 'fr'), 'en', 'routes', 'custom', sys_get_temp_dir()));
     $router = new I18nRouter($container, $config);
     $router->setI18nLoaderId('i18n_loader');
     $router->setDefaultLocale('en');
     return $router;
 }
开发者ID:natxet,项目名称:JMSI18nRoutingBundle,代码行数:17,代码来源:I18nRouterTest.php

示例13: setupForms

 protected function setupForms()
 {
     // Set up the CSRF provider
     $csrfProvider = new DefaultCsrfProvider(CSRF_SECRET);
     // Set up the Translation component
     $translator = new Translator('en');
     $translator->setFallbackLocale(array('en'));
     $translator->setLocale('en');
     $translator->addLoader('xlf', new XliffFileLoader());
     $translator->addResource('xlf', VENDOR_FORM_DIR . '/Resources/translations/validators.en.xlf', 'en', 'validators');
     $translator->addResource('xlf', VENDOR_VALIDATOR_DIR . '/Resources/translations/validators.en.xlf', 'en', 'validators');
     // Set up the Validator component
     $validator = Validation::createValidatorBuilder()->setTranslator($translator)->setTranslationDomain('validators')->getValidator();
     $formEngine = new TwigRendererEngine(array(DEFAULT_FORM_THEME));
     $twig = $this->view->getInstance();
     $formEngine->setEnvironment($twig);
     $twig->addExtension(new TranslationExtension($translator));
     $twig->addExtension(new FormExtension(new TwigRenderer($formEngine, $csrfProvider)));
     // Set up the Form component
     $this->form = Forms::createFormFactoryBuilder()->addExtension(new CsrfExtension($csrfProvider))->addExtension(new ValidatorExtension($validator))->getFormFactory();
 }
开发者ID:yash19970,项目名称:rapyd-framework,代码行数:21,代码来源:Application.php


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