コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 /**
  * @dataProvider languagesProvider
  */
 public function testConvertLanguageTagToLocaleId($localeId, $languageTag)
 {
     $this->assertEquals($localeId, Language::toLocaleID($languageTag));
 }
コード例 #3
0
 /**
  * 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);
 }