Viewing Mode

Internationalization

ModelRails ships in English only, but everything user-facing goes through I18n anyway. That is not aspirational multi-language support — it is what lets a fork rewrite every string in the product without touching a template, and it is why the design-system rule “no hardcoded UI strings” is enforceable at all.

Two gates keep it honest. Both fail the suite, so neither can rot.

Where keys live

Content lives in domain-split files under config/locales/en/:

config/locales/
  en.yml                    # catch-all — see below
  en/
    auth.en.yml
    workspaces.en.yml
    notifications.en.yml
    …

Rails loads config/locales/**/*.{rb,yml}, so any .yml in that tree is picked up — with or without the .en. infix. Prefer the infix for consistency with the existing files.

config/locales/en.yml holds no keys. It is the landing zone for i18n-tasks add-missing; anything that appears there still needs a home in a domain file.

The two gates

raise_on_missing_translations (runtime, test only)

Enabled in config/environments/test.rb. A t() call for a key that does not exist raises instead of rendering translation missing. It catches real regressions, but only on code paths a spec actually walks — and only when the call site has no inline default:.

It is deliberately off in development, where a missing key renders inline. That is the more useful signal while a page is still being built, and CI runs the full suite on every pull request that changes code, so a missing key cannot merge.

No inline defaults

A translation call carries no default:. Both gates look straight through one: the runtime gate never raises for a key that has a fallback, and the static gate reports the key as present, so a missing key with a default looks healthy forever and a user reads the fallback. Put the text under the key (bundle exec i18n-tasks add-missing files it) and drop the default. A dynamic key (project_tools.#{key}.name) is the one case neither gate can see at all; it gets a spec that walks every value and asserts the key exists (spec/code_smells/project_tools_have_locale_keys_spec.rb is the shape). The ModelRails/NoI18nDefault cop (lib/rubocop) fails a default: on commit, in Ruby files through RuboCop and in views through erb_lint’s Rubocop linter. The vendored app/components/ui primitives are out of its scope: they are the modelrails_ui gem’s files, regenerated by its installer, and their fallbacks are how the gem renders without host keys.

i18n-tasks (static, spec/i18n_spec.rb)

Scans the repo without executing anything, so it sees paths no spec covers — including call sites with an inline default: masking the gap.

bundle exec i18n-tasks missing        # gated — fails the suite
bundle exec i18n-tasks check-consistent-interpolations   # gated
bundle exec i18n-tasks unused         # gated — fails the suite (#522)
bundle exec i18n-tasks normalize      # never gated — see spec/i18n_spec.rb (#523)

It runs as an ordinary spec rather than a separate CI step, so CI and the pre-push hook get it with nothing to keep in sync.

When the gate fails, add the key. Do not add an entry to ignore_missing or disable the config — those exist for engine-owned namespaces, not for convenience.

Lazy keys: only inside actions

Rails resolves t(".key") in a controller against action_name. Inside a private helper, that scope is a claim the code cannot honour — and static analysis, which resolves the enclosing method name, cannot verify it either.

This bit us: invalid_token and expired_or_used were defined only under create:, while the shared find_valid_invitation filter also ran for show. Both flashes rendered translation missing to real users, and the request specs passed because they asserted only the redirect.

The rule:

def show
  redirect_to root_path, alert: t(".not_found")           # ✅ inside an action
end

private

def find_valid_invitation
  redirect_to root_path, alert: t("invitations.invalid")  # ✅ absolute
end

And assert the message, not just the redirect:

expect(response).to redirect_to(root_path)
expect(flash[:alert]).to eq(I18n.t("invitations.invalid"))

Validation messages

Pass a symbol; put the text in a locale file. Never inline the string, and never use I18n.t(..., default: "…") — the default silences the gate permanently, so a missing key looks healthy forever.

# ✅
errors.add(:join_policy, :personal_must_be_invite)
en:
  activerecord:
    errors:
      models:
        workspace:
          attributes:
            join_policy:
              personal_must_be_invite: "must be 'invite' for personal %{workspaces}"

One caveat: activerecord.errors.* and activerecord.attributes.* are both in ignore_unused, because Active Model consumes them itself — errors.* via full_message, attributes.* via human_attribute_name — rather than any explicit t() call. That means a key left behind by a deleted validation or a renamed attribute will never be reported — remove it by hand.

activerecord.attributes.workspace.owner_email is the first app-level override of a humanized attribute name (config/locales/en/operations.en.yml). It exists because the operator-create form’s error summary prefixes a validation failure with the humanized attribute name — that prefix has to read the same as the field’s own label (operations.workspaces.new.owner_email, “Owner’s email address”), or the summary names a field the form doesn’t.

A translation ending in _html is a separate Rails convention worth knowing alongside this: the suffix marks the translation’s own text as html_safe, so markup written into the value survives, while every interpolation argument that is not already html_safe is escaped as usual. See operations.operatorships.index.granted_by_html in the same file: it interpolates a <time> element built by content_tag (already safe, passes through) beside a %{name} that stays escaped. Never reach for the suffix to skip escaping an interpolation argument — it does not do that.

Dates and times

Render dates through I18n.localize, never strftime:

<%= l Date.current, format: :long %>

:default, :short and :long come from ActiveSupport. Override them, or add your own, in a locale file:

en:
  date:
    formats:
      long: "%-d %B %Y"      # 25 July 2026 instead of July 25, 2026
      invoice: "%Y-%m-%d"

Every l call in the app then follows, with no template edits.

Adding a language

config.i18n.available_locales is pinned to [:en] in config/application.rb. Register your locale there first.

That pin is not ceremony. Without it, available_locales is derived from the load path — and faker (a development/test gem shipping ~350 locale files) made it ~60 entries under test and [:en] in production. I18n.translate calls enforce_available_locales! before it reaches the backend, so an unregistered locale raised I18n::InvalidLocale in production while specs passed. That shipped a 500 on the notification bell for any user whose saved locale was not en.

So:

  1. Add the locale to config.i18n.available_locales in config/application.rb.
  2. Add config/locales/fr/*.fr.yml.
  3. Run bundle exec i18n-tasks missing — it compares every locale against base_locale and lists what you still owe.

UserPreferences#locale validates against available_locales, so a language you have not registered cannot be selected.

Know what the runtime gate does not cover

config.i18n.fallbacks = true is set in test, development and production, so a lookup that misses in :fr terminates at :en rather than dying. That is the right production behaviour — but it means a missing :fr key resolves to English and your :fr specs pass on English text.

Cross-locale completeness is i18n-tasks missing’s job, not raise_on_missing_translations’s. If you add a language, that static gate is the one keeping you honest.

Fork seams

File What a fork changes
config/application.rb available_locales — register a new language
config/locales/en/*.en.yml Product copy, per domain
config/locales/en/brand.en.yml Product name and brand strings
config/i18n-tasks.yml ignore_missing if you mount another engine
config/environments/*.rb raise_on_missing_translations if you want it in development too

Vocabulary

Two nouns are data, not copy: workspace and project. config/vocabulary.yml holds the template’s forms, config/vocabulary.local.yml a fork’s overrides, and config/initializers/vocabulary.rb merges the derived tokens (%{workspace}, %{Workspace}, %{workspaces}, %{Workspaces} and the project four) into any translation whose string uses one — a string that keeps a %{count} or %{name} for client-side JavaScript is left alone, so it stays literal — unless it also uses a noun token, which the gate forbids. Write copy with the tokens, never the word; spec/code_smells/locale_values_use_vocabulary_tokens_spec.rb fails on the word, and locale_interpolation_tokens_are_supplied_spec.rb fails on a token nobody supplies. Word sentences so no indefinite article precedes a token. Assert copy in specs through I18n.t so a renamed fork stays green; spec_copy_assertions_use_i18n_spec.rb enforces it. A translation call never passes a vocabulary token name as an argument (project:, workspace:); a record’s name is workspace_name: / project_name:, and locale_interpolation_tokens_are_supplied_spec.rb fails a call that does.