Skip to content

default_locale from translation.php has no effect on Twig when started from CLI #42503

Closed
@ThomasLandauer

Description

@ThomasLandauer

Symfony version(s) affected: 5.3.6

Description
When started from a Console Command, Twig's format_datetime() filter is not respecting default_locale from translation.php

How to reproduce
translation.php:

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension('framework', [
        'default_locale' => 'de',
        'translator' => [
            'enabled'         => true,
            'logging'         => false,
            'enabled_locales' => ['en', 'de'],
        ],
    ]);
};

Template:

{{ date()|format_datetime(pattern="ccc") }}

If I output this from a controller with return $this->render('locale.html.twig');, I'm getting:

Do

=> fine!

However, if I output it from a console command with $output->writeln($this->twig->render('locale.html.twig'));, I'm getting:

Thu

=> not fine :-(

In my fpm/php.ini I have:

intl.default_locale = de_AT.UTF-8

I didn't have that in my cli/php.ini. I "fixed" the issue by adding it there too.

So the question is: Why does default_locale not have any effect in CLI? If that's the expected behavior, it should be explained at https://symfony.com/doc/current/reference/configuration/framework.html#default-locale

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions