13 July 2015

Internationalization I18n

# Gemfile
gem 'rails-i18n', '~> 4.0.0'

# config/environment/*
config.i18n.available_locales = :en, :es, :ca

# application.rb
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
config.i18n.default_locale = :ca
<h1><%= t :Emergency_info %></h1>
<%= link_to t(:Edit), edit_emergency_path(@emergency) %>
<p>
  <%= @emergency.simulacrum ? t(:Simulacrum) : t(:Real_emergency) %>
</p>

Reasons to use I18n always

https://robots.thoughtbot.com/better-tests-through-internationalization

Reco: Use VIM and http://github.com/stefanoverna/vim-i18n plugin to fast apply I18n Reco: https://github.com/redealumni/i18n_yaml_sorter to sort alphabetically YML files You can make missing translations fail your tests by adding the following to an initializer:

if Rails.env.development? || Rails.env.test?
  I18n.exception_handler = lambda do |exception, locale, key, options|
    raise "missing translation: #{key}"
  end
end

http://svenfuchs.com/2011/2/11/organizing-translations-with-i18n-cascade-and-i18n-missingtranslations