Skip to content

Return only the key from interpolation_keys for sprintf-style patterns - #752

Open
lenamonj wants to merge 1 commit into
ruby-i18n:masterfrom
lenamonj:i18n-01
Open

Return only the key from interpolation_keys for sprintf-style patterns#752
lenamonj wants to merge 1 commit into
ruby-i18n:masterfrom
lenamonj:i18n-01

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 2, 2026

Copy link
Copy Markdown

I18n.interpolation_keys returned the sprintf format specifier alongside the key for the %<name>fmt form:

I18n.backend.store_translations(:en, greeting: "n = %<count>d, x = %<v>.2f")
I18n.interpolation_keys("greeting") #=> [["count", "d"], ["v", ".2f"]]

Regexp.union of the interpolation patterns has two capture groups for that pattern, and scan returns every group. interpolate_hash already picks the first non-nil capture as the key; interpolation_keys_from_translation now does the same, so the example returns ["count", "v"].

Four tests added. bundle exec rake passes on Ruby 3.3.8, 1611 runs (1607 before).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant