/** * @covers phpDocumentor\Translator\Translator::addTranslations * @covers phpDocumentor\Translator\Translator::translate */ public function testTranslateWithAlternateDefaultLocale() { $this->fixture->addTranslations($this->filename, self::LOCALE_NL); $this->fixture->setLocale(self::LOCALE_NL); $this->assertEquals(self::TEST_VALUE, $this->fixture->translate(self::TEST_KEY)); }
public function initLocale() { // Load from persist $locale = $this->getPersist(static::PERSIST_LOCALE); if ($locale) { $this->locale = $locale; // Detect via browser } elseif (!$this->locale) { $auto = 'en'; $acceptedLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; $matched = preg_match_all('/([a-z]{2,8}(-[a-z]{2,8})?)\\s*(;\\s*q\\s*=\\s*(1|0\\.[0-9]+))?/i', $acceptedLanguage, $matches); if ($matched) { $languageList = $this->getLanguages(); foreach ($matches[1] as $language) { $canonized = strtolower($language); if (isset($languageList[$canonized])) { $auto = $canonized; break; } else { $pos = strpos($language, '-'); if (false !== $pos) { $canonized = substr($language, 0, $pos); if (isset($languageList[$canonized])) { $auto = $canonized; break; } } } } } $this->setLocale($auto); } $charset = $this->getPersist(static::PERSIST_CHARSET); if ($charset) { $this->charset = $charset; } Translator::setPath($this->getRoot() . '/locale'); Translator::setLocale($this->locale); Translator::loadDomain('default'); }