该代码适用于英语,西类牙语和德语序号,但对于俄语或意大利语序号则无效。
'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)具有以下可用格式:

  • 拼写出来的基数女性(scf)
  • 拼写输出基数男性(scm)
  • 咒语-基数中性(scne)
  • 拼写编号(sn)
  • 拼写编号年(sny)

  • ...和意大利语(it):
  • 拼写出来的基数女性(scf)
  • 拼写输出基数男性(scm)
  • 拼写编号(sn)
  • 拼写编号年(sny)
  • 拼写-普通女性(sof)
  • 拼写输入法-男性(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拼写普通-俄语和意大利语,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24282324/

    10-14 13:02