gpt4 book ai didi

PHP NumberFormatter 总是给我默认的 en_US

转载 作者:行者123 更新时间:2023-12-05 03:17:56 29 4
gpt4 key购买 nike

当尝试在我的 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。

也欢迎提供有关编写更好问题的任何提示。

最佳答案

除了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

正如预期的那样。

关于PHP NumberFormatter 总是给我默认的 en_US,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73895691/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com