Enforcement

RuboCop cops

locallingo ships two i18n cops so fully-qualified keys and locale-aware dates are enforced, not just documented.

Enabling the cops#

The cops load lazily — requireing them pulls in RuboCop, which is a development-time dependency, never a runtime one. In your app's .rubocop.yml:

.rubocop.yml
require:
  - locallingo/rubocop
inherit_gem:
  locallingo: config/default.yml

inherit_gem brings in locallingo's shipped defaults (enabled state, include globs, ScopedDirectories); override any of it in your own file.

Locallingo/RelativeI18nKey#

Flags relative lazy-lookup keys like t(".title") and — where the file path maps to a known convention — autocorrects them to the fully-qualified key derived from the path and enclosing method. Relative keys silently break when a translation moves file, an action is renamed, or a string is reused; fully-qualified keys are explicit and grep-able.

before / after
# bad
t(".title")

# good (autocorrected in app/views/users/index.rb)
t("users.index.title")

Configure which directories map to a lazy-lookup scope with ScopedDirectories — defaults to controllers, mailers, views, components, models, services, jobs, notifiers.

Locallingo/StrftimeInView#

Flags .strftime(...) in view files — hardcoded date formats bypass locale-aware formatting. Use I18n.l(value, format: :name) with named formats in config/locales/{date,time}.*.yml instead. .strftime inside a value: pair (an HTML datetime-local input, which must follow the HTML spec) is exempt.

before / after
# bad
created_at.strftime("%B %d, %Y")

# good
I18n.l(created_at, format: :long)