本文整理汇总了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;
}
示例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'));
}
示例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'));
}
示例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;
}
示例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'));
}
示例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';
}
示例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();
});
}
示例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']);
}
}
示例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)));
}
示例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)));
}
示例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;
}
示例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;
}
示例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();
}