Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't I just simply get the day name I18n-ed?

I'm pretty new with rails also with ruby.

I just want to get the I18n.l of a day name or a month name, without a whole date or time. Because I don't have it.

For example, I simply want to internationalize for example

= l Date::DAYNAMES[0]

or

= l Date::MONTHNAME[0]

Is it possible?

like image 889
raulricardo21 Avatar asked Oct 11 '13 20:10

raulricardo21


2 Answers

I'm from brazil. In my rails applications I have a pt-BR.yml inside config/locales. It's like this:

"pt-BR":
  date:    
    day_names:
      - Domingo
      - Segunda
      - Terça
      - Quarta
      - Quinta
      - Sexta
      - Sábado

It's the same for month names, etc... In my application.rb I have

config.i18n.default_locale = 'pt-BR'

That gives me translated names. Read the I18N guide for more.

like image 56
Felipe Regis Fernandes Avatar answered Nov 05 '22 20:11

Felipe Regis Fernandes


You can access the day names with:

I18n.t(:"date.day_names")
#=> ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

and the month names with:

I18n.t(:"date.month_names")
#=> [nil, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
like image 42
Stefan Avatar answered Nov 05 '22 19:11

Stefan