Skip to content

[BUG] I18n.fallbacks should not be mutable #717

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

Open
alexfiennes opened this issue Jun 6, 2025 · 0 comments
Open

[BUG] I18n.fallbacks should not be mutable #717

alexfiennes opened this issue Jun 6, 2025 · 0 comments

Comments

@alexfiennes
Copy link

What I tried to do

teamskills(dev)> I18n.locale
=> :en
teamskills(dev)> fallbacks = I18n.fallbacks[I18n.locale]
=> [:en, :"en-US"]
teamskills(dev)> fallbacks.concat([:wtf])
=> [:en, :"en-US", :wtf]
teamskills(dev)> I18n.fallbacks[I18n.locale]
=> [:en, :"en-US", :wtf]

What I expected to happen

I would either expect that the array that is returned from I18n.fallbacks is a dup of the original one so that I can mutate it without poisoning future requests, or that the array that is returned is frozen so that it can't be mutated.

I personally would prefer the frozen array so that we don't incur the overhead of duplicating the array on each request if we probably aren't going to mutate it.

I can make a PR once we have decided which behaviour we prefer.

What actually happened

The array that is returned is mutable and if I mutate it then the mutated array is returned for future requests.

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

i18n version 1.14.7
rails 7.2.2.1
ruby 3.4.2


Bonus points for providing an application or a small code example which reproduces the issue.

Thanks! ❤️

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