2016-11-22 57 views
1

asSpellaut有時工作不正確。是否在asSpellout下設置其他功能? 代碼:格式化程序如何修正

<?=\Yii::$app->formatter->asSpellout($eur)?> EUR 

例如,在拉脫維亞實際Yii2 spelaut 1978年爲 「vienstūkstošideviņsimtseptiņdesmitastoņi」,但正確的是 「vienstūkstotisdeviņisimtiseptiņdesmitastoņi」

回答

1

asSpellout()使用PHP國際擴展。

1)嘗試直接與不同的選擇使用MessageFormatter或的NumberFormatter:

MessageFormatter::formatMessage("lv_LV", "{0, spellout}",[1978]); 

參見http://intl.rmcreative.ru/site/message-formatting?locale=lv_LV 「消息格式」 和 「數字格式化」 的選項卡的信息。

2)您也可以使用翻譯:

echo \Yii::t('app', '{0, number} is spelled as {0, spellout}', [1978]); 

3)也可以擴展格式化類和實現自己的asSpellout方法:

// components/Formatter.php 
namespace app\components; 

class Formatter extends \yii\i18n\Formatter 
{ 
    public function asSpellout ($value) { 
     ... 
    } 
} 

並將此類作爲應用程序組件

// config/web.php 
'components' => [ 
    ... 
    'formatter' => [ 
     'class' => 'app\components\Formatter', 
    ], 
],