/** * @dataProvider invalidLanguagesProvider * @expectedException \InvalidArgumentException */ public function testInvalidLanguage($language) { Language::normalize($language, '-'); }
/** * @param PageModel $page * @param string $language * * @return PageModel * * @throws \RuntimeException * @throws \InvalidArgumentException */ public function findAssociatedParentForLanguage(PageModel $page, $language) { // Stop loop if we're at the top if (0 === $page->pid || 'root' === $page->type) { $rootPages = $this->findRootPagesForPage($page); foreach ($rootPages as $model) { if (Language::toLocaleID($model->language) === $language) { return $model; } } throw new \InvalidArgumentException(sprintf('There\'s no language "%s" related to root page ID "%s"', $language, $page->id)); } $parent = PageModel::findPublishedById($page->pid); if (!$parent instanceof PageModel) { throw new \RuntimeException(sprintf('Parent page for page ID "%s" not found', $page->id)); } return $this->findAssociatedForLanguage($parent, $language); }
/** * @param string $language * @param string $href * @param string $title */ private function store($language, $href, $title) { $language = Language::toLanguageTag($language); // URLs must always be absolute if (0 !== strpos($href, 'http://') && 0 !== strpos($href, 'https://')) { $href = \Environment::get('base') . $href; } $this->links[$language] = ['language' => $language, 'href' => $href, 'title' => $title]; }
/** * Returns the language formatted as ICU Locale ID * Example: en, en_US, de_CH * * @return string * * @see http://userguide.icu-project.org/locale */ public function getLocaleId() { return Language::toLocaleID($this->rootPage->language); }