i18n icon indicating copy to clipboard operation
i18n copied to clipboard

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

Open jcw- opened this issue 2 years ago • 3 comments

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

jcw- avatar May 19 '23 06:05 jcw-

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

bboerkoel avatar May 22 '23 09:05 bboerkoel

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.

mfechner avatar Jun 02 '23 09:06 mfechner

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)

kbrock avatar Jun 02 '23 15:06 kbrock