shopware icon indicating copy to clipboard operation
shopware copied to clipboard

Locale validation fails when no PHP default locale is set in `intl.default_locale`

Open aragon999 opened this issue 2 months ago • 1 comments

Shopware Version

trunk

Affected area / extension

Platform(Default)

Actual behaviour

Commands which need the TranslationConfigService fail if the PHP setting intl.default_locale is not set (which is the default): Image

The reason is, that the locales are validated here: https://github.com/shopware/shopware/blob/trunk/src/Core/System/Snippet/DataTransfer/Language/Language.php#L22-L32

However if no locale is passed, which is the case for the Symfony\Component\Intl\Locales::exists() method: https://github.com/symfony/symfony/blob/7.4/src/Symfony/Component/Intl/Locales.php#L42-L48

Symfony falls back to the \Locale::getDefault() locale: https://github.com/symfony/symfony/blob/7.4/src/Symfony/Component/Intl/ResourceBundle.php#L58

Which is empty, and then leads to an error: Image

Note that this only happens on the CLI, as in the web the default locale is set.

Furthermore I am not sure how to solve it, i.e. if this is an error in Symfony itself, or if on CLI commands a default locale should be set. Hence I am happy to hear your feedback, how to solve it, then I will take care.

Expected behaviour

Do not fail, if the default php.ini settings are used.

How to reproduce

For example try to generate an export, with the default PHP setting for intl.default_locale. But the same error also occurs when one tries to generate demodata and probably more commands.

aragon999 avatar Oct 17 '25 13:10 aragon999

Hey @aragon999, see the linked PR, i hope i found a fix that worked around the issue, however best would be if you could report the issue upstream to symfony, maybe the fix i did is valid for their exists() check as well.

On another note i was not able to reproduce your issue in any way, and according to php manual Locale::getDefault should fall back to ICU default

At the PHP initialization this value is set to 'intl.default_locale' value from php.ini if that value exists or from ICU's function uloc_getDefault().

https://www.php.net/manual/en/locale.getdefault.php

i assume the case you are running into is some kind of edge case 🤷

keulinho avatar Dec 08 '25 16:12 keulinho