diff --git a/core/includes/config.inc b/core/includes/config.inc index 2857c68..c7362a2 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -179,6 +179,19 @@ function config_context_leave() { } /** + * Gets the current config context. + * + * @see config_context_enter() + * @see config_context_leave() + * @see \Drupal\Core\Config\ConfigFactory + */ +function config_context() { + drupal_container() + ->get('config.factory') + ->getContext(); +} + +/** * Return a list of all config entity types provided by a module. * * @param string $module diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/Date.php index 8f5831a..63b601b 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/Date.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Datetime; use Drupal\Component\Utility\Xss; +use Drupal\Core\Config\Context\LanguageConfigContext; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Language\Language; @@ -130,16 +131,26 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N /** * Loads the given format pattern for the given langcode. * - * @param string $format The machine name of the date format. - * @param string $langcode The langcode of the language to use. - * If NULL, we load the interface language format pattern. - * @return string The pattern for the date format in the given language. + * @param string $format + * The machine name of the date format. + * @param string $langcode + * The langcode of the language to use. If NULL, we load the current context + * language if any or the interface language format pattern as the last fallback. + * @return string + * The pattern for the date format in the given language. */ protected function dateFormat($format, $langcode = NULL) { // If a langcode is not given, we use the interface language. $needs_language_context = !empty($langcode); if (!$needs_language_context) { - $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; + // If we are at any context we try to get the language from there. + $context = config_context(); + if ($context !== NULL && $contextLanguage = $context->get(LanguageConfigContext::LANGUAGE_KEY)) { + $langcode = $contextLanguage; + } + else { + $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; + } } if (!isset($this->dateFormats[$format][$langcode])) { // Enter a language specific context for the language if some language is