Mark

Start your next Ruby on Rails app.

Get Started

Backend

Frontend

Extras

Internationalization (I18n)

Jumpstart Pro comes preconfigured with internationalization support allowing you to translate your app to any locale easily.

I18n Settings

Inside config/application.rb you will find several settings for I18n:

  • available_locales - An array of locales your app supports
  • default_locale - The default locale to use
  • fallbacks - Whether or not to use the default locale as a fallback
  • load_path - Folders to look for translation files

Requests

The SetLocale concern sets the locale at the beginning of each request. It checks for a locale from several places:

  • params[:locale]
  • HTTP_ACCEPT_LANGUAGE header
  • The current user's preferred_language attribute
  • I18n.default_locale

You can customize this concern to change the order or look for the locale in other places such as the domain or subdomain.

Devise

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

Translation Examples

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

Views

# app/views/dashboard/show.html.erb
<%= t ".hello" %>
en:
  dashboard:
    show:
      hello: "Your placeholder text here"

With Arguments

# app/views/dashboard/show.html.erb
<%= t ".welcome", name: "Chris" %>
en:
  dashboard:
    show:
      hello: "Welcome, %{name}"

With HTML

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>"

Output

Hello, Chris

Controllers

# 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."

Placeholders

<%= f.input :name, placeholder: true %>
en:
  helpers:
    placeholder:
      message:
        name: "Your placeholder text here"

Model names

en:
  activerecord:
    models:
      accounts: "Teams"

Model attributes

en:
  activerecord:
    attributes:
      api_token:
        last_used_at: "Last Used"

Model validation errors

en:
  activerecord:
    errors:
      models:
        account:
          attributes:
            domain:
              reserved: "%{value} is reserved."