Ivan Triviño
Ivan Triviño

Reputation: 51

Symfony 4: You have requested a non-existent parameter "locale"

When I enable the 'dev' mode in my Symfony 4 app (that is already online in a shared hosting service) it shows this message:

(1/1) ParameterNotFoundException
You have requested a non-existent parameter "locale".

in ParameterBag.php (line 100)
at ParameterBag->get('locale')
in EnvPlaceholderParameterBag.php (line 57)
at EnvPlaceholderParameterBag->get('locale')
in ParameterBag.php (line 216)
at ParameterBag->resolveString('%locale%', array('locale' => true))
in ParameterBag.php (line 187)
...

and does not allow to debug the app. My config/services.yml code is as default:

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: 'en'

services:
    # default configuration for Services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your Services.
        autoconfigure: true # Automatically registers your Services as commands, event subscribers, etc.
        public: false       # Allows optimizing the container by removing unused Services; this also means
                            # fetching Services directly from the container via $container->get() won't work.
                            # The best practice is to be explicit about your dependencies anyway.
...

Please, someone can help me to fix this error.

Upvotes: 5

Views: 12366

Answers (3)

Steven
Steven

Reputation: 1

When upgrading from symfony 4.2 to symfony 4.4 I also got this error when composer commands.

This parameter seems so be used in config/packages/translation.yml. Updating the symfony/translation recipe which no longer refers to %locale% but hardcode 'en' solves the problem for me.

Simply run composer recipes:install symfony/translation --force -v

Upvotes: 0

MilanG
MilanG

Reputation: 7114

Had the same problem during the fresh symfony 4.3 + sonata admin bundle installation. As a solution I added locale parameter:

// /config/services.yaml

parameters:
    locale: 'en' 

Upvotes: 10

Andrew Cotton
Andrew Cotton

Reputation: 425

While I am not a Symphony expert the documentation appears to allow anything in the parameters section, but it does mention also defining the values in the .env.dist file as well for them to be used here.

http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters

Upvotes: 2

Related Questions