NumberFormatter::SPELLOUT spellout-ordinal in russian and italian

六月ゝ 毕业季﹏ 提交于 2019-12-03 13:06:04

NumberFormatter is using ICU formatting.

As you can check here: http://saxonica.com/html/documentation/extensibility/config-extend/localizing/ICU-numbering-dates/ICU-numbering.html

... Russian (ru) has following formatting available:

  • spellout-cardinal-feminine (scf)
  • spellout-cardinal-masculine (scm)
  • spellout-cardinal-neuter (scne)
  • spellout-numbering (sn)
  • spellout-numbering-year (sny)

... and Italian (it):

  • spellout-cardinal-feminine (scf)
  • spellout-cardinal-masculine (scm)
  • spellout-numbering (sn)
  • spellout-numbering-year (sny)
  • spellout-ordinal-feminine (sof)
  • spellout-ordinal-masculine (som)

That is why you will not be able to set ordinal format for (ru) and following code:

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

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

Will print:

string 'quaranta­duesima' (length=17)

Like you (propably) want.

EDIT:

Informations about used formatting with references to ICU: http://php.net/manual/en/numberformatter.create.php

Tested with PHP 5.4.x and ICU version => 51.2; ICU Data version => 51.2. You can use shell command:

$ php -i | grep ICU

To check what version of ICU you have.

For latest ICU version you should propably install/update php-intl package: http://php.net/manual/en/intl.installation.php

EDIT 2:

I have created extension for NumberFormatter (so far with polish ordinals). Feel free to contribute another languages: https://github.com/arius86/number-formatter

Just a Recommendation, I am not sure if this works or have an Apache services open at this point of time as I am at college, but have you tried to put ru-RU for Russia. In PHP I personally put my Language Codes as "en-GB"

http://download1.parallels.com/SiteBuilder/Windows/docs/3.2/en_US/sitebulder-3.2-win-sdk-localization-pack-creation-guide/30801.htm

Here is a List I found on the internet with some to help you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!