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

[BUG] Symbol resolving interpolates the string multiple times #599

Open
movermeyer opened this issue Jan 7, 2022 · 1 comment
Open

[BUG] Symbol resolving interpolates the string multiple times #599

movermeyer opened this issue Jan 7, 2022 · 1 comment

Comments

@movermeyer
Copy link
Contributor

movermeyer commented Jan 7, 2022

What I tried to do

# frozen_string_literal: true

require "i18n"

I18n.backend = I18n::Backend::Simple.new
I18n.backend.store_translations(:en, foo: :bar, bar: "%{baz}")
puts(I18n.t("foo", baz: "%{qux}"))

What I expected to happen

"%{qux}"

i.e., the resolved Symbol's value is only interpolated once and returned.

What actually happened

I18n::MissingInterpolationArgument: missing interpolation argument :qux in "%{qux}" ({:baz=>"%{qux}"} given)

This is a result of %{baz} interpolating to %{qux}, and then the code trying to interpolate %{qux}.

Note that removing the Symbol resolving works:

# frozen_string_literal: true

require "i18n"

I18n.backend = I18n::Backend::Simple.new
I18n.backend.store_translations(:en, foo: "%{baz}")
puts(I18n.t("foo", baz: "%{qux}"))

Note that interpolation occurs for each layer of Symbol resolving that is done:

e.g.,

# frozen_string_literal: true

require "i18n"

I18n.backend = I18n::Backend::Simple.new
I18n.backend.store_translations(:en, foo: :bar, bar: :baz, baz: "%{baz}")
puts(I18n.t("foo", baz: "%{qux}", qux: "%{cat}"))

Interpolates the string three times.

Versions of i18n, rails, and anything else you think is necessary

i18n: v1.8.11
Ruby: v3.0.3
@movermeyer movermeyer changed the title [BUG] Symbol resolving interpolates the string twice [BUG] Symbol resolving interpolates the string multiple times Jan 10, 2022
@movermeyer
Copy link
Contributor Author

This can also happen as a result of Symbol resolving via default parameters:

# frozen_string_literal: true

require "i18n"

I18n.backend = I18n::Backend::Simple.new
I18n.backend.store_translations(:en, foo: "%{baz}")
puts(I18n.t("non-existent", baz: "%{qux}", default: [:foo]))

@ruby-i18n ruby-i18n deleted a comment from tomadam123 Apr 8, 2023
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

No branches or pull requests

1 participant