php – NumberFormatter :: SPELLOUT spellout-ordinal in Russian and italian

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – NumberFormatter :: SPELLOUT spellout-ordinal in Russian and italian脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这段代码适用于英语,西班牙语和德语的ordninal数字,但俄语或意大利语的号码不起作用.

‘ru-RU’,’it-IT’也行不通

我用俄语获得2 – > два(这是基数),但我想要序数,这将是2 – > второй.

我在意大利语中得到2 – >到期(这是基数),这将是2 – > SECONDO.

更新:

我找到了一个法语,西班牙语,德语和其他语言的解决方案:

maskuline序数:%spellout-ordinal-maskuline

女性序数:%spellout-ordinal-feminine

俄语和意大利语版本不起作用,我已经尝试使用-maskuline / -feminine

$ru_ordinal = new NumberFormatter('ru',NumberFormatter::SPELLOUT);
$ru_ordinal->setTextAttribute(NumberFormatter::DEFAULT_RULESET,"%spellout-ordinal");
NumberFormatter正在使用ICU格式.

你可以在这里查看:http://saxonica.com/html/documentation/extensibility/config-extend/localizing/ICU-numbering-dates/ICU-numbering.html

…俄语(ru)有以下格式:

> spellout-cardinal-feminine(scf)
> spellout-cardinal-masculine(scm)
> spellout-cardinal-neuter(scne)
>拼写编号(sn)
> spellout-numbering-year(sny)

……和意大利语(它):

> spellout-cardinal-feminine(scf)
> spellout-cardinal-masculine(scm)
>拼写编号(sn)
> spellout-numbering-year(sny)
> spellout-ordinal-feminine(sof)
> spellout-ordinal-masculine(som)

这就是为什么你将无法为(ru)和以下代码设置序数格式的原因:

$nFormat = new NumberFormatter('it',NumberFormatter::SPELLOUT);
$nFormat->setTextAttribute(NumberFormatter::DEFAULT_RULESET,"%spellout-ordinal-feminine");

var_dump($nFormat->format(42));

将打印:

string 'quaranta­duesima' (length=17)

像你(可能)想要的.

编辑:

有关二手格式的信息,参考ICU:http://php.net/manual/en/numberformatter.create.php

使用PHP 5.4.x和ICU版本=>进行测试51.2; ICU数据版本=> 51.2.
你可以使用shell命令:

$PHP -i | grep ICU

检查您的ICU版本.

对于最新的ICU版本,您应该可以安装/更新PHP-intl软件包:http://php.net/manual/en/intl.installation.php

编辑2:

我已经为NumberFormatter创建了扩展(到目前为止已经有了抛光序数).欢迎提供其他语言:https://github.com/arius86/number-formatter

脚本宝典总结

以上是脚本宝典为你收集整理的php – NumberFormatter :: SPELLOUT spellout-ordinal in Russian and italian全部内容,希望文章能够帮你解决php – NumberFormatter :: SPELLOUT spellout-ordinal in Russian and italian所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: