Unverified Commit 117168a8 authored by alexpott's avatar alexpott
Browse files

Issue #2639382 by mohit_aghera, yogeshmpawar, stomusic, mpdonadio, Abdelrahman...

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
parent f928fe9d
......@@ -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
......
......@@ -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');
}
}
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment