From 117168a8cd8d3ad15b717dd3bfde23f355f29962 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 30 Aug 2021 15:46:13 +0100
Subject: [PATCH] Issue #2639382 by mohit_aghera, yogeshmpawar, stomusic,
 mpdonadio, Abdelrahman Amer, scott_euser, idebr, dagmar, dineshw, Lendude,
 mpp, alexpott, larowlan, manuel.adan, charginghawk, cestmoi, Berdir,
 redseujac: "Authored on" string on multilanguage sites not translating;
 always renders English "ago" for "time ago" format

---
 core/config/schema/core.entity.schema.yml     |  4 +-
 .../ConfigTranslationViewListUiTest.php       | 58 +++++++++++++++++++
 .../config/schema/datetime.schema.yml         |  4 +-
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml
index 1ff2a19d7553..5603953b1c08 100644
--- a/core/config/schema/core.entity.schema.yml
+++ b/core/config/schema/core.entity.schema.yml
@@ -343,10 +343,10 @@ field.formatter.settings.timestamp_ago:
   label: 'Timestamp ago display format settings'
   mapping:
     future_format:
-      type: string
+      type: label
       label: 'Future format'
     past_format:
-      type: string
+      type: label
       label: 'Past format'
     granularity:
       type: integer
diff --git a/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
index fa520e417d46..c8bae85e9f4a 100644
--- a/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
+++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
@@ -2,7 +2,11 @@
 
 namespace Drupal\Tests\config_translation\Functional;
 
+use Drupal\language\Entity\ConfigurableLanguage;
 use Drupal\Tests\views_ui\Functional\UITestBase;
+use Drupal\views\Views;
+
+// cspell:ignore später
 
 /**
  * Visit view list and test if translate is available.
@@ -36,6 +40,8 @@ protected function setUp($import_test_views = TRUE): void {
     $permissions = [
       'administer views',
       'translate configuration',
+      'access content overview',
+      'administer languages',
     ];
 
     // Create and log in user.
@@ -60,4 +66,56 @@ public function testTranslateOperationInViewListUi() {
     $this->assertSession()->linkByHrefExists('admin/structure/views/view/test_view');
   }
 
+  /**
+   * Test to ensure that TimestampFormatter translation works.
+   */
+  public function testTimestampFormatterTranslation() {
+    ConfigurableLanguage::createFromLangcode('de')->save();
+
+    $this->drupalCreateContentType(['type' => 'article']);
+    $node = $this->drupalCreateNode(['type' => 'article', 'title' => $this->randomMachineName()]);
+
+    // Update the view to set the field formatter.
+    $view = Views::getView('content');
+    $display = &$view->storage->getDisplay('default');
+    $display['display_options']['fields']['changed']['type'] = 'timestamp_ago';
+    $display['display_options']['fields']['changed']['settings'] = [
+      'future_format' => '@interval hence',
+      'past_format' => '@interval ago',
+      'granularity' => 1,
+    ];
+    $view->save();
+
+    // Add a translation to the views configuration for the past and future
+    // formats.
+    $this->drupalGet('admin/structure/views/view/content/translate/de/edit');
+    $edit = [
+      'translation[config_names][views.view.content][display][default][display_options][fields][changed][settings][future_format]' => '@interval später',
+      'translation[config_names][views.view.content][display][default][display_options][fields][changed][settings][past_format]' => 'vor @interval',
+    ];
+    $this->submitForm($edit, 'Save translation');
+
+    // Create a timestamp just over an hour in the past and set the nodes update
+    // time to this.
+    $past_timestamp = \Drupal::time()->getCurrentTime() - 3700;
+    $node->setChangedTime($past_timestamp);
+    $node->save();
+
+    $this->drupalGet('/de/admin/content');
+    // Not all normal string translations are available, so 'hour' is still in
+    // English.
+    $this->assertSession()->pageTextContains('vor 1 hour');
+
+    // Create a timestamp just over an hour in the future and set the nodes
+    // update time to this.
+    $past_timestamp = \Drupal::time()->getCurrentTime() + 3700;
+    $node->setChangedTime($past_timestamp);
+    $node->save();
+
+    $this->drupalGet('/de/admin/content');
+    // Not all normal string translations are available, so 'hour' is still in
+    // English.
+    $this->assertSession()->pageTextContains('1 hour später');
+  }
+
 }
diff --git a/core/modules/datetime/config/schema/datetime.schema.yml b/core/modules/datetime/config/schema/datetime.schema.yml
index a00901160bd2..44783bdbefa0 100644
--- a/core/modules/datetime/config/schema/datetime.schema.yml
+++ b/core/modules/datetime/config/schema/datetime.schema.yml
@@ -55,10 +55,10 @@ field.formatter.settings.datetime_time_ago:
   label: 'Datetime time ago display format settings'
   mapping:
     future_format:
-      type: string
+      type: label
       label: 'Future format'
     past_format:
-      type: string
+      type: label
       label: 'Past format'
     granularity:
       type: integer
-- 
GitLab