-
Notifications
You must be signed in to change notification settings - Fork 282
Description
Description
The RailsModelMatcher incorrectly reports missing translations when using Model.human_attribute_name with dot notation that resolves to slash notation in locale files.
Steps to Reproduce
- Define a translation in
config/locales/en.yml:
en:
activerecord:
attributes:
product/status:
active: Active
inactive: Inactive- Use it in a view:
<%= Product.human_attribute_name("status.active") %>- Run
i18n-tasks missing
Expected Behavior
The translation should be recognized as existing since Rails' human_attribute_name correctly resolves "status.active" to activerecord.attributes.product/status.active.
Actual Behavior
i18n-tasks reports the key as missing:
activerecord.attributes.product.status.active app/views/products/show.html.erb:10
Verification
Rails correctly finds the translation:
Product.human_attribute_name("status.active")
# => "Active"This works because Rails internally converts dot notation to slash notation when looking up ActiveRecord attribute translations for nested scopes.
Environment
- i18n-tasks version: 1.1.2
- Rails version: 7.2.2.2
- Ruby version: 3.3.10
Proposed Solution
The RailsModelMatcher should be aware that Rails' human_attribute_name method has special logic that converts dot notation to slash notation, following the same lookup pattern that Rails uses internally.
Additional Context
This slash notation pattern is commonly used in Rails for STI (Single Table Inheritance) models and enum-like nested attributes. The mismatch between how i18n-tasks scans for keys and how Rails actually resolves them causes false positives in the missing translations report.
Reference
Rails i18n Guide - Translations for Active Record Models:
https://guides.rubyonrails.org/i18n.html#translations-for-active-record-models
The guide documents how Rails uses slash notation for model attribute translations, particularly for STI models and nested scopes.