ruby-i18n / i18n

Internationalization (i18n) library for Ruby
MIT License
988 stars 411 forks source link

[BUG] Breaking change in v1.13.0, strings are now being returned frozen #658

Open jcw- opened 1 year ago

jcw- commented 1 year ago

What I tried to do

Invoked I18n.t

What I expected to happen

An unfrozen string to be returned (like in v1.12.0)

What actually happened

A frozen string was returned

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

i18n: v1.13.0 Rails: 6.0.6.1 Translations: In a yml file

The issue is the conditional return statement introduced in this commit: https://github.com/ruby-i18n/i18n/commit/be2f3a056a964f855def08a1e84a7afe5d0c46db

The prior version would always return the result of gsub, which has the effect of "unfreezing" a frozen string. By adding a code path where the original string can be returned, the frozen string loaded from the yaml can now be returned.

image

Workaround: For now, we will version pin to the prior version, v1.12.0

bboerkoel commented 1 year ago

If you use gettext_i18n_rails you can update that to version 1.10.1+, then it's fixed by: https://github.com/grosser/gettext_i18n_rails/pull/196

Easiest way to fix this for v1.13.0 might be to add a .dup since it doesn't copy the attributes. Or more explicitely withclone(freeze: false)

interpolated ? interpolated_string : string.dup
mfechner commented 1 year ago

Thanks, I tried this fix and it solves a problem with gitlab which stops working on some pages if i18n 1.13.0 is installed.

kbrock commented 1 year ago

alternatively, can you just always return interpolated_string?

Can you provide a test to reproduce?

(I'm not a committer, so feel free to ignore my suggestions)