languageId = $languageId; $this->locale = new Locale($locale); $this->base = $base; $this->configuration = $configuration; if (!empty($configuration['languageTag'])) { $this->languageTag = $configuration['languageTag']; } if (!empty($configuration['title'])) { $this->title = $configuration['title']; } if (!empty($configuration['navigationTitle'])) { $this->navigationTitle = $configuration['navigationTitle']; } if (!empty($configuration['websiteTitle'])) { $this->websiteTitle = $configuration['websiteTitle']; } if (!empty($configuration['flag'])) { $this->flagIdentifier = $configuration['flag']; } if (!empty($configuration['typo3Language'])) { $this->typo3Language = $configuration['typo3Language']; } if (!empty($configuration['hreflang'])) { $this->hreflang = $configuration['hreflang']; } if (!empty($configuration['fallbackType'])) { $this->fallbackType = $configuration['fallbackType']; } if (isset($configuration['fallbacks'])) { $fallbackLanguageIds = $configuration['fallbacks']; // It is important to distinct between "0" and "" so, empty() should not be used here if (is_string($fallbackLanguageIds)) { if ($fallbackLanguageIds !== '') { $fallbackLanguageIds = explode(',', $fallbackLanguageIds); } else { $fallbackLanguageIds = []; } } elseif (is_scalar($fallbackLanguageIds)) { $fallbackLanguageIds = [$fallbackLanguageIds]; } $this->fallbackLanguageIds = array_map(intval(...), $fallbackLanguageIds); } if (isset($configuration['enabled'])) { $this->enabled = (bool)$configuration['enabled']; } if (!empty($configuration['primary'])) { $this->primary = true; } } /** * Returns the SiteLanguage in an array representation for e.g. the usage * in TypoScript. */ public function toArray(): array { return array_merge($this->configuration, [ 'languageId' => $this->getLanguageId(), 'languageTag' => $this->getLanguageTag(), // kept for backwards-compat for the time being, might change to BGP-47 format 'locale' => $this->getLocale()->posixFormatted(), 'base' => (string)$this->getBase(), 'title' => $this->getTitle(), 'websiteTitle' => $this->getWebsiteTitle(), 'navigationTitle' => $this->getNavigationTitle(), 'hreflang' => $this->hreflang ?: $this->locale->getName(), 'typo3Language' => $this->getTypo3Language(), 'flagIdentifier' => $this->getFlagIdentifier(), 'fallbackType' => $this->getFallbackType(), 'enabled' => $this->enabled(), 'primary' => $this->isPrimary(), 'fallbackLanguageIds' => $this->getFallbackLanguageIds(), ]); } public function getConfiguration(): array { return $this->toArray(); } public function getLanguageId(): int { return $this->languageId; } public function getLanguageTag(): string { return $this->languageTag; } public function getLocale(): Locale { return $this->locale; } public function getBase(): UriInterface { return $this->base; } public function getTitle(): string { return $this->title; } public function getNavigationTitle(): string { return $this->navigationTitle ?: $this->title; } public function getWebsiteTitle(): string { return $this->websiteTitle; } public function getFlagIdentifier(): string { return $this->flagIdentifier; } /** * Returns the XLF label language key. * For locales like "en-US", this method returns "en_US" which can then be used * for XLF file prefixes properly. */ public function getTypo3Language(): string { if ($this->typo3Language !== '') { return $this->typo3Language; } $typo3Language = $this->locale->getLanguageCode(); if ($this->locale->getCountryCode()) { $typo3Language .= '_' . $this->locale->getCountryCode(); } return $typo3Language; } /** * @internal */ public function hasCustomTypo3Language(): bool { return $this->typo3Language !== ''; } /** * Returns the RFC 1766 / 3066 language tag for hreflang tags */ public function getHreflang(bool $fetchCustomSetting = false): string { // Ensure to check if a custom attribute is set if ($fetchCustomSetting) { return $this->hreflang; } return $this->hreflang ?: $this->locale->getName(); } /** * Returns true if the language is available in frontend usage */ public function enabled(): bool { return $this->enabled; } /** * Helper so fluid can work with this as well. */ public function isEnabled(): bool { return $this->enabled; } public function isPrimary(): bool { return $this->primary; } public function getFallbackType(): string { return $this->fallbackType; } public function getFallbackLanguageIds(): array { return $this->fallbackLanguageIds; } }