Yii Framework Forum: Localization - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Localization how is it set Rate Topic: -----

#1 User is offline   Cooper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 26-November 09

Posted 15 April 2010 - 09:36 PM

I am trying to use CNumberFormatter::formatCurrency() however its giving me an error that _locale is not set in my controller.

I would imagine that locale would be set application wide with a suitable default, but it appears not.

How can I set the locale for my application?

Thanks!
0

#2 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 16 April 2010 - 01:30 AM

You'll have to do something like this:

<?php $formatter = new CNumberFormatter('en') ?>
	<?php echo $formatter->formatCurrency('10.11', 'USD'); ?>

Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
0

#3 User is offline   Cooper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 26-November 09

Posted 16 April 2010 - 02:18 AM

Thanks. I ended up doing it like this:

$fm = new CNumberFormatter(Yii::app()->getLocale());

echo $fm->formatCurrency($val['display_price'], "USD");


I am curious with locale how Yii would return "USD" (or other currency) if multiple currencies/locales are available.
0

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 16 April 2010 - 02:53 AM

View PostCooper, on 16 April 2010 - 02:18 AM, said:

Thanks. I ended up doing it like this:

$fm = new CNumberFormatter(Yii::app()->getLocale());

echo $fm->formatCurrency($val['display_price'], "USD");



There's already CApplication::numberFormatter. So your code is the same as:

echo Yii::app()->numberFormatter->formatCurrency(...);

0

#5 User is offline   Cooper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 26-November 09

Posted 16 April 2010 - 11:52 AM

View PostMike, on 16 April 2010 - 02:53 AM, said:

There's already CApplication::numberFormatter. So your code is the same as:

echo Yii::app()->numberFormatter->formatCurrency(...);



Right you are, thanks for the tip!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users