diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/Date.php index 51a16eb..f7bd661 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/Date.php @@ -127,32 +127,12 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N return Xss::filter($date->format($format, $settings)); } - /** - * 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. - */ protected function dateFormat($format, $langcode = NULL) { - $needs_language_context = !empty($langcode); if (empty($langcode)) { $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 - // given, so the right date format is loaded. - $needs_language_context = $needs_language_context && - \Drupal::moduleHandler()->moduleExists('language') && !empty($langcode); - if ($needs_language_context) { - $language_context = config_context_enter('Drupal\language\LanguageConfigContext'); - $language_context->setLanguage(new Language(array('id' => $langcode))); - } $this->dateFormats[$format][$langcode] = $this->dateFormatStorage->load($format); - if ($needs_language_context) { - config_context_leave(); - } } return $this->dateFormats[$format][$langcode]; } diff --git a/core/modules/locale/lib/Drupal/locale/LocalizedDate.php b/core/modules/locale/lib/Drupal/locale/LocalizedDate.php new file mode 100644 index 0000000..72760b9 --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/LocalizedDate.php @@ -0,0 +1,35 @@ +setLanguage(new Language(array('id' => $langcode))); + $format = parent::dateFormat($format, $langcode); + config_context_leave(); + return $format; + } + +} diff --git a/core/modules/locale/lib/Drupal/locale/LocalizedDateServiceProvider.php b/core/modules/locale/lib/Drupal/locale/LocalizedDateServiceProvider.php new file mode 100644 index 0000000..75d0f6b --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/LocalizedDateServiceProvider.php @@ -0,0 +1,35 @@ +getDefinition('date'); + $definition->setClass('Drupal\locale\LocalizedDate'); + } + +} diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php index 72f8e39..efae6b8 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php @@ -117,7 +117,7 @@ function testConfigTranslation() { $this->assertEqual($format, 'D', 'Got the right date format pattern after translation.'); // Formatting the date 8 / 27 / 1985 @ 13:37 EST with pattern D should display "Tue". - $formatted_date = format_date(494015820, $type = 'medium', NULL, NULL, $langcode = $langcode); + $formatted_date = format_date(494015820, 'medium', NULL, NULL, $langcode); $this->assertEqual($formatted_date, 'Tue', 'Got the right formatted date using the date format translation pattern.'); // Assert strings from image module config are not available.