Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I would like to have possibility setup enabledLocales via env variables but i get an error. Is it possible to solve this problem?

.env file

DEFAULT_LOCALE='en'
AVAILABLE_LOCALES="[\"en\", \"sk\", \"cs\", \"de\", \"uk\"]"

configuration file

    $framework
        ->defaultLocale(env('DEFAULT_LOCALE'))
        ->enabledLocales(env('json:AVAILABLE_LOCALES'))
        ->translator()
        ->defaultPath('%kernel.project_dir%/translations')
        ->fallbacks(['en']);

Error

Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension::registerTranslatorConfiguration(): Argument #5 ($enabledLocales) must be of type array, string given, called in /var/www/html/vendor/symfony/framework-bundle/DependencyInjection/FrameworkExtension.php on line 377

You must be logged in to vote

Replies: 1 comment · 2 replies

Comment options

The list of enabled locales is currently required during the compilation:
For the routing:

if ($enabledLocales) {
$enabledLocales = implode('|', array_map('preg_quote', $enabledLocales));
$container->getDefinition('routing.loader')->replaceArgument(2, ['_locale' => $enabledLocales]);
}

To configure the translators:

$locales = $enabledLocales;
foreach ($config['providers'] as $provider) {
if ($provider['locales']) {
$locales += $provider['locales'];
}
}
$locales = array_unique($locales);
$container->getDefinition('console.command.translation_pull')
->replaceArgument(4, array_merge($transPaths, [$config['default_path']]))
->replaceArgument(5, $locales)
;
$container->getDefinition('console.command.translation_push')
->replaceArgument(2, array_merge($transPaths, [$config['default_path']]))
->replaceArgument(3, $locales)
;
$container->getDefinition('translation.provider_collection_factory')
->replaceArgument(1, $locales)
;

I think we can convert update the code so that the manipulations are compiled into the dumped container to be executed at runtime.

You must be logged in to vote
2 replies
@sveneld
Comment options

It will be great. Thanks. Should I create an issue for this?

@GromNaN
Comment options

GromNaN Sep 14, 2025
Collaborator

On further reflection, I realize that the routing is compiled into the cache anyway. It would therefore be necessary to clear the cache if the value of this environment variable changes.

You can try opening a PR to call $container->resolveEnvPlaceholders($config['enabled_locales']) to resolve the env var before using it.

This PR must target the branch 7.4 and test should be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.