When creating truly internationalized content, you need to think of a few things – first, what country your are in, and secondly, what the locale is in that country. Why should you care? User input.
While Symfony does have handy features via
sfI18N, it doesn’t expose some of the methods needed to correctly parse strings. While string parsing isn’t meant to be the scope of this post, I’ll explain how to get your hands on the number formatting information to enable your application to correctly parse input strings and/or display them in templates (although, I might remind you of the Number helper and its application within the view layer, to aviod logic duplication when that’s already been taken care of).
When you want to get number format information, you simply create an instance of
sfCultureInfo, like so:
// lang php $culture_info = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture()); $number_format_info = $culture_info->getNumberFormat(); $negative_sign = $number_format->getNegativeSign(); $decimal_sign = $number_format->getDecimalSeparator();
This gives you the chance to write your own number parser according to the expected format and/or use locale-specific settings for different purposes for user-friendly input, not just