Selecting the Locale
Learn to add the support of multiple languages.
We'll cover the following...
Configuration for locale
Creating a new configuration file that encapsulates our knowledge of what locales are available and which one is to be used as the default:
Press + to interact
#---# Excerpted from "Agile Web Development with Rails 6",# published by The Pragmatic Bookshelf.# Copyrights apply to this code. It may not be used to create training material,# courses, books, articles, and the like. Contact us if you are in doubt.# We make no guarantees that this code is fit for any purpose.# Visit http://www.pragmaticprogrammer.com/titles/rails6 for more book information.#---#encoding: utf-8I18n.default_locale = :enLANGUAGES = [['English', 'en'],["Español".html_safe, 'es']]
This code is doing two things.
The first thing it does is use the I18n
module to set the default locale. Certainly, I18n
is a funny name, but it sure beats typing out “internationalization” all the time. Internationalization, after all, starts with an i
, ends with an n
, and has eighteen letters in between.
Then the code defines a list of associations between display names and locale names. ...