I came across a small glitch when using views on a multilanguage site. When using the "Authored On" field in a view, views will not use a translated version of the whole string but only of the time itself. For example:

  • Last updated: 2 hours 34 minutes ago
  • Letztes update: 2 Stunden 34 Minuten ago

As for the second line (which is in German), the "ago" should switch to a place in front of the string and be translated to "vor".

I checked the string translations but could not find the correct one; I'd be more than happy to fix this if someone could just point me to the right location. I also found other Drupal 8 sites while doing my research about this which are suffering from the same problem.

Proposed fix:
* Change the config from a string to a label
* Other issues like #3063020: Support translation of the list of styles in CKEditor have done this without an upgrade path, so follow that pattern

CommentFileSizeAuthor
#94 interdiff-2639382-92-94.txt2.17 KBmohit_aghera
#94 2639382-94.patch4.71 KBmohit_aghera
#92 interdiff-2639382-88-92.txt2.56 KBmohit_aghera
#92 2639382-92.patch4.46 KBmohit_aghera
#88 interdiff-2639382-64-88.txt2.78 KBmohit_aghera
#88 test-only-2639382-88.patch2.78 KBmohit_aghera
#88 2639382-88.patch3.95 KBmohit_aghera
#83 2639382-81.patch2.85 KBAbdelrahman Amer
#82 2639382-80.patch2.6 KBAbdelrahman Amer
#64 interdiff-60-64.txt630 bytesmpdonadio
#64 2639382-64.patch1.17 KBmpdonadio
#63 Screenshot from 2019-01-26 17-05-36.png8.72 KBscott_euser
#60 drupal-future-past-timestamp-ago-formatter-2639382-59.patch568 bytesscott_euser
#60 interdiff-2639382-51-59.txt1.01 KBscott_euser
#59 issue-2639382-translated-timestamp-ago.png72.9 KBscott_euser
#59 issue-2639382-user-interface-translation.png24.04 KBscott_euser
#59 issue-2639382-configuration-translation-of-view.png124.56 KBscott_euser
#51 interdiff-41-51.txt19 bytesDom.
#51 2639382-51.patch1.8 KBDom.
#50 interdiff-41-50.txt2.75 KBmpdonadio
#50 2639382-50.patch1.17 KBmpdonadio
#41 2639382-41.patch2.12 KBidebr
#41 interdiff-38-41.txt1.65 KBidebr
#38 authored_on_string_on-2639382-38.patch2.19 KBgaurav.kapoor
#36 interdiff-2639382-33-36.txt1.21 KByogeshmpawar
#36 authored_on_string_on-2639382-36.patch2.03 KByogeshmpawar
#33 interdiff-2639382-31-33.txt560 bytesyogeshmpawar
#33 authored_on_string_on-2639382-33.patch2.05 KByogeshmpawar
#31 authored_on_string_on-2639382-31.patch1.5 KByogeshmpawar
#28 translate-time-ago-2639382-16.patch1.27 KBstomusic
#25 translate-time-ago-2639382-15.patch1.5 KBstomusic
#18 translate-time-ago-2639382-14.patch1.58 KBstomusic
#16 italian-time-ago.jpg5.39 KBdileepmaurya
#13 translate-time-ago-2639382-13.patch687 bytesdagmar
#9 marathi-time-ago.jpg33.42 KBdineshw
#9 english-time-ago.jpg33.2 KBdineshw
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Pierrere created an issue. See original summary.

dawehner’s picture

This should be config translation, at least its just using the formatter settings for this.

Pierrere’s picture

The config translations seem to be correct, yet I can reproduce the bug on any Drupal 8 installation. When I head over to "String translation" under /admin/config/regional/translate, I can find for the string-contains search "ago":
%time ago -- vor %time
(the simplytest.me page below also shows translations on all other languages for the %time ago string)

Reproducing the error

If someone wants to check themselves, try this:

  1. Run Drupal's official multilingual demo on simplytest.com
    1. Edit the "Trips Grid Page" view - add a time field, for example "Content: Authored on"
    2. Set the formatter of this new field to: "Time ago" and save the changes
    3. Save the view and head back to the homepage
    4. Try switching languages and see how the new time field displays

    Simplytest.me results

    • 32 minutes 2 seconds ago
    • 32 minutos 20 segundos ago
    • 32 minutes 34 secondes ago
    • 32 perc 57 másodperc ago
Pierrere’s picture

Title: "Authored on" string on multilanguage sites not translating » "Authored on" string on multilanguage sites not translating; always renders "ago" for "time ago format"
Version: 8.0.1 » 8.0.3
Pierrere’s picture

Title: "Authored on" string on multilanguage sites not translating; always renders "ago" for "time ago format" » "Authored on" string on multilanguage sites not translating; always renders English "ago" for "time ago" format
jamesliu78’s picture

Status: Active » Needs review
Issue tags: +drupalconasia2016

I try it work.

Setting
Field Content: Authored on
Formatter: Time ago

Display
English: 10 minutes 11 seconds ago
Chinese: 10 分鐘 16 秒 ago

jamesliu78’s picture

Status: Needs review » Needs work

Oh, I got! The "Ago" still here.

dineshw’s picture

Assigned: Unassigned » dineshw
dineshw’s picture

FileSize
33.2 KB
33.42 KB

I too able to test it, "ago" word is still there

jamesliu78’s picture

I can't find the position for render date, is there any possible position? Or possible overwrite way?

"core\modules\views\src\Plugin\views\field\Date.php" not work.
"core\modules\datetime\src\Plugin\Field\FieldFormatter\DateTimeTimeAgoFormatter.php" also tried.

dineshw’s picture

I spot with Gabor, we found the issue needs to make @interval ago to be marked as label in schema iml file.

On top of that, Views has default settings for format, granularity and timestamp
out of which granularity is only available for export config.

Schema change should fix it.

ajithams_zyxware’s picture

It is not translated string. This text coming from settings form. Refer core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php. What to do in this case?

dagmar’s picture

Version: 8.0.3 » 8.2.x-dev
Assigned: dineshw » Unassigned
Status: Needs work » Needs review
Issue tags: -drupalconasia2016 +Needs tests
FileSize
687 bytes

Something like this?

Status: Needs review » Needs work

The last submitted patch, 13: translate-time-ago-2639382-13.patch, failed testing.

dagmar’s picture

Status: Needs work » Needs review

Let's try one more time with the tests.

dileepmaurya’s picture

Status: Needs review » Needs work
FileSize
5.39 KB

I applied patch #13 and still not translating "ago".

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

stomusic’s picture

I think it fix this problem, and clear deprecated functions

dagmar’s picture

Status: Needs work » Needs review
darius.restivan’s picture

Status: Needs review » Reviewed & tested by the community

Tested, the german version of the page shows the english translation for the "authored on".

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This isn't right - configuration is translated using configuration schema. We need to tell the configuration system this is a translatable string and not use t().

Basically...

field.formatter.settings.timestamp_ago:
  type: mapping
  label: 'Timestamp ago display format settings'
  mapping:
    future_format:
      type: string
      label: 'Future format'
    past_format:
      type: string
      label: 'Past format'
    granularity:
      type: integer
      label: 'Granularity'

Needs to change to

field.formatter.settings.timestamp_ago:
  type: mapping
  label: 'Timestamp ago display format settings'
  mapping:
    future_format:
      type: text
      label: 'Future format'
    past_format:
      type: text
      label: 'Past format'
    granularity:
      type: integer
      label: 'Granularity'

IE. the types need to change to 'text' - which will indicate to the configuration system and localize.drupal.org that this is a translatable string.

alexpott’s picture

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php
@@ -187,13 +187,13 @@ protected function formatTimestamp($timestamp) {
+        '#markup' => new FormattableMarkup(t($this->getSetting('past_format')), ['@interval' => $result->getString()]),

Also just fyi... if t() was the right answer here (and it's not) then just using $this->t() instead of FormattableMarkup(t()) would be the way to go... ->t() returns a TranslatableMarkup object which is a markup object like FormattableMarkup and what SafeMarkup::format() returns.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

charginghawk’s picture

I'd just like to note that neither of these work:

    past_format:
      type: text
      label: 'Past format'
    past_format:
      type: string
      label: 'Past format'
      translatable: true

I've tried both ways and the '@interval ago' still refuses to show up in the interface translation.

stomusic’s picture

alexpott #22, thanks. Upd patch

yogeshmpawar’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 25: translate-time-ago-2639382-15.patch, failed testing.

stomusic’s picture

Oops, some went wront.I'm so sorry for it. I download last dev version and renew patch.

yogeshmpawar’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 28: translate-time-ago-2639382-16.patch, failed testing.

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
1.5 KB

Updated patch because previous patch failed to apply.

dagmar’s picture

Status: Needs review » Needs work

@alexpott said this is not the right approach. Please read #21.

yogeshmpawar’s picture

Thanks @dagmar - please review updated patch taking consideration comment #21 & also added interdiff.

yogeshmpawar’s picture

Status: Needs work » Needs review
dagmar’s picture

Status: Needs review » Needs work

@Yogesh Pawar: Thanks, but I think this is not the right approach.

#21 says:

We need to tell the configuration system this is a translatable string and not use t().

Is worth to mention that not use t() also implies not use $this->t() which is the same.

yogeshmpawar’s picture

@dagmar - thanks for your suggestion, i have removed the usage of t() & $this->t(), changes done as per comments #35 & #21

Status: Needs review » Needs work

The last submitted patch, 36: authored_on_string_on-2639382-36.patch, failed testing.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
2.19 KB

Status: Needs review » Needs work

The last submitted patch, 38: authored_on_string_on-2639382-38.patch, failed testing.

Anyeos’s picture

I just do my own work. It is working, you must filter for "@interval ago" and translate that text something like: "hace @interval" (same for "@interval hence").
Not apply other path. I only modified one file from original Drupal 8.3.2 (I don't know if it is already solved in 8.4 dev branch but my solution is simple and clean):

Diff output for the file /core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php

6a7
> use Drupal\Core\StringTranslation\TranslatableMarkup;
97,98c98,99
<       'future_format' => '@interval hence',
<       'past_format' => '@interval ago',
---
>       'future_format' => new TranslatableMarkup('@interval hence'),
>       'past_format' => new TranslatableMarkup('@interval ago'),
nicrodgers’s picture

Patch in #41 applies ok and makes the future_format and past_format translatable.

I couldn't see the 'settings' tab in the views UI for my fields that were using timestamp_ago though, so I was confused at first and thought it wasn't working. However, when I manually edited the .yml files and put this in to the English (primary) language config:

settings:
            granularity: 1
            future_format: '@interval hence'
            past_format: '@interval ago'

then the settings appeared in the Translate View UI.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

BartNijs’s picture

Please help me out here. I've applied the patch in #41. When I go to /admin/config/regional/translate the string "@interval ago" does not show up. Please explain to me step by step what I need to do.

This is what I did:
* apply patch #41
* go to /admin/config/regional/translate and searched for @interval and also for ago. All instances I found were already correctly translated.
* My view still show 38 minuten en 15 seconden ago.

I really need to be able to translate this!

nicrodgers’s picture

@Bartelli, the translation comes from the translated view entity rather than the global interface translation strings. See the comment in #42 - to make it work, I had to manually edit the yml file.

igorski’s picture

@nicrodgers, you comment would be so infinitely more helpful if you could elaborate on the location of “the” yml file.
Thanks!
#33 works for the moment.

Berdir’s picture

  1. +++ b/core/config/schema/core.entity.schema.yml
    @@ -330,10 +330,10 @@ field.formatter.settings.timestamp_ago:
       mapping:
         future_format:
    -      type: string
    +      type: text
           label: 'Future format'
         past_format:
    -      type: string
    +      type: text
           label: 'Past format'
    

    type: label is a one-line translatable string, text is multi-line.

  2. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php
    @@ -187,13 +187,13 @@ protected function formatTimestamp($timestamp) {
           $result = $this->dateFormatter->formatTimeDiffSince($timestamp, $options);
           $build = [
    -        '#markup' => SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $result->getString()]),
    +        '#markup' => new FormattableMarkup($this->getSetting('past_format'), ['@interval' => $result->getString()]),
           ];
    

    This should not be necessary, using the correct schema should automatically make it translatable through config translation.

idebr’s picture

Status: Needs review » Needs work

Settings to 'Needs work' per #48

mpdonadio’s picture

Status: Needs work » Needs review
FileSize
1.17 KB
2.75 KB

#48 should be taken care of, and fixed schema for the datetime version.

Dom.’s picture

@mpdonadio at #50 regarding @berdir #48 did not made it translatable to me. Neither did #41.

I had to do the following (patch attached) to get it translated.

Berdir’s picture

Status: Needs review » Needs work

This is wrong and not secure. The value of that setting will then not be escaped and can contain anything, including javascript.

The change isn't meant to make it translatable through interface translation but configuration translation. The problem is that formatter/widget settings aren't properly exposed in config translation, there's an old issue about that.

charginghawk’s picture

@berdir, is this the issue you're referring to? #2546212: Entity view/form mode formatter/widget settings have no translation UI

If so, then theoretically, the latest patch from ^^ that issue, combined with the patch from #50, should resolve the issue satisfactorily.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cestmoi’s picture

@charginghawk I tried your suggestion in your last comment and didn't work for me (D 8.6.1). I applied the two patches and still couldn't find a place to translate "ago"

cestmoi’s picture

As per @Berdir 's comment #48, I applied the change in core.entity.schema.yml (string > text) and the TimestampAgoFormatter.php was already changed in core but that didn't make any difference either. The field is still untranslatable

UPDATE: I tried as per comment #42 by @nicrodgers, edited the views.view.content_recent.yml for the Recent Content view e.g. and still no luck !

On a side note: I'm not a programmer but, having seen how long this issue has been on table, I'm shocked that such a tiny "thing" takes so long (years) or is so complicated to get fixed !

manuel.adan’s picture

In the mean time a custom field formatter can solve it. The following just print the translated time ago (past) format. For newbies, copy and paste into a custom module field formatters folder, such as "www/modules/custom/custom_module/src/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php"

<?php

namespace Drupal\custom_module\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampAgoFormatter as CoreTimestampAgoFormatter;
use Drupal\Core\Cache\CacheableMetadata;

/**
 * Custom plugin implementation of the 'timestamp' formatter as time ago.
 *
 * @FieldFormatter(
 *   id = "custom_module_timestamp_ago",
 *   label = @Translation("Time ago (custom)"),
 *   field_types = {
 *     "timestamp",
 *     "created",
 *     "changed",
 *   }
 * )
 */
class TimestampAgoFormatter extends CoreTimestampAgoFormatter {

  /**
   * Formats a timestamp.
   *
   * @param int $timestamp
   *   A UNIX timestamp to format.
   *
   * @return array
   *   The formatted timestamp string using the past or future format setting.
   */
  protected function formatTimestamp($timestamp) {
    if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
      $granularity = $this->getSetting('granularity');
      $options = [
        'granularity' => $granularity,
        'return_as_object' => TRUE,
      ];
      $result = $this->dateFormatter->formatTimeDiffSince($timestamp, $options);
      $build = [
        '#markup' => $this->t('%time ago', ['%time' => $result->getString()]),
      ];
      CacheableMetadata::createFromObject($result)->applyTo($build);
    }
    else {
      $build = parent::formatTimestamp($timestamp);
    }

    return $build;
  }

}
redseujac’s picture

Drupal 8.6.7

Applying manually the patch to the two schema.yml files as in #50 mpdonadio (2639382-50 patch) is working for me now.

Those 2 files are:

  • core/config/schema/core.entity.schema.yml
  • core/modules/datetime/config/schema/datetime.schema.yml

The "problem" could be easily fixed for the next Drupal update.

You only have to replace the word "string" with "label" under the "type" of "future_format" and "past_format" in both files mentioned above. Done!

Nothing has to be changed in the file core/lib/Drupal/Core/Field/Plugin/FieldFormatter/TimestampAgoFormatter.php, because the necessary changes are already made in that file.

scott_euser’s picture

Thank you @alexpott for the advice on this. Updated patch with the config update only as the change to the TimestampAgoFormatter is not actually necessary. Removing 'needs tests' as tests are no longer needed when just schema change.

Steps to translate successfully with just the schema change:

1. Add the second language (I added Dutch)

2. Translate configuration of '1 second', '@count seconds', '1 minute', '@count minutes', etc in Interface Translation:
screenshot of interface translation

3. Translate configuration of view (to translate the 'ago') via Configuration Translation > View > Your View:
screenshot of configuration translation of view

And the end result, fully translated string:
screenshot of configuration translation of view

If you wanted to shift works around, like moving the 'ago' infront of the interval, that can be done in the the Configuration Translation of the view like 'Ago @interval' and if you would want to move the word 'second' infront of the number for instance, that could be done in the Interface Translation like 'second 1' and 'seconds @count', so I believe all situations are covered by this but good to get input from others. In any case, we have more translation flexibility then before with this patch.

scott_euser’s picture

scott_euser’s picture

manuel.adan’s picture

#60 works for date field in views, but not for regular field display. Even with #2546212-93: Entity view/form mode formatter/widget settings have no translation UI, date formatter settings can not be translated due to a similar issue in the datetime module. This issue is assigned to the views.module component, so the patch is OK and a new issue should be added for the same thing but in datetime module.

scott_euser’s picture

@manuel.adan It should also be translatable. I am not sure where to find it in the UI, but with the patch applied, if I do this:

  1. Add a field 'field_timestamp' to 'page' node type
  2. Set manage display for the field to 'time ago'
  3. Run `config-export`
  4. Copy `/path/to/config/sync/core.entity_view_display.node.page.default.yml` to `/path/to/config/sync/language/nl/core.entity_view_display.node.page.default.yml` (for example for Dutch)
  5. Edit the latter config to be '@interval geleden' instead of '@interval ago'

I then get this on the front-end (ie, correctly translated):

Front-end showing timestamp ago correctly fully translated

mpdonadio’s picture

One place was overlooked.

manuel.adan’s picture

#63, it works with timestamp field type, not datetime. #64 patch solves it for datetime, but as previously mentioned, not sure if a new issue should be added since it is a different component.

mpdonadio’s picture

I have no issue fixing both here.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mpp’s picture

Status: Needs review » Reviewed & tested by the community

Glad to see this fixed properly :-)

idebr’s picture

Closed #3071897: Time ago formatter untranslatable as a duplicate issue.

larowlan’s picture

+++ b/core/config/schema/core.entity.schema.yml
@@ -337,10 +337,10 @@ field.formatter.settings.timestamp_ago:
-      type: string
+      type: label

Does this need an empty update /post update hook to trigger a cache clear?

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

For #70

mpp’s picture

Status: Needs review » Reviewed & tested by the community

@larowan, I've seen many of these patches but none of them performs a cache clear. I suppose a cache clear is part of most deploy scripts.

idebr’s picture

#72 Can you find a link to a similar issue? It would be interesting to see the discussion / consideration in earlier issues.

In this case Drupal will still be functional without a cache rebuild, unlike adding a new argument to a class constructor for example. I agree we can probably do without.

mpp’s picture

mpp’s picture

Since a lot of developers don't seem to be aware of the type: label shorthand, I also updated the documentation for the translatable property here:
https://www.drupal.org/docs/8/api/configuration-api/configuration-schema...

idebr’s picture

#74 Cheers, #3063020: Support translation of the list of styles in CKEditor seems a good reference for leaving out an empty post_update hook. RTBC+1

Wim Leers’s picture

@mpp+++++++ for #75!

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Thanks, I looked at those issues and you're correct, there's no update hook - but should we be adding a test here? We would ordinarily require a test for a bugfix.

topology’s picture

translating something according to its content is already a complication issue. keeping that in mind, the translation mechanism is already highly customizable, and one solution does not have to fit all. At least I am getting well with languages with right to left direction, like Arabic and Hebrew.

In the case of the time format in some common areas, like: "Submitted by...", In case that is not already translated or you are not satisfied with it, you can translate that by going to:
admin/config/regional/translate , and searching there for the "Submitted by" , Remember this is a case sensitive search. Also pick language you are translating for in the "translation language" field and pick "both translated and untranslated strings" in the "Search in field"; just in case you want to change already translated string to something else.
Most likely the following string will pop up:
Submitted by @author_name on @date

In the target language (in my case it is of direction right to left, otherwise the order is the same) , either type your intended translation in the order of your typing without keeping attention how it looks ,it will look messy but Drupal render it correctly later on according to the language, or else change the direction of typing (In firefox Ctr-Shift+X, in Chrome Left-Click> Writing Direction> RTL)and view what you are typing. Place @author_name and @date where they should fit in that language.

In some languages Day and Hour (and many contextual form of that) might be already translated while others (like Seconds and Minutes) are not yet. In that case, just type for instance "second" in case that is missing, and translate it in a way similar to the case of "hour" while keeping the syntax of the language as correct as possible. Just use the word @count as is.

If all that is already done, the only place where i was using Time Ago format was in the Views, in a place like "Authored On" Field.
If I create a View for something, and by adding for instance an "Authored on" field, I got away with following:

First I chose the format, by editing View>View-To-Edit>Edit>Field(Here "Authored on").
In the settings of that Field ("Authored on"), I change the label to "Authored since". But when translating I will do with more relevant sentence. Keeping in mind that the answer in time in English is like: 2days 4hours, and with an answer similar in the other language.
In the Formatter I will keep Time Ago, in the Future format I replace @interval hence with @interval and in Past format I change @interval ago to just @interval.
The problem with "ago" translation emerges here when trying to to search for "ago" string in the previous method; among the results of that search is that %time ago , but translating that has no effect on the view here.
The only solution I could find was translating and changing "Authored on" title accordingly as I said, in the View area; View>Translate(tab) and then opening all the collapsed titles translating that "Authored on" Title to something meaningful.
The end result in View is like: (lets say in French)
Title: "Publie depuis" , Date: 2jours 4heurs. While in English: Tilte:"Published since" , Date: 2days 4hours.
As you can see, the translation and the way I did things won't let me keep the "ago" word for the English version wihile hiding it from the French one..

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Abdelrahman Amer’s picture

This patch for 8.9 and it works for me.

Abdelrahman Amer’s picture

This is for 9.1

Coops_’s picture

Confirming #64 works great for me. As the discussion above states, this should be handled as configuration translation, rather than UI.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

dgaspara’s picture

Works for me. Thanks!

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mohit_aghera’s picture

I think the patch #64 from @mpdonadio is the correct approach.
I've uploaded the patch with the test cases.

I've taken interdiff with that patch only.
For now, I'm keeping the needs tests tag as I need some inputs on whether this test is sufficient or not.

Status: Needs review » Needs work

The last submitted patch, 88: test-only-2639382-88.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review
Lendude’s picture

Priority: Minor » Normal
Status: Needs review » Needs work

Looking really good!

Mostly just some comment nitpicks/suggestions. But we should expand the test to cover the future format change too.

  1. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
    @@ -60,4 +64,43 @@ public function testTranslateOperationInViewListUi() {
    +    // Update view to set the field formatter.
    

    Update the view ....

  2. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
    @@ -60,4 +64,43 @@ public function testTranslateOperationInViewListUi() {
    +    // Add the views translation.
    

    "Add a translation to the views configuration for the past and future formats."

  3. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
    @@ -60,4 +64,43 @@ public function testTranslateOperationInViewListUi() {
    +      'translation[config_names][views.view.content][display][default][display_options][fields][changed][settings][future_format]' => '@interval hence',
    

    We should also add a test for the future format change

  4. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
    @@ -60,4 +64,43 @@ public function testTranslateOperationInViewListUi() {
    +    // Create one past time stamp, so we can update node's updated field.
    
    index a00901160b..44783bdbef 100644
    --- a/core/modules/datetime/config/schema/datetime.schema.yml
    

    "Create a timestamp just over an hour in the past and set the nodes update time to this."

  5. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
    @@ -60,4 +64,43 @@ public function testTranslateOperationInViewListUi() {
    +    // Translation of "hour" string is english only, as all the strings'
    +    // translations are not uploaded.
    

    "Not all normal string translations are available, so 'hour' is still in English."

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
4.46 KB
2.56 KB

Addressing all 5 suggestions mentioned in the comment #91

Lendude’s picture

Issue tags: -Needs tests

Nice, just some nits left

  1. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
    @@ -60,4 +64,56 @@ public function testTranslateOperationInViewListUi() {
    +      'future_format' => '@interval hence',
    ...
    +      'translation[config_names][views.view.content][display][default][display_options][fields][changed][settings][future_format]' => '@interval hence',
    ...
    +    $this->assertSession()->pageTextContains('1 hour hence');
    

    Can we make the translation be something else then the English version?

  2. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
    @@ -60,4 +64,56 @@ public function testTranslateOperationInViewListUi() {
    +    // Create a timestamp just over an hour in the future and set the nodes update
    +    // time to this.
    

    Dreditor indicates this is over 80 characters but that might not be true, it's been wrong before I think....

mohit_aghera’s picture

Fixing few more suggestions from #93

The last submitted patch, 92: 2639382-92.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 94: 2639382-94.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review
Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me now, thanks!

Lendude’s picture

Issue summary: View changes

Updated the IS to mention the proposed fix and the discussion on having an update or not.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Fixing issue credit - which is now correct as far as I can see.

@mohit_aghera please add all the schema changes from #64 here. Yes the datetime ones might not be tested but fixing one without the other makes no sense. Once the changes that were removed from #64 you can re-rtbc the patch.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

@Lendude pointed out that the datetime schema stuff is there. Nice....

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 117168a and pushed to 9.3.x. Thanks!

diff --git a/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
index fb8f779905..c8bae85e9f 100644
--- a/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
+++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
@@ -6,6 +6,8 @@
 use Drupal\Tests\views_ui\Functional\UITestBase;
 use Drupal\views\Views;
 
+// cspell:ignore später
+
 /**
  * Visit view list and test if translate is available.
  *

Let's inline the addition to the dictionary. Fix on commit.

  • alexpott committed 117168a on 9.3.x
    Issue #2639382 by mohit_aghera, yogeshmpawar, stomusic, mpdonadio,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.