當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。