setLocale() public method

public setLocale ( $locale )
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('lang')) {
         return;
     }
     $this->translator->setLocale($input->getOption('lang'));
 }
Ejemplo n.º 2
0
 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);
 }
 /**
  * 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);
     }
 }
Ejemplo n.º 4
0
 public function testSetGetLocale()
 {
     $translator = new Translator('en', new MessageSelector());
     $this->assertEquals('en', $translator->getLocale());
     $translator->setLocale('fr');
     $this->assertEquals('fr', $translator->getLocale());
 }
 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'));
 }
Ejemplo n.º 6
0
 public function setLocale($locale)
 {
     if (null === $locale) {
         return;
     }
     $this->app['locale'] = $locale;
     parent::setLocale($locale);
 }
Ejemplo n.º 7
0
 /**
  * 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'));
     }
 }
Ejemplo n.º 8
0
 /**
  * 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'));
 }
Ejemplo n.º 9
0
 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'));
 }
Ejemplo n.º 10
0
 /**
  * @dataProvider getValidLocalesTests
  */
 public function testSetValidLocale($locale)
 {
     $translator = new Translator($locale, new MessageSelector());
     $translator->setLocale($locale);
     $this->assertEquals($locale, $translator->getLocale());
 }
Ejemplo n.º 11
0
 public function setLocale($locale)
 {
     $this->translator->setLocale($locale);
 }
Ejemplo n.º 12
0
 /**
  * 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;
 }
Ejemplo n.º 13
0
 public function setLocale($locale)
 {
     $this->app['locale'] = $locale;
     parent::setLocale($locale);
 }
Ejemplo n.º 14
0
     * @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('', '*****@*****.**');
$violations = $validator->validate($user);
var_dump($violations->get(0)->getMessage());
Ejemplo n.º 15
0
 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();
 }
Ejemplo n.º 16
0
 /**
  * @param string $locale
  * @return $this
  */
 public function setLocale($locale)
 {
     $this->translator->setLocale($locale);
     $this->addResource($locale, 'messages');
     return $this;
 }