Reputation: 362
asSpellaut sometime work incorrect. Is solution for setting other function under asSpellout? Code:
<?=\Yii::$app->formatter->asSpellout($eur)?> EUR
For example in Latvian actual Yii2 spelaut 1978 as "viens tūkstoši deviņsimt septiņdesmit astoņi", but correct is "viens tūkstotis deviņi simti septiņdesmit astoņi"
Upvotes: 1
Views: 403
Reputation: 1314
asSpellout() uses PHP intl extension.
1) Try to use MessageFormatter or NumberFormatter directly with different options:
MessageFormatter::formatMessage("lv_LV", "{0, spellout}",[1978]);
See http://intl.rmcreative.ru/site/message-formatting?locale=lv_LV "Message formatting" and "Number formatting" tabs for details.
2) You can also use translations:
echo \Yii::t('app', '{0, number} is spelled as {0, spellout}', [1978]);
3) Or you can extend Formatter class and implement your own asSpellout method:
// components/Formatter.php
namespace app\components;
class Formatter extends \yii\i18n\Formatter
{
public function asSpellout ($value) {
...
}
}
And set this class as application component
// config/web.php
'components' => [
...
'formatter' => [
'class' => 'app\components\Formatter',
],
],
Upvotes: 1