Problem/Motivation
I'm trying to render a node with a certain language, I'd like to make sure every part of the rendered node is displayed with the given langcode. My problem is that the SmartDateDefaultFormatter does not pass the langcode value to the date formatter service `format()` method, which causes that the smart date fields always rendered with the current interface language. The SmartDateDefaultFormatter receives the $langcode parameter from Drupal's field formatter but never passes it to SmartDateTrait::formatSmartDate() or any of its helper methods. As a result, every call to \Drupal::service('date.formatter')->format() omits the $langcode argument, causing dates to always render in the current interface language.
Steps to reproduce
Create a content entity with a Smart Date field, add at least one date value, then render that entity in a language different from the current interface language (e.g. render a hu node while the UI language is en). The formatted date output — including day names, month names, and AM/PM strings — appears in the interface language instead of the entity's language.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | Formatter-ignores-langcode-QA-2.png | 37.52 KB | dkmishra |
| #4 | Formatter-ignores-langcode-QA-1.png | 40.23 KB | dkmishra |
Issue fork smart_date-3592521
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
tikaszvince commentedComment #4
dkmishra commented@tikaszvince Thanks, I have tested it, and it looks fine to me. One thing I would like to point out is that when the date is displayed in a format like “Fri, May 29, 2026, All day”, the “All day” text is not translated into the selected language. I understand that “All day” is not part of the date format itself, but it should still be translated according to the selected language. Please see the screenshots.
Comment #5
tikaszvince commented@dkmishra looks like my changes has effect only on the date formatter calls, but other translated elements still using the "currentLanguage". My current workaround is a
hook_entity_preprare_viewwhich is "reconfigure" the current language before rendering my nodes. This is "works for me" but its not a stable solution.