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

Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Ernesto Gimeno asked in Rails
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
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.