Exemplo n.º 1
0
 /**
  * Gets the translator for the provided locale
  * @param zibo\library\i18n\locale\Locale $locale
  * @return zibo\library\i18n\translation\Translator
  */
 public function getTranslator(Locale $locale)
 {
     $localeCode = $locale->getCode();
     if (array_key_exists($localeCode, $this->translators)) {
         return $this->translators[$localeCode];
     }
     return $this->translators[$localeCode] = new Translator($locale, $this->io);
 }
 /**
  * @dataProvider providerGetAllLocales
  *
  * @param Locale $locale
  * @param array $options
  */
 public function testGetLocaleReturnsNullIfLocaleNotFound(Locale $locale, $options)
 {
     $this->configIOMock->setValues('l10n', array($locale->getCode() => $options));
     $nonExistingLocale = $this->io->getLocale('nonexistinglocalecode');
     $this->assertNull($nonExistingLocale);
     $existingLocale = $this->io->getLocale($locale->getCode());
     $result = $this->assertEquals($locale, $existingLocale);
 }
 /**
  * Gets the translator for the provided locale
  * @param zibo\library\i18n\locale\Locale $locale
  * @return zibo\library\i18n\translation\Translator
  */
 public function getTranslator(Locale $locale)
 {
     $localeCode = $locale->getCode();
     if (isset($this->translators[$localeCode])) {
         return $this->translators[$localeCode];
     }
     return $this->translators[$localeCode] = new Translator($locale, $this->io);
 }
 public function providerGetLocales()
 {
     $provider = array();
     $options = array('name' => $this->name, 'plural' => $this->plural);
     $locale = new Locale($this->code, $options['name'], $options['plural']);
     $provider[] = array($locale, $options);
     $options = array('name' => $this->name, 'plural' => $this->plural, 'format' => array('date' => array('default' => 'Y-m-d H:i:s')));
     $locale = new Locale($this->code . '2', $options['name'], $options['plural']);
     $locale->setDateFormat('default', 'Y-m-d H:i:s');
     $provider[] = array($locale, $options);
     return $provider;
 }
Exemplo n.º 5
0
 /**
  * Constructs a new translator
  * @param zibo\library\i18n\locale\Locale $locale
  * @param zibo\library\i18n\translation\io\TranslationIO $io
  */
 public function __construct(Locale $locale, TranslationIO $io)
 {
     $this->locale = $locale->getCode();
     $this->pluralScript = $locale->getPluralScript();
     $this->io = $io;
 }
Exemplo n.º 6
0
 /**
  * Sets the formats of the locale
  *
  * @param array $formats
  * @param zibo\library\i18n\locale\Locale $locale
  */
 private function setFormats($formats, Locale $locale)
 {
     if (isset($formats[self::OPTION_DATE])) {
         foreach ($formats[self::OPTION_DATE] as $identifier => $format) {
             $locale->setDateFormat($identifier, $format);
         }
     }
 }
Exemplo n.º 7
0
 public function testGetDateFormatsReturnsAvailableDateFormats()
 {
     $locale = new Locale('en', 'en');
     $locale->setDateFormat('id', 'd-m-Y');
     $dateFormats = $locale->getDateFormats();
     $this->assertTrue(is_array($dateFormats));
     $this->assertEquals(array('id' => 'd-m-Y'), $dateFormats);
 }
Exemplo n.º 8
0
 /**
  * Sets a translation in this translator
  * @param string $key Key of the translation
  * @param string $translation Translation string
  * @return null
  */
 public function setTranslation($key, $translation)
 {
     $this->io->setTranslation($this->locale->getCode(), $key, $translation);
 }
Exemplo n.º 9
0
 /**
  * Sets the current locale
  * @param zibo\library\i18n\locale\Locale $locale
  * @return null
  */
 public function setCurrentLocale(Locale $locale)
 {
     setlocale(LC_ALL, $locale->getCode());
     $this->currentLocale = $locale;
 }