Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction between add-missing and i18n gem reserved keys check? #552

Closed
mjankowski opened this issue Mar 7, 2024 · 1 comment · Fixed by #553
Closed

Interaction between add-missing and i18n gem reserved keys check? #552

mjankowski opened this issue Mar 7, 2024 · 1 comment · Fixed by #553
Labels

Comments

@mjankowski
Copy link

As part of a larger CI process, we are running the command: bundle exec i18n-tasks add-missing -l en

In a PR which bumped the version of i18n gem from 1.14.1 to 1.14.4, we see this failure: https://github.com/mastodon/mastodon/actions/runs/8187366599/job/22387716072?pr=29495

Relevant error portion:

bundler: failed to load command: i18n-tasks (/home/runner/work/mastodon/mastodon/vendor/bundle/ruby/3.2.0/bin/i18n-tasks)
/home/runner/work/mastodon/mastodon/vendor/bundle/ruby/3.2.0/gems/i18n-1.14.4/lib/i18n/backend/base.rb:65:in `translate': reserved key :default used in "Value. Interpolates: %{value}, %{human_key}, %{key}, %{default}, %{value_or_human_key}, %{value_or_default_or_human_key}" (I18n::ReservedInterpolationKey)

          raise ReservedInterpolationKey.new($1.to_sym, entry)

I think that the reserved keys check (added in i18n 1.14.3) is raising an error because of one of these reserved keywords being used in an interpolation - https://github.com/ruby-i18n/i18n/blob/master/lib/i18n.rb#L19-L34

The error seems to point back to this section of the i18n-tasks default config - https://github.com/glebm/i18n-tasks/blob/main/config/locales/en.yml#L32-L34 - and the %{default} key in particular being used there.

@glebm
Copy link
Owner

glebm commented Mar 7, 2024

Oh, we should probably escape these "interpolations". They're meant to be there verbatim.

We'll also need to adjust the regex here to not match escaped interpolations:

@variable_regex = /%{[^}]+}/.freeze

Interpolations can be escaped with %% (e.g. %%{default}) according to https://github.com/ruby-i18n/i18n/blob/master/lib/i18n/interpolate/ruby.rb

The regexp that we want for that is probably something like this: /(?<!%)%{[^}]+}/: https://rubular.com/r/catthAgMPZ1afN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants