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


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.

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.

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

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.

I've encountered a specific problem in I18n with Hebrew which is an RTL language. How do you customize ActiveRecord's 'order' query so that the sorting is done correctly on a column which is in Hebrew? It seems not to work at all.

Here is the solution for anyone running into this problem with Hebrew or other languages. This is a database collation issue. My environment is postgresql 12 on Mac OS Big Sur.

Change the collation for the table column that contains the Hebrew text to be sorted to:

I used the pgadmin application for this: navigated to Servers/PostgreSQL 12/Databases//schemas(1)/public/Tables//columns/.Click on the column name, and then click on Edit. In the Edit dialog that opens, click on Definition, and select the proper collation for your language in the Collation field. I had to do a bit of research to find the right value for Hebrew on a Mac.

BTW, on Heroku I had no problems with the Hebrew collation, it seems that on their database the collation that is defined works well.

Amazing episode, thank you Chris!

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 ;)

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

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:


# 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

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

The video gives the perfect solution,but here as you have described the method in application_controller for set_locale--> if user signed_in?
this works fine,but i want something where when user logs in,the language selected at that time should be same when logged in. @Chris Oliver if you could help here.

Thank you in advance

Hello Chris, you mention at the end, an episode about translating modes. Is it available? I made a search but couldn't find anything other than this episode. Really appreciate any pointers!

Join the discussion

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

Join 68,099+ 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.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.