本文介绍了NumberFormatter :: SPELLOUT拼写普通-俄语和意大利语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码适用于英语,西班牙语和德语序号,但对于俄语或意大利语序号则无效.

'ru-RU''it-IT'也不起作用

例如,我得到俄语的2->два(这是基数),但是我想要序数,这将是2->второй.

例如,我用意大利语得到2->到期(这是基数),但是我想要序数,这里是2-> secondo.

更新:

我找到了使用法语,西班牙语,德语和其他一些语言的作品的解决方案:

马斯克林序数:%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)
  • 拼写基数男性(scm)
  • spellout-cardinal-neuter(scne)
  • 拼写编号(sn)
  • 详细说明编号年份(sny)

...和意大利语(it):

  • spellout-cardinal-feminine(scf)
  • 拼写基数男性(scm)
  • 拼写编号(sn)
  • spellout-numbering-year(sny)
  • spellout-ordinal-feminine(sof)
  • spellout-ordinal-男性(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

我已经为NumberFormatter创建了扩展名(到目前为止已使用波兰语序号).随时提供其他语言: https://github.com/arius86/number-formatter

this code works for english, spanish and german ordninal numbers, but with russian or italian ordninal numbers it doesn't work.

'ru-RU','it-IT' also don't work

I get for example in russian for 2 -> два (this is the cardinal number) , but I want the ordinal number and this would be here 2 -> второй.

I get for example in italian for 2 -> due (this is the cardinal number) , but I want the ordinal number and this would be here 2 -> secondo.

Update:

I found a solution with works in french, spain, german and some other languages:

maskuline ordinal numbers: %spellout-ordinal-maskuline

feminine ordinal numbers: %spellout-ordinal-feminine

russian and italian version doesn't work and I tried already with -maskuline/-feminine

$ru_ordinal = new NumberFormatter('ru', NumberFormatter::SPELLOUT);
$ru_ordinal->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%spellout-ordinal");  
解决方案

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

这篇关于NumberFormatter :: SPELLOUT拼写普通-俄语和意大利语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 13:32