/**
  * @dataProvider providerGetLocales
  */
 public function testGetLocales(Locale $locale, $options)
 {
     $this->configIOMock->setValues('l10n', array($locale->getCode() => $options));
     $result = $this->io->getLocales();
     $expected = array($locale->getCode() => $locale);
     $this->assertEquals($expected, $result);
 }
 /**
  * @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);
 }
Beispiel #3
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);
 }
 /**
  * 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);
 }
Beispiel #5
0
 public function testConstruct()
 {
     $code = "code";
     $name = "name";
     $plural = "plural";
     $locale = new Locale($code, $name, $plural);
     $this->assertEquals($code, $locale->getCode());
     $this->assertEquals($name, $locale->getName());
     $this->assertEquals($plural, $locale->getPluralScript());
 }
Beispiel #6
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;
 }
Beispiel #7
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);
 }
Beispiel #8
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;
 }