Skip to Content

Rails - I18n lazy load

Posted on

Normaly, we call i18n by using: t "user.new.new_user", but it’s quite long.

First, we need to add this line to config/application.rb

config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]

After that, we need to manage config/locale folder like:

config/locale
  -views
    en.yml
  - controller

On en.yml file:

en:
  users:
    new:
      new_user: "New User"

Now, we can call “New User” by using: t ".new_user" on views/users/new.html.erb

comments powered by Disqus