views:

115

answers:

1

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.

+1  A: 

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'
Hugo Peixoto
Thanks! It's all about using `localize` instead of `translate` helper. Btw, in console (in Rails 2.3) it should be `helper.localize Time.now, :format => "%B"`, not `controller.`. And another addition - you must have `pl, time, formats` entries in `pl.yml`.
Paweł Gościcki