Jumpstart Pro comes preconfigured with internationalization support allowing you to translate your app to any locale easily.
Inside config/application.rb
you will find several settings for I18n:
available_locales
- An array of locales your app supportsdefault_locale
- The default locale to usefallbacks
- Whether or not to use the default locale as a fallbackload_path
- Folders to look for translation filesThe SetLocale
concern sets the locale at the beginning of each request. It checks for a locale from several places:
params[:locale]
HTTP_ACCEPT_LANGUAGE
headerpreferred_language
attributeYou can customize this concern to change the order or look for the locale in other places such as the domain or subdomain.
The devise-i18n gem comes preinstalled to provide translations for most languages.
These translations don't include every key since Devise has been customized. You will need to customize the translations using the following command:
rails g devise:i18n:locale es
Jumpstart Pro uses the standard Rails I18n functionality. See the Rails I18n guide for details on how Rails implements I18n.
Translations are automatically scoped by specifying a period .
at the beginning of the key. Without the period (.
) at the beginning, it will start lookup at the top level.
t("hello")
in app/views/dashboard/show.html.erb
will look for en.hello
t(".hello")
in app/views/dashboard/show.html.erb
will look for en.dashboard.show.hello
# app/views/dashboard/show.html.erb
<%= t ".hello" %>
# config/locales/en.yml
en:
dashboard:
show:
hello: "Your placeholder text here"
# app/views/dashboard/show.html.erb
<%= t ".welcome", name: "Chris" %>
# config/locales/en.yml
en:
dashboard:
show:
hello: "Welcome, %{name}"
Keys ending in _html
will render as HTML.
# app/views/dashboard/show.html.erb
<%= t ".welcome_html", name: "Chris" %>
en:
dashboard:
show:
hello_html: "Welcome, <strong>%{name}</strong>"
# app/controllers/messages_controller.rb
MessagesController < BaseController
def update
# Some business logic
return redirect_to:index, notice: t(".notice") if @resource.save
render :edit, alert: t(".alert")
end
end
en:
messages:
update:
notice: "Message was successfully updated."
alert: "Unable to update message."
<%= f.input :name, placeholder: true %>
en:
helpers:
placeholder:
message:
name: "Your placeholder text here"
en:
activerecord:
models:
accounts: "Teams"
en:
activerecord:
attributes:
api_token:
last_used_at: "Last Used"
en:
activerecord:
errors:
models:
account:
attributes:
domain:
reserved: "%{value} is reserved."