International ordinals on rails

I'm new to rails

My site is developed in two languages: English and French, I use i18n for translation.

I want to use i18n with ordering if anyone can help me here.

I went through the link but havent got success

http://murfy.de/read/i18n-ordinalization

http://info.michael-simons.eu/2009/02/12/localizing-dates-and-time-with-rails-i18n-using-procs/

Read which steps I must complete.

Thanks Sunil

+4
source share
1 answer

I ran into the same problem and I tried the links you provided. However, I could not get them to work. Finally, I came up with a solution:

1) add a new helper method in app/helpers/application_helper.rb

 def ordinalize_number number case I18n.locale when :en return number.ordinalize when :'zh-TW' return number else return number end end 

2) update your config/locales/*.yml (en.yml in this case)

 end_quarter: 'End The %{order} Quarter' 

3) use helper method with default i18n method in html.erb

 <%= t('end_quarter', :order => ordinalize_number(3)) %> # it will show "End The 3rd Quarter" properly 

Although I'm not sure if this is the best solution, it works without changing any environment settings.

+4
source

All Articles