當嘗試在我的 PHP 8.1 alpine docker 容器中格式化貨幣時,我總是得到默認的語言環境(en_US)。
$ docker run -it --rm php:8.1-fpm-alpine /bin/ash
# apk update && apk add icu-dev
# docker-php-ext-configure intl && docker-php-ext-install intl
# php -a
> $formatter = new NumberFormatter('nl_NL', NumberFormatter::CURRENCY);
> echo $formatter->getLocale();
en_US
> echo $formatter->format(1234.567);
€1,234.57
我希望 getLocale() 回傳 nl_NL 并格式化回傳 €1.234,57。
如果我嘗試使用語言環境 en_GB,getLocale() 會回傳 en_GB。
也歡迎任何有關撰寫更好問題的提示。
uj5u.com熱心網友回復:
除了icu-dev包,還要安裝icu-data-full包。默認情況下,僅icu-data-en安裝,其中包含您所看到的美式和英式英語,但沒有荷蘭語。
拆分是在Alpine 3.16.0中引入的,可能是為了節省空間:整個安裝包重約 29 MB,與影像的其余部分相比很大。
安裝完整資料后,您的示例給出
php > echo $formatter->getLocale();
nl_NL
php > echo $formatter->format(1234.567);
€ 1.234,57
正如預期的那樣。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/510481.html
