diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index eda43525fb3311070ef26f0870623b339cbb9197..cd27c747b824f2e95edfb760bfb2203a875d13bc 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -87,28 +87,43 @@ public function getLanguageTypes() { } /** - * {@inheritdoc} + * Returns information about all defined language types. + * + * Defines the three core language types: + * - Interface language is the only configurable language type in core. It is + * used by t() as the default language if none is specified. + * - Content language is by default non-configurable and inherits the + * interface language negotiated value. It is used by the Field API to + * determine the display language for fields if no explicit value is + * specified. + * - URL language is by default non-configurable and is determined through the + * URL language negotiation method or the URL fallback language negotiation + * method if no language can be detected. It is used by l() as the default + * language if none is specified. + * + * @return array + * An associative array of language type information arrays keyed by + * language type machine name, in the format of + * hook_language_types_info(). */ public function getDefinedLanguageTypesInfo() { - // This needs to have the same return value as - // language_language_type_info(), so that even if the Language module is - // not defined, users of this information, such as the Views module, can - // access names and descriptions of the default language types. - return array( + $this->definedLanguageTypesInfo = array( LanguageInterface::TYPE_INTERFACE => array( - 'name' => $this->t('Interface text'), - 'description' => $this->t('Order of language detection methods for interface text. If a translation of interface text is available in the detected language, it will be displayed.'), + 'name' => new TranslationWrapper('Interface text'), + 'description' => new TranslationWrapper('Order of language detection methods for interface text. If a translation of interface text is available in the detected language, it will be displayed.'), 'locked' => TRUE, ), LanguageInterface::TYPE_CONTENT => array( - 'name' => $this->t('Content'), - 'description' => $this->t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), + 'name' => new TranslationWrapper('Content'), + 'description' => new TranslationWrapper('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), 'locked' => TRUE, ), LanguageInterface::TYPE_URL => array( 'locked' => TRUE, ), ); + + return $this->definedLanguageTypesInfo; } /** diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 342e7302d8a8d6567ba1574dc0ca2eec2a99584b..29c93d2cf9e383c9c9e863d82d50f3e27c3901f0 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -282,42 +282,6 @@ function language_get_default_langcode($entity_type, $bundle) { return $configuration->getDefaultLangcode(); } -/** - * Implements hook_language_types_info(). - * - * Defines the three core language types: - * - Interface language is the only configurable language type in core. It is - * used by t() as the default language if none is specified. - * - Content language is by default non-configurable and inherits the interface - * language negotiated value. It is used by the Field API to determine the - * display language for fields if no explicit value is specified. - * - URL language is by default non-configurable and is determined through the - * URL language negotiation method or the URL fallback language negotiation - * method if no language can be detected. It is used by l() as the default - * language if none is specified. - */ -function language_language_types_info() { - return array( - LanguageInterface::TYPE_INTERFACE => array( - 'name' => t('Interface text'), - 'description' => t('Order of language detection methods for interface text. If a translation of interface text is available in the detected language, it will be displayed.'), - 'locked' => TRUE, - ), - LanguageInterface::TYPE_CONTENT => array( - 'name' => t('Content'), - 'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), - 'fixed' => array(LanguageNegotiationUI::METHOD_ID), - 'locked' => TRUE, - ), - LanguageInterface::TYPE_URL => array( - 'name' => t('URL'), - 'description' => t('Order of language detection methods for URLs. The detected language will be used as the default when generating URLs for internal links on the site.'), - 'fixed' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationUrlFallback::METHOD_ID), - 'locked' => TRUE, - ), - ); -} - /** * Reads language prefixes and uses the langcode if no prefix is set. */ @@ -540,3 +504,16 @@ function language_tour_tips_alter(array &$tour_tips, EntityInterface $entity) { } } } + +/** + * Implements hook_language_types_info_alter(). + * + * We can't set the fixed properties in \Drupal\Core\Language\LanguageManager, + * where the rest of the properties for the default language types are defined. + * The LanguageNegation classes are only loaded when the language module is + * enabled and we can't be sure of that in the LanguageManager. + */ +function language_language_types_info_alter(array &$language_types) { + $language_types[LanguageInterface::TYPE_CONTENT]['fixed'] = [LanguageNegotiationUI::METHOD_ID]; + $language_types[LanguageInterface::TYPE_URL]['fixed'] = [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationUrlFallback::METHOD_ID]; +} diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index d4dad5c04932f042d6e377aa1631b97a3b4d0823..d51692f1a43c079b5d2ab7f24d714138edf5472b 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -182,10 +182,14 @@ protected function loadLanguageTypesConfiguration() { */ public function getDefinedLanguageTypesInfo() { if (!isset($this->languageTypesInfo)) { + $defaults = parent::getDefinedLanguageTypesInfo(); + $info = $this->moduleHandler->invokeAll('language_types_info'); + $language_info = $info + $defaults; + // Let other modules alter the list of language types. - $this->moduleHandler->alter('language_types_info', $info); - $this->languageTypesInfo = $info; + $this->moduleHandler->alter('language_types_info', $language_info); + $this->languageTypesInfo = $language_info; } return $this->languageTypesInfo; }