Twig\Error\RuntimeError: The date format "html_date" does not exist

Created on 5 February 2024, 11 months ago
Updated 8 September 2024, 4 months ago

Problem/Motivation

I get

Twig\Error\RuntimeError: The date format "html_date" does not exist, known formats are: "none", "short", "medium", "long", "full", "relative_short", "relative_medium", "relative_long", "relative_full". in Twig\Extra\Intl\IntlExtension->createDateFormatter() (line 37 of core/modules/locale/templates/locale-translation-update-info.html.twig).

when running translation updates at
/admin/reports/translations

Reason unclear

Steps to reproduce

Open /admin/reports/translations

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    The interesting thing is, that there even is a Drupal date format "html_date" on that page, so this can't be what's ment by this error?

  • 🇩🇪Germany Anybody Porta Westfalica

    Seems like this module conflicts with the Drupal core "format_date" twig filter from

    new TwigFilter('format_date', [$this->dateFormatter, 'format']),
    

    Drupal\Core\Template\TwigExtension.

    Houston we have a problem...

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇮🇳India arunkumark Coimbatore

    @Anybody

    I hope the issue is not with the Drupal core format_date() twig extension. Till TWIG version 2.12 the format_date() is part of default. But on TWIG version >2.12 and 3.x version, format_date() extension is removed from the default and added into the IntlExtension. The IntlExtension needs to be installed separately to access the additional extensions.

    https://twig.symfony.com/doc/2.x/filters/format_date.html
    https://twig.symfony.com/doc/3.x/filters/format_date.html

    If Twig IntlExtension needs to work fine with Drupal core means, we can extend the TwigExtension.php from the path Drupal\Core\Template\TwigExtension.php.

    My reply about the patch on Drupal core available on this comment 🐛 Custom Core Twig Filter "format_date" conflicts with twig/intl-extra Active
    https://www.drupal.org/project/drupal/issues/3419294#comment-15694037 🐛 Custom Core Twig Filter "format_date" conflicts with twig/intl-extra Active

  • 🇩🇪Germany gogowitsch

    If you are using a custom theme, you can fix it by copying the template file locale-translation-update-info.html.twig from core to the templates directory of your theme.

    Within the <li> tag, you can change the param of format_date, for example to this: format_date('short'). This will circumvent the error.

    I have attached a patch file to make the necessary fix a little bit clearer. If you are using a theme managed by composer, then the "cweagans/composer-patches" plugin can prevent losing the manual change. Add these lines to your composer.json file, within the "extra" section:

            "patches": {
                "drupal/core": [{
                    "description": "https://www.drupal.org/project/twig_intl/issues/3419285",
                    "url": "locale-translation-update-info.html.twig.patch"
                }]
            },

    Then, you can run composer require cweagans/composer-patches:~2.0 && composer patches-relock && composer patches-repatch.

Production build 0.71.5 2024