Translating i18nDateTimeInterface::diffForHumans

Is there a way to translate the result of the method diffForHumans() to another language on CakePHP 4.3? I’ve been searching and found this:

So this is what I’ve done

  1. bin/cake i18n extract --extract-core yes
  2. Modified cake.pot and moved it into resources/locale/es/cake.po
  3. bin/cake schema_cache clear
  4. i18n::setLocale(‘es_AR’);
  5. echo $record-timestamp->diffForHumans();
  6. Also created a new instance of RelativeTimeFormatter and used diffForHumans

Now, some translations are working as expected, like:

#: ./vendor/cakephp/cakephp/src/Validation/Validator.php:2559
#: ./vendor/cakephp/cakephp/src/View/Form/ArrayContext.php:249
msgid “This field cannot be left empty”
msgstr “Debe completar este campo”

But everything about RelativeTimeFormatter is not:

#: ./vendor/cakephp/cakephp/src/I18n/RelativeTimeFormatter.php:78
#: ./vendor/cakephp/cakephp/src/I18n/RelativeTimeFormatter.php:150
msgid “{0} second”
msgid_plural “{0} seconds”
msgstr[0] “{0} segundo”
msgstr[1] “{0} segundos”

Am I missing something? thanks in advance!

Translations are cached under tmp/cache/persistent, did you clear those too?

Yes I did. I’m not sure what’s happening

Some more dumb questions…

Do you also have resources/locale/es_AR/cake.po without the time translations in it?

Do you have the translations for all the things other than seconds in your file, just not shown here? :wink:

  • I don’t have a resources/locale/es_AR/cake.po file, only a resources/locale/es/cake.po file.
  • My file it is not fully translated. But as I said in the first post, translations that don’t belong to RelativeTimeFormatter are working as expected.
  • Also found this but it is not working neither.

Thanks for all your help!

Well, remember that Cake code is still all just PHP, so you can debug it the same as you debug your own code. xdebug is your friend!