All threads / How to translate and localize apps with Rails Internationalization (18n) Discussion

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to translate and localize apps with Rails Internationalization (18n) Discussion

This was really great, thank you! Can you provide a link as to what you need to sanitize the variable you passed in, name? Looking forward to the next episode!

You can usually just call the sanitize method and that'll do what you need.

Reply

Hi Chris, this is a very good video. I have completed a few rails apps for my clients that utilize multiple foreign languages using a process that is very similar to the one in your video. For these projects I also had to update the Bootstrap and Simple form YML files to include the appropriate translations for the available languages that were defined for the respective apps.

Reply

Love it, and interested in what's coming! Thanks Chris!

Reply
Reply

Thank you for a very good episode. In a future video perhaps you could expand on approaches to LTR languages like Hebrew, and adding the dir tag to html elements based on the I18n.locale.

Reply

Amazing episode, thank you Chris!

Reply

Hi Chris, on the jumpstartpro template, I created an he.yml file, as a copy of the en.yml, and translated a few strings to Hebrew. That's the only change I made, did not change the default locale or touch any other file. in applicalion.rb it still says config.i18n.available_locales = [:en]. But when launching the app, the strings were translated to Hebrew.
Somehow rails is picking the he.yml file for English as well. When I remove the file, translations revert back to English. Any idea why is that?

Did you remember to change the first line of he.yml, after you made the copy?
The very first line should be
he: and not en:

That is one thing that have tricked me in the past, when translating rails applications ;)

Reply
Reply

Hi Chris,
I added English and Dutch translations, but when I switch to Dutch(nl), I don't see the translations...Any idea where I might have gone wrong? In the nl.yml file the first line is nl:
Thanks in advance

Reply

I have noticed that it works perfectly if the language settings matches one of the available locales. But unfortunately as soon as the browser language does not match one of the locales I will get an I18n::InvalidLocale

I found a solution to my problem but I don't know if it's the best option:

application.rb

# Configuration for internationalization options
I18n.enforce_available_locales = false
# Permitted locales available for the application
config.i18n.available_locales = [:en, :es]
# Set default locale
config.i18n.default_locale = :es
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true

Unfortunately, it doesn't solve all the problem. As soon as I get a form with a date field I have the following error: .date.order only accepts :year, :month and :day, which seems to be related to a helper from rails https://apidock.com/rails/ActionView/Helpers/DateTimeSelector/translated_date_order

# _form.html.erb
<%= form.date_select :date, :default => {:month=>01,:day=>01}, :start_year=>1780 %>

Reply
Join the discussion

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

Join 48,387+ 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

    © 2021 GoRails, LLC. All rights reserved.