Skip to main content

local_time gem: Where to place the I18n file to modify the string literals?

Rails • Asked by Ernesto Gimeno
EDIT. Finally solved, I pasted the keys from I18n.coffee into application.js like that:

LocalTime.config.i18n["es"] = {
    date: {
      dayNames: [
        "Domingo",
        "Lunes",
        "Martes",
        "Miércoles",
        "Jueves",
        "Viernes",
        "Sabado"
      ],
      abbrDayNames: ["Dom", "Lun", "Mar", "Mie", "Ju", "Vie", "Sab"],
.
.
.

then in the same file i placed `LocalTime.config.locale = "es";`
-----------

Hi,

I want to use this gem, which was part of an old episode, but I need to translate the string literals to spanish  in order to use it in my application.

According to their docs, you can just manipulate this file (i18n.coffee) that contains the english defaults, which I did since it looks the easiest way to do it:

The problem is, I don't know where to place this file to get the translated strings loaded, the texts remain as per default. I have modified locales yml files in the past to translate other gems such as devise, but I don't know hot to deal with that.

I have tried in several paths such as:

app/assets/config/i18n.coffee

app/assets/javascripts/src/local-time/config/i18n.coffee

The answer must be pretty obvious but I can't find it :(, any help would be appreciated.


Doesn't it use the i18n yml in `config/locale/<xx>.yml`? 
Great base/starting point is https://github.com/svenfuchs/rails-i18n

I don't think so, that's the reason for my confusion.

They point to this i18n.coffee file in their docs which contains the default english translations:

https://github.com/basecamp/local_time/blob/master/lib/assets/javascripts/src/local-time/config/i18n.coffee

Did you try duplicating all the keys below `en:` for your Spanish translation? I'd expect you can use the same file.

I see you can you pass in the format as a :symbol (`
<%= local_time(date, :long) %>
`), this should look for it in the `config/locale/xx.yml` files.

I tried to copy the keys in locales/en.yml but I get this syntax error:

EDIT. Checking with YAMLLint, looks like the spaces between : and [ are not allowed.

I18n::InvalidLocaleData at /orderscan not load translations from /vagrant/src/pascual-apps/config/locales/en.yml: #&lt;Psych::SyntaxError: (/vagrant/src/pascual-apps/config/locales/en.yml): did not find expected ',' or ']' while parsing a flow sequence at line 34 column 17&gt;

Line 34 is the one for dayNames:

en:
date:
dayNames: [
"Sunday"
"Monday"
"Tuesday"
"Wednesday"
"Thursday"
"Friday"
"Saturday"
]
abbrDayNames: [
"Sun"
"Mon"
"Tue"
"Wed"
"Thu"
"Fri"
"Sat"
]
...

I managed to get  valid YML, translated it,  but the name of the months remains in english.

EDIT. In this issue they talk about it, tried what the last comment says, still no luck. 

https://github.com/basecamp/local_time/pull/53

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.