Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 2.3.5 I18n month/day name translation problem

My config/locales/pl.yml file (sampled from here):

pl:
  date:
    day_names: [Niedziela, Poniedziałek, Wtorek, Środa, Czwartek, Piątek, Sobota]
    month_names: [~, Styczeń, Luty, Marzec, Kwiecień, Maj, Czerwiec, Lipiec, Sierpień, Wrzesień, Październik, Listopad, Grudzień]

In script/console:

I18n.locale = 'pl'
=> "pl"

Time.now.strftime("%A, %B")
=> "Tuesday, August"

Why? Or put it another way - how can I get translated month names? I'll also note that the locale file is definitely read as it includes a bunch of other translations, which all work.

like image 456
Paweł Gościcki Avatar asked Aug 31 '10 19:08

Paweł Gościcki


1 Answers

That depends on which rails version you are using. There's a helper to translate that, on rails 3.0.0 (I don't know from which version it was made available).

In a view, you can write

localize Time.now, :format => '%A, %B'

in script/console (or rails console), try typing:

controller.localize Time.now, :format => '%A, %B'

and see if it works. There's also the lhelper (lowercase L), which is a shorthand for localize:

controller.l Time.now, :format => '%A, %B'
like image 104
Hugo Peixoto Avatar answered Nov 06 '22 18:11

Hugo Peixoto