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


PHP Translator::setLocale方法代码示例

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


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

示例1: execute

 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('lang')) {
         return;
     }
     $this->translator->setLocale($input->getOption('lang'));
 }
开发者ID:OverByThere,项目名称:Behat,代码行数:10,代码来源:LanguageController.php

示例2: __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

示例3: configureLocale

 /**
  * Configure translator locale.
  */
 public static function configureLocale()
 {
     $localeOption = Validation::option('locale');
     if (!is_array($localeOption)) {
         /** @noinspection ExceptionsAnnotatingAndHandlingInspection */
         self::$translator->setLocale($localeOption);
         /** @noinspection ExceptionsAnnotatingAndHandlingInspection */
         self::$translator->setFallbackLocales([$localeOption]);
     } else {
         /** @noinspection ExceptionsAnnotatingAndHandlingInspection */
         self::$translator->setLocale(array_shift($localeOption));
         /** @noinspection ExceptionsAnnotatingAndHandlingInspection */
         self::$translator->setFallbackLocales($localeOption);
     }
 }
开发者ID:VanillaPackage,项目名称:vanilla-validation,代码行数:18,代码来源:ValidationLocalize.php

示例4: testSetGetLocale

 public function testSetGetLocale()
 {
     $translator = new Translator('en', new MessageSelector());
     $this->assertEquals('en', $translator->getLocale());
     $translator->setLocale('fr');
     $this->assertEquals('fr', $translator->getLocale());
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:7,代码来源:TranslatorTest.php

示例5: testGetCatalogue

 public function testGetCatalogue()
 {
     $translator = new Translator('en');
     $this->assertEquals(new MessageCatalogue('en'), $translator->getCatalogue());
     $translator->setLocale('fr');
     $this->assertEquals(new MessageCatalogue('fr'), $translator->getCatalogue('fr'));
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:7,代码来源:TranslatorTest.php

示例6: setLocale

 public function setLocale($locale)
 {
     if (null === $locale) {
         return;
     }
     $this->app['locale'] = $locale;
     parent::setLocale($locale);
 }
开发者ID:brodaproject,项目名称:broda,代码行数:8,代码来源:Translator.php

示例7: execute

 /**
  * Validate the security.yml and the configuration.yml.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $language = $input->getArgument('language');
     if (in_array($language, array('de', 'en')) == true) {
         $this->translator->setLocale($language);
     }
     if (is_dir($this->configDir) == true) {
         if ($this->validateSecurity($output) == true) {
             $output->writeln($this->translator->trans('validation.success', array('%file%' => 'security')));
         }
         if ($this->validateConfiguration($output) == true) {
             $output->writeln($this->translator->trans('validation.success', array('%file%' => 'configuration')));
         }
     } else {
         $output->writeln($this->translator->trans('validation.error.dir'));
     }
 }
开发者ID:dimug,项目名称:api,代码行数:24,代码来源:ValidateCommand.php

示例8: execute

 /**
  * Validate the security.yml and the configuration.yml.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $language = $input->getArgument('language');
     if (in_array($language, array('de', 'en')) == true) {
         $this->translator->setLocale($language);
     }
     foreach ($this->installs as $install) {
         if ($this->createDir($install['target']) == true) {
             if (isset($install['source']) == true) {
                 if ($this->copyFiles($output, $install['source'], $install['target'], $install['files']) == false) {
                     return;
                 }
             }
         } else {
             $output->writeln($this->translator->trans('install.dir.create', array('%dir%' => $install['target'])));
             return;
         }
     }
     $output->writeln($this->translator->trans('install.success'));
 }
开发者ID:dimug,项目名称:api,代码行数:27,代码来源:InstallCommand.php

示例9: testRefreshCacheWhenResourcesChange

 public function testRefreshCacheWhenResourcesChange()
 {
     // prime the cache
     $loader = $this->getMock('Symfony\\Component\\Translation\\Loader\\LoaderInterface');
     $loader->method('load')->will($this->returnValue($this->getCatalogue('fr', array('foo' => 'foo A'))));
     $translator = new Translator('fr', null, $this->tmpDir, true);
     $translator->setLocale('fr');
     $translator->addLoader('loader', $loader);
     $translator->addResource('loader', 'foo', 'fr');
     $this->assertEquals('foo A', $translator->trans('foo'));
     // add a new resource to refresh the cache
     $loader = $this->getMock('Symfony\\Component\\Translation\\Loader\\LoaderInterface');
     $loader->method('load')->will($this->returnValue($this->getCatalogue('fr', array('foo' => 'foo B'))));
     $translator = new Translator('fr', null, $this->tmpDir, true);
     $translator->setLocale('fr');
     $translator->addLoader('loader', $loader);
     $translator->addResource('loader', 'bar', 'fr');
     $this->assertEquals('foo B', $translator->trans('foo'));
 }
开发者ID:RuntyCybin,项目名称:csymfony,代码行数:19,代码来源:TranslatorCacheTest.php

示例10: testSetValidLocale

 /**
  * @dataProvider getValidLocalesTests
  */
 public function testSetValidLocale($locale)
 {
     $translator = new Translator($locale, new MessageSelector());
     $translator->setLocale($locale);
     $this->assertEquals($locale, $translator->getLocale());
 }
开发者ID:Viduc,项目名称:tiremoidlaold,代码行数:9,代码来源:TranslatorTest.php

示例11: setLocale

 public function setLocale($locale)
 {
     $this->translator->setLocale($locale);
 }
开发者ID:JoshyPHP,项目名称:flarum-core,代码行数:4,代码来源:LocaleManager.php

示例12: setLocale

 /**
  * Megpróbálja beállítani a paraméterben megadott locale-t. Ha nincsen, megpróbálja betölteni a HTTP_ACCEPT_LANGUAGE
  * szerver változóból a locale-t, de ha az nem támogatott, akkor legvégül a default nyelvet tölti be.
  *
  * Igaz a visszatérési érték, ha sikerült beállítani a paraméterben megadott locale-t. Minden más esetben hamis.
  *
  * @param string $locale
  * @return bool
  */
 public function setLocale($locale)
 {
     if ($this->isSupportedLocale($locale)) {
         //Ha létezik ilyen támogatott locale, akkor beállítjuk
         $validLocale = $locale;
         $success = true;
     } else {
         //Ha nem létezik megpróbáljuk beállítani a HTTP_ACCEPT_LANGUAGE változóból
         $httpLocale = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
         if ($this->isSupportedLocale($httpLocale)) {
             $validLocale = $httpLocale;
         } else {
             $validLocale = $this->configuration["fallbackLocales"][0];
         }
         $success = false;
     }
     $this->translator->setLocale($validLocale);
     // Adott stratégiák esetén be kell állítani a cookie-kat is
     if ($this->configuration["strategy"] == Translator::STRATEGY_ONLY_COOKIE || $this->configuration["strategy"] == Translator::STRATEGY_COOKIE_AND_URL) {
         $this->setLocaleToCookie($validLocale);
     }
     return $success;
 }
开发者ID:nagyatka,项目名称:kodiapp,代码行数:32,代码来源:Translator.php

示例13: setLocale

 public function setLocale($locale)
 {
     $this->app['locale'] = $locale;
     parent::setLocale($locale);
 }
开发者ID:silvioneto,项目名称:ondealmocar,代码行数:5,代码来源:Translator.php

示例14: __construct

     * @Assert\NotBlank(message = "user.name.not_blank")
     */
    private $name;
    /**
     * @Assert\Email
     * @Assert\NotBlank
     */
    private $email;
    public function __construct($name, $email)
    {
        $this->name = $name;
        $this->email = $email;
    }
    /**
     * @Assert\IsTrue(message = "The user should have a Google Mail account")
     */
    public function isGmailUser()
    {
        return false !== strpos($this->email, '@gmail.com');
    }
}
$trans = new Translator('es');
$trans->setLocale("zh");
$trans->addLoader('xliff', new XliffFileLoader());
$trans->addResource('xliff', __DIR__ . '/Resources/translations/validators.en.xlf', 'en');
$trans->addResource('xliff', __DIR__ . '/Resources/translations/validators.es.xlf', 'es');
$trans->addResource('xliff', __DIR__ . '/Resources/translations/validators.zh.xlf', 'zh');
$validator = Validation::createValidatorBuilder()->setTranslator($trans)->enableAnnotationMapping()->getValidator();
$user = new User('', 'john@example.com');
$violations = $validator->validate($user);
var_dump($violations->get(0)->getMessage());
开发者ID:qiuyin,项目名称:symfony_validation,代码行数:31,代码来源:main.php

示例15: 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::setLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。