Home > OS >  How to translate the content with Symfony?
How to translate the content with Symfony?

Time:09-16

I try to translate dates in French. I succeeded to have the right format, but the month is in English.

I have this in config/packages/translation.yaml :

framework:
    default_locale: fr
    translator:
        default_path: '%kernel.project_dir%/translations'
        fallbacks:
            - fr

And I created forms.fr.yaml in translations fold :

Jan: Janvier
Feb: Février
Mar: Mars
Apr: Avril
May: Mai
Jun: Juin
Jul: Juillet
Aug: Août
Sep: Septembre
Oct: Octobre
Nov: Novembre
Dec: Décembre

At the moment, it doesn't work. What did I miss ?

Thank you for your help.

CodePudding user response:

You can use format_date adn/or format_datetime filter from twig

Like

{{ '2019-08-07 23:39:12'|format_datetime('full', 'full', locale='fr') }}
{# or #}
{{ myDateVariable|format_datetime('short', 'short') }}
{# or #}
{{ date('now')|format_date('medium', locale='de')

Take a look at the docs https://twig.symfony.com/doc/3.x/filters/format_datetime.html

You can specify your own format-pattern.

Note: In order to use it, you'll need twig/intl-extra and twig/extra-bundle

  • Related