Chris@0: defaultLanguage = $default_language; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function isMultilingual() { Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLanguageTypes() { Chris@0: return [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT, LanguageInterface::TYPE_URL]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns information about all defined language types. Chris@0: * Chris@0: * Defines the three core language types: Chris@0: * - Interface language is the only configurable language type in core. It is Chris@0: * used by t() as the default language if none is specified. Chris@0: * - Content language is by default non-configurable and inherits the Chris@0: * interface language negotiated value. It is used by the Field API to Chris@0: * determine the display language for fields if no explicit value is Chris@0: * specified. Chris@0: * - URL language is by default non-configurable and is determined through the Chris@0: * URL language negotiation method or the URL fallback language negotiation Chris@0: * method if no language can be detected. It is used by l() as the default Chris@0: * language if none is specified. Chris@0: * Chris@0: * @return array Chris@0: * An associative array of language type information arrays keyed by Chris@0: * language type machine name, in the format of Chris@0: * hook_language_types_info(). Chris@0: */ Chris@0: public function getDefinedLanguageTypesInfo() { Chris@0: $this->definedLanguageTypesInfo = [ Chris@0: LanguageInterface::TYPE_INTERFACE => [ Chris@0: 'name' => new TranslatableMarkup('Interface text'), Chris@0: 'description' => new TranslatableMarkup('Order of language detection methods for interface text. If a translation of interface text is available in the detected language, it will be displayed.'), Chris@0: 'locked' => TRUE, Chris@0: ], Chris@0: LanguageInterface::TYPE_CONTENT => [ Chris@0: 'name' => new TranslatableMarkup('Content'), Chris@0: 'description' => new TranslatableMarkup('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), Chris@0: 'locked' => TRUE, Chris@0: ], Chris@0: LanguageInterface::TYPE_URL => [ Chris@0: 'locked' => TRUE, Chris@0: ], Chris@0: ]; Chris@0: Chris@0: return $this->definedLanguageTypesInfo; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE) { Chris@0: return $this->getDefaultLanguage(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function reset($type = NULL) { Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDefaultLanguage() { Chris@0: return $this->defaultLanguage->get(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { Chris@0: $static_cache_id = $this->getCurrentLanguage()->getId(); Chris@0: if (!isset($this->languages[$static_cache_id][$flags])) { Chris@0: // If this language manager is used, there are no configured languages. Chris@0: // The default language and locked languages comprise the full language Chris@0: // list. Chris@0: $default = $this->getDefaultLanguage(); Chris@0: $languages = [$default->getId() => $default]; Chris@0: $languages += $this->getDefaultLockedLanguages($default->getWeight()); Chris@0: Chris@0: // Filter the full list of languages based on the value of $flags. Chris@0: $this->languages[$static_cache_id][$flags] = $this->filterLanguages($languages, $flags); Chris@0: } Chris@0: return $this->languages[$static_cache_id][$flags]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getNativeLanguages() { Chris@0: // In a language unaware site we don't have translated languages. Chris@0: return $this->getLanguages(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLanguage($langcode) { Chris@0: $languages = $this->getLanguages(LanguageInterface::STATE_ALL); Chris@0: return isset($languages[$langcode]) ? $languages[$langcode] : NULL; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLanguageName($langcode) { Chris@0: if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) { Chris@0: return new TranslatableMarkup('None'); Chris@0: } Chris@0: if ($language = $this->getLanguage($langcode)) { Chris@0: return $language->getName(); Chris@0: } Chris@0: if (empty($langcode)) { Chris@0: return new TranslatableMarkup('Unknown'); Chris@0: } Chris@0: return new TranslatableMarkup('Unknown (@langcode)', ['@langcode' => $langcode]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDefaultLockedLanguages($weight = 0) { Chris@0: $languages = []; Chris@0: Chris@0: $locked_language = [ Chris@0: 'default' => FALSE, Chris@0: 'locked' => TRUE, Chris@0: 'direction' => LanguageInterface::DIRECTION_LTR, Chris@0: ]; Chris@0: // This is called very early while initializing the language system. Prevent Chris@0: // early t() calls by using the TranslatableMarkup. Chris@0: $languages[LanguageInterface::LANGCODE_NOT_SPECIFIED] = new Language([ Chris@0: 'id' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@0: 'name' => new TranslatableMarkup('Not specified'), Chris@0: 'weight' => ++$weight, Chris@0: ] + $locked_language); Chris@0: Chris@0: $languages[LanguageInterface::LANGCODE_NOT_APPLICABLE] = new Language([ Chris@0: 'id' => LanguageInterface::LANGCODE_NOT_APPLICABLE, Chris@0: 'name' => new TranslatableMarkup('Not applicable'), Chris@0: 'weight' => ++$weight, Chris@0: ] + $locked_language); Chris@0: Chris@0: return $languages; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function isLanguageLocked($langcode) { Chris@0: $language = $this->getLanguage($langcode); Chris@0: return ($language ? $language->isLocked() : FALSE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getFallbackCandidates(array $context = []) { Chris@0: return [LanguageInterface::LANGCODE_DEFAULT]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLanguageSwitchLinks($type, Url $url) { Chris@0: return []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getStandardLanguageList() { Chris@0: // This list is based on languages available from localize.drupal.org. See Chris@0: // http://localize.drupal.org/issues for information on how to add languages Chris@0: // there. Chris@0: // Chris@0: // The "Left-to-right marker" comments and the enclosed UTF-8 markers are to Chris@0: // make otherwise strange looking PHP syntax natural (to not be displayed in Chris@0: // right to left). See https://www.drupal.org/node/128866#comment-528929. Chris@0: return [ Chris@0: 'af' => ['Afrikaans', 'Afrikaans'], Chris@0: 'am' => ['Amharic', 'አማርኛ'], Chris@0: 'ar' => ['Arabic', /* Left-to-right marker "‭" */ 'العربية', LanguageInterface::DIRECTION_RTL], Chris@0: 'ast' => ['Asturian', 'Asturianu'], Chris@0: 'az' => ['Azerbaijani', 'Azərbaycanca'], Chris@0: 'be' => ['Belarusian', 'Беларуская'], Chris@0: 'bg' => ['Bulgarian', 'Български'], Chris@0: 'bn' => ['Bengali', 'বাংলা'], Chris@0: 'bo' => ['Tibetan', 'བོད་སྐད་'], Chris@0: 'bs' => ['Bosnian', 'Bosanski'], Chris@0: 'ca' => ['Catalan', 'Català'], Chris@0: 'cs' => ['Czech', 'Čeština'], Chris@0: 'cy' => ['Welsh', 'Cymraeg'], Chris@0: 'da' => ['Danish', 'Dansk'], Chris@0: 'de' => ['German', 'Deutsch'], Chris@0: 'dz' => ['Dzongkha', 'རྫོང་ཁ'], Chris@0: 'el' => ['Greek', 'Ελληνικά'], Chris@0: 'en' => ['English', 'English'], Chris@0: 'en-x-simple' => ['Simple English', 'Simple English'], Chris@0: 'eo' => ['Esperanto', 'Esperanto'], Chris@0: 'es' => ['Spanish', 'Español'], Chris@0: 'et' => ['Estonian', 'Eesti'], Chris@0: 'eu' => ['Basque', 'Euskera'], Chris@0: 'fa' => ['Persian, Farsi', /* Left-to-right marker "‭" */ 'فارسی', LanguageInterface::DIRECTION_RTL], Chris@0: 'fi' => ['Finnish', 'Suomi'], Chris@0: 'fil' => ['Filipino', 'Filipino'], Chris@0: 'fo' => ['Faeroese', 'Føroyskt'], Chris@0: 'fr' => ['French', 'Français'], Chris@0: 'fy' => ['Frisian, Western', 'Frysk'], Chris@0: 'ga' => ['Irish', 'Gaeilge'], Chris@0: 'gd' => ['Scots Gaelic', 'Gàidhlig'], Chris@0: 'gl' => ['Galician', 'Galego'], Chris@0: 'gsw-berne' => ['Swiss German', 'Schwyzerdütsch'], Chris@0: 'gu' => ['Gujarati', 'ગુજરાતી'], Chris@0: 'he' => ['Hebrew', /* Left-to-right marker "‭" */ 'עברית', LanguageInterface::DIRECTION_RTL], Chris@0: 'hi' => ['Hindi', 'हिन्दी'], Chris@0: 'hr' => ['Croatian', 'Hrvatski'], Chris@0: 'ht' => ['Haitian Creole', 'Kreyòl ayisyen'], Chris@0: 'hu' => ['Hungarian', 'Magyar'], Chris@0: 'hy' => ['Armenian', 'Հայերեն'], Chris@0: 'id' => ['Indonesian', 'Bahasa Indonesia'], Chris@0: 'is' => ['Icelandic', 'Íslenska'], Chris@0: 'it' => ['Italian', 'Italiano'], Chris@0: 'ja' => ['Japanese', '日本語'], Chris@0: 'jv' => ['Javanese', 'Basa Java'], Chris@0: 'ka' => ['Georgian', 'ქართული ენა'], Chris@0: 'kk' => ['Kazakh', 'Қазақ'], Chris@0: 'km' => ['Khmer', 'ភាសាខ្មែរ'], Chris@0: 'kn' => ['Kannada', 'ಕನ್ನಡ'], Chris@0: 'ko' => ['Korean', '한국어'], Chris@0: 'ku' => ['Kurdish', 'Kurdî'], Chris@0: 'ky' => ['Kyrgyz', 'Кыргызча'], Chris@0: 'lo' => ['Lao', 'ພາສາລາວ'], Chris@0: 'lt' => ['Lithuanian', 'Lietuvių'], Chris@0: 'lv' => ['Latvian', 'Latviešu'], Chris@0: 'mg' => ['Malagasy', 'Malagasy'], Chris@0: 'mk' => ['Macedonian', 'Македонски'], Chris@0: 'ml' => ['Malayalam', 'മലയാളം'], Chris@0: 'mn' => ['Mongolian', 'монгол'], Chris@0: 'mr' => ['Marathi', 'मराठी'], Chris@0: 'ms' => ['Bahasa Malaysia', 'بهاس ملايو'], Chris@0: 'my' => ['Burmese', 'ဗမာစကား'], Chris@0: 'ne' => ['Nepali', 'नेपाली'], Chris@0: 'nl' => ['Dutch', 'Nederlands'], Chris@0: 'nb' => ['Norwegian Bokmål', 'Norsk, bokmål'], Chris@0: 'nn' => ['Norwegian Nynorsk', 'Norsk, nynorsk'], Chris@0: 'oc' => ['Occitan', 'Occitan'], Chris@0: 'pa' => ['Punjabi', 'ਪੰਜਾਬੀ'], Chris@0: 'pl' => ['Polish', 'Polski'], Chris@0: 'pt-pt' => ['Portuguese, Portugal', 'Português, Portugal'], Chris@0: 'pt-br' => ['Portuguese, Brazil', 'Português, Brasil'], Chris@0: 'ro' => ['Romanian', 'Română'], Chris@0: 'ru' => ['Russian', 'Русский'], Chris@0: 'sco' => ['Scots', 'Scots'], Chris@0: 'se' => ['Northern Sami', 'Sámi'], Chris@0: 'si' => ['Sinhala', 'සිංහල'], Chris@0: 'sk' => ['Slovak', 'Slovenčina'], Chris@0: 'sl' => ['Slovenian', 'Slovenščina'], Chris@0: 'sq' => ['Albanian', 'Shqip'], Chris@0: 'sr' => ['Serbian', 'Српски'], Chris@0: 'sv' => ['Swedish', 'Svenska'], Chris@0: 'sw' => ['Swahili', 'Kiswahili'], Chris@0: 'ta' => ['Tamil', 'தமிழ்'], Chris@0: 'ta-lk' => ['Tamil, Sri Lanka', 'தமிழ், இலங்கை'], Chris@0: 'te' => ['Telugu', 'తెలుగు'], Chris@0: 'th' => ['Thai', 'ภาษาไทย'], Chris@0: 'tr' => ['Turkish', 'Türkçe'], Chris@0: 'tyv' => ['Tuvan', 'Тыва дыл'], Chris@0: 'ug' => ['Uyghur', /* Left-to-right marker "‭" */ 'ئۇيغۇرچە', LanguageInterface::DIRECTION_RTL], Chris@0: 'uk' => ['Ukrainian', 'Українська'], Chris@0: 'ur' => ['Urdu', /* Left-to-right marker "‭" */ 'اردو', LanguageInterface::DIRECTION_RTL], Chris@0: 'vi' => ['Vietnamese', 'Tiếng Việt'], Chris@0: 'xx-lolspeak' => ['Lolspeak', 'Lolspeak'], Chris@0: 'zh-hans' => ['Chinese, Simplified', '简体中文'], Chris@0: 'zh-hant' => ['Chinese, Traditional', '繁體中文'], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * The 6 official languages used at the United Nations. Chris@0: * Chris@0: * This list is based on Chris@0: * http://www.un.org/en/sections/about-un/official-languages/index.html and it Chris@0: * uses the same format as getStandardLanguageList(). Chris@0: * Chris@0: * @return array Chris@0: * An array with language codes as keys, and English and native language Chris@0: * names as values. Chris@0: */ Chris@0: public static function getUnitedNationsLanguageList() { Chris@0: return [ Chris@0: 'ar' => ['Arabic', /* Left-to-right marker "‭" */ 'العربية', LanguageInterface::DIRECTION_RTL], Chris@0: 'zh-hans' => ['Chinese, Simplified', '简体中文'], Chris@0: 'en' => ['English', 'English'], Chris@0: 'fr' => ['French', 'Français'], Chris@0: 'ru' => ['Russian', 'Русский'], Chris@0: 'es' => ['Spanish', 'Español'], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Sets the configuration override language. Chris@0: * Chris@0: * This function is a noop since the configuration cannot be overridden by Chris@0: * language unless the Language module is enabled. That replaces the default Chris@0: * language manager with a configurable language manager. Chris@0: * Chris@14: * @param \Drupal\Core\Language\LanguageInterface $language Chris@14: * The language to override configuration with. Chris@14: * Chris@14: * @return $this Chris@14: * Chris@0: * @see \Drupal\language\ConfigurableLanguageManager::setConfigOverrideLanguage() Chris@0: */ Chris@0: public function setConfigOverrideLanguage(LanguageInterface $language = NULL) { Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getConfigOverrideLanguage() { Chris@0: return $this->getCurrentLanguage(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Filters the full list of languages based on the value of the flag. Chris@0: * Chris@0: * The locked languages are removed by default. Chris@0: * Chris@0: * @param \Drupal\Core\Language\LanguageInterface[] $languages Chris@0: * Array with languages to be filtered. Chris@0: * @param int $flags Chris@0: * (optional) Specifies the state of the languages that have to be returned. Chris@0: * It can be: LanguageInterface::STATE_CONFIGURABLE, Chris@0: * LanguageInterface::STATE_LOCKED, or LanguageInterface::STATE_ALL. Chris@0: * Chris@0: * @return \Drupal\Core\Language\LanguageInterface[] Chris@0: * An associative array of languages, keyed by the language code. Chris@0: */ Chris@0: protected function filterLanguages(array $languages, $flags = LanguageInterface::STATE_CONFIGURABLE) { Chris@0: // STATE_ALL means we don't actually filter, so skip the rest of the method. Chris@0: if ($flags == LanguageInterface::STATE_ALL) { Chris@0: return $languages; Chris@0: } Chris@0: Chris@0: $filtered_languages = []; Chris@0: // Add the site's default language if requested. Chris@0: if ($flags & LanguageInterface::STATE_SITE_DEFAULT) { Chris@0: Chris@0: // Setup a language to have the defaults with data appropriate of the Chris@0: // default language only for runtime. Chris@0: $defaultLanguage = $this->getDefaultLanguage(); Chris@0: $default = new Language( Chris@0: [ Chris@0: 'id' => $defaultLanguage->getId(), Chris@0: 'name' => new TranslatableMarkup("Site's default language (@lang_name)", Chris@0: ['@lang_name' => $defaultLanguage->getName()]), Chris@0: 'direction' => $defaultLanguage->getDirection(), Chris@0: 'weight' => $defaultLanguage->getWeight(), Chris@0: ] Chris@0: ); Chris@0: $filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default; Chris@0: } Chris@0: Chris@0: foreach ($languages as $id => $language) { Chris@0: if (($language->isLocked() && ($flags & LanguageInterface::STATE_LOCKED)) || (!$language->isLocked() && ($flags & LanguageInterface::STATE_CONFIGURABLE))) { Chris@0: $filtered_languages[$id] = $language; Chris@0: } Chris@0: } Chris@0: Chris@0: return $filtered_languages; Chris@0: } Chris@0: Chris@0: }