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!

Reply

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

awesome, thank you!

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

Great idea!

Reply

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.

Reply

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:
pg_catalog."he-IL-x-icu"

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.

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?

Reply

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

No I didn't! Thanks much

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
Reply

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

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

Reply

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!

Reply
Join the discussion
Create an account Log in

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

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

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