I've been working a bit with Rails Internationalization (I18n) this week, here's what I learned:
I18n.load_path
. This command is also helpful in a debugging context to verify that files you have added are being recognized. By default, Rails only loads the locale files at the root of config/locales
. If you want to organize your locales into directories, you need to configure Rails (config/application.rb.) to look deeper with:config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")]
/views/users/index.html.erb
, I can simply use t(".hi_there")
instead of t("users.index.hi_there")
._html
will prevent the content from being html escaped, similar to using the .html_safe
view helper. For example, I could create the key hi_there_html: "<strong>Hi there</strong>"
, and it would correctly display my markup.The Rails Guides on Internationalization have really good information on I18n, if you haven't read through it, it's worth a quick read, I bet you'll pick up a thing or two.
Written by Alex Brinkman who lives and works in Denver, but plays in the mountains.