ruby-i18n/i18n

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

jcw- opened this issue · 3 comments

jcw- commented

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: be2f3a0

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

If you use gettext_i18n_rails you can update that to version 1.10.1+, then it's fixed by: grosser/gettext_i18n_rails#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

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

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)