Fix RailsModelMatcher to recognize slash notation in ActiveRecord attribute translations#703
Merged
glebm merged 2 commits intoglebm:mainfrom Jan 12, 2026
Merged
Fix RailsModelMatcher to recognize slash notation in ActiveRecord attribute translations#703glebm merged 2 commits intoglebm:mainfrom
glebm merged 2 commits intoglebm:mainfrom
Conversation
glebm
approved these changes
Jan 10, 2026
davidwessman
requested changes
Jan 11, 2026
wagner
commented
Jan 12, 2026
| ] | ||
| ) | ||
| ) | ||
| describe "key verification" do |
Contributor
Author
There was a problem hiding this comment.
Lots of changes here because I had to split the tests: Spec/ExampleLength: Example has too many lines. [158/140]
wagner
commented
Jan 12, 2026
Comment on lines
+174
to
+176
| candidate_keys: [ | ||
| "activerecord.attributes.product/status.active" | ||
| ] |
Contributor
Author
There was a problem hiding this comment.
The reorganization made it hard to see, but here's the only actual change in the test. 👆
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #702
Problem
The
RailsModelMatcherincorrectly reported missing translations when usingModel.human_attribute_namewith dot notation that should resolve to slash notation in locale files.Rails'
human_attribute_namemethod has special logic that converts dot notation to slash notation when looking up nested attribute translations. This is commonly used for STI (Single Table Inheritance) models and enum-like nested attributes.Example
Locale file (
config/locales/en.yml):View code:
Before this fix:
i18n-taskslooked for:activerecord.attributes.product.status.activeAfter this fix:
i18n-taskscorrectly looks for:activerecord.attributes.product/status.activeSolution
Updated both the AST-based (
RailsModelMatcher) and Prism-based scanners to detect when an attribute name contains a dot and convert the separator between the model name and attribute to a slash, matching Rails' internal behavior.Changes
lib/i18n/tasks/scanners/ast_matchers/rails_model_matcher.rb: Added logic to use slash separator when attribute contains a dotlib/i18n/tasks/scanners/prism_scanners/visitor.rb: Applied the same conversion logic for the Prism scannerTesting
Test Cases Added
Product.human_attribute_name("status.active")<%= Product.human_attribute_name("status.active") %>Backward Compatibility
This change is fully backward compatible. Attributes without dots continue to use the standard dot notation:
Archive.human_attribute_name(:name)→activerecord.attributes.archive.name✅References