Posted by ngty on August 06, 2010
For reliable formatting of a date/time string in the desired language, use I18n.localise, Time#strftime can cause u unnecessary headache.
On different machines, Time#strftime can yield different results, and there is no reliable way to ensure u get the string with the desired language, even after setting the environment variable $LANG, and even recompiling ruby under the desired locale setting. Use I18n.localize instead:
I18n.localize(Time.now) # using :default format I18n.localize(Time.now, :format => :short) # using short format I18n.localize(Date.today) # using :default format I18n.localize(Date.today, :format => :short) # using short format
In view layer, u can replace the verbose I18n.localize(...) with just shorthand l(...).
All u need is to have the appropriate yml data file under config/locales, the resources at http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/ provides a good starting point.