Difference between #3 and #4 of
How to handle decimal separators (e.g comma instead of dot) for l18n

Revision #4 has been created by jpablo on Jan 23, 2012, 6:17:06 AM with the memo:

Forum post added
« previous (#3)

Changes

Title unchanged

How to handle decimal separators (e.g comma instead of dot) for l18n

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

Content changed

Yii i18n does not cover decimal format. Some languages like Spanish (I live in Argentina) uses comma ',' instead of dot '.' as decimal separator. A localized web app should:
 
1- Display decimal values with the local decimal separator.
 
2- Allow entering decimal values with the local decimal separator.

Yii does not provides a way to do it, there is an extesion to solve this situation (decimali18nbehavior), but it has a couple of severe issues: User input is transformed to DB format using 'beforeSave', that's after rules validation. Every number validation will fail because Yii will try to validate as a number with dot separator a value with comma separator. By the other hand, decimali18nbehavior formats the decimal values before displaying usign the afterFind event. That's prevents to be able to make any math operation on the values. In other word, un version is made too late, and the other conversion is made too early.
[...]
I know that it's not an elegant solution, but as far as I know there is no way to override a core class reusing the original class code. If anyone has any idea to improve this approach just post a message.

Please add your comments, suggestions, etc, in the forum. [Forum post](http://www.yiiframework.com/forum/index.php?/topic/28048-handling-decimal-separators-wiki-article/ "Forum post")
2 0
10 followers
Viewed: 22 691 times
Version: 1.1
Category: How-tos
Tags:
Written by: jpablo
Last updated by: jpablo
Created on: Jan 23, 2012
Last updated: 12 years ago
Update Article

Revisions

View all history