V
V
Vyacheslav Alekseev2014-10-01 12:56:10
ruby
Vyacheslav Alekseev, 2014-10-01 12:56:10

[Ruby => Sinatra] How to do date formatting and add Russian language?

Hey!
I'm working on a Sinatra project and I'm currently learning the R18n.
I added gem sinatra-r18n
In main.rb added

require 'sinatra/r18n'
R18n::I18n.default = 'ru'
R18n.default_places { './config/locales/' }

I added ru.yml to the config/locales folder.
In the view I write:
<option value="<%= date.date %>"><%= l date.date, :format => :short %></option>

And the actual error:
Unknown time formatter {:format=>:short}
file: locale.rb location: localize line: 167

Tell me what I did wrong?
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
anyd3v, 2014-10-01
@AlexeevVyacheslav

Are you sure that there is such a format https://github.com/ai/r18n/blob/master/r18n-core/l... ?
in my opinion an example from rails.

P
phil_tsarik, 2014-10-13
@phil_tsarik

To localize the date, you need to use time in yml files, because such an object as yours is apparently a DateTime class (or similar):

ru:
  time:
    formats:
      short: ! '%-d %b'

Moreover, this is evidenced by the error:
unknown time formatter {:format=>:short}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question