Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dasbrow's avatar

Invalid locale en_US, de, etc.

I am adding other languages to our software, which works fine on my development machine, but on our test server we get the following error. I can't seem to figure out way? Google does not seem to be helping in this matter. I've tried to remove all but English from resources/lang, yet the message below remains the same.

removing \App::setLocale(\Request::server('HTTP_ACCEPT_LANGUAGE')); from my middleware helps, but I would like to know why it's working on my dev system only.

Invalid \"en_US,en;q=0.9,de;q=0.8,fr_FR;q=0.7,fr;q=0.6,pt;q=0.5\" locale. at /data/nginx/reminded_gaass/vendor/symfony/translation/Translator.php:441
1 like
6 replies
tisuchi's avatar

@dasbrow If I am not mistaken, this is the right way:

+'locale' => 'en', // Correct
- 'locale' => 'en-US', // Incorrect

This means, setting the locale to a supported format in your config/app.php file. Here is the full picture:

'locale' => 'en',

// Other code...
1 like
dasbrow's avatar

@tisuchi That's the issue, my locale is set to 'en' - I don't know where the system is pick up en-US or

That's how it's already set.

1 like
tisuchi's avatar

@dasbrow hmm... what you are getting when you do this in the tinker?

dd(App::getLocale()); 

Check if it is en or en-US?

1 like
dasbrow's avatar

@tisuchi Applogizes for the delayed response

dd(App::getLocale());

returns 'en'

Upon further testing, if I set the locale in google dev tools, under sensors, everything works, set to en, english, set to fr, french works. etc. Only if I don't over ride the settings does this error happen.

2 likes
martinbean's avatar
Level 80

@dasbrow The Request class has a method for parsing the preferred language from an Accept-Language HTTP header:

App::setLocale($request->getPreferredLanguage());

This would parse fr_CH from fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5 for example.

2 likes
dasbrow's avatar

@martinbean Thanks You! I knew I should have dig into other options and didn't

1 like

Please or to participate in this conversation.