Question

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?

Was it helpful?

Solution

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"]

OTHER TIPS

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.

AFAICT, that information is not exposed directly by the Rails I18N API. Probably easiest to make up a date in the month or weekday you need, localize it, and extract the desired string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top