New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatter asShortWeight method throws unexpected errors with some locales #19744
Comments
What happens if you try for
Still same error? |
$formatter = new Formatter([
'locale' => 'de',
]);
$result = $formatter->asShortWeight(round(5 / 1000, 2)); This gives the same error I get with
|
The reason here is that keys for Then formatter returns empty message which results in improperly formatted message This might be ICU issue, but it's strange since DE is commonly used locale. Other less often used langs have those definitions, e.g. SK, CS, HU, .. But for example PL is also missing those keys. |
@lubosdz Thanks for the information! Yes, I was also surprised to see this issue, felt unlikely that I'd be the first to stumble upon this. But if it's an issue with the ICU data, maybe it needs to be changed there? Or maybe Yii2 can provide a wrapper / fallback in this case? |
@MoritzLost |
I would just wait for the ICU fix to be honest. This looks really weird and I would be surprised if it was not fixed quickly when reported. |
@lubosdz Thanks for the suggestion, we're now using Could one of you report this bug in the ICU repository? I don't understand the ICU data structure well enough to be able to provide accurate information on what exactly is missing here. |
What steps will reproduce the problem?
I'm having trouble with the
asShortWeight
method of the formatter. This works as expected for some locales, but throws errors for others (in particular,de
).What is the expected result?
The examples above should output
5 kg
,5 g
and5 tn
, respectively. They do that if I use theen
locale as well as some others I tested. However, with thede
locale and some others as well, I get errors.What do you get instead?
Different errors depending on the order of magnitude of the input:
Surprisingly, this does work (it returns
5 tn. sh.
):Additional info
Not sure if this is an error with Yii or with my environment. I'm using PHP 8.2 installed through homebrew, which comes with the intl extension and an up-to-date version of the ICU data.
The text was updated successfully, but these errors were encountered: