Skip to content

Conversation

@lee266
Copy link

@lee266 lee266 commented Oct 3, 2025

Related issue: #723

Summary

This PR fixes an issue where I18n.locale is unexpectedly reset when entering a new Fiber context.

Currently, I18n stores its configuration with Thread.current[:i18n_config].
However, in Ruby, Thread.current[:key] is fiber-local, not strictly thread-local.
As a result, each Fiber gets its own isolated config, and I18n.locale falls back to default_locale inside new Fibers.

Fix

Switch to Thread#thread_variable_get/set, which provides true thread-local storage and is inherited by Fibers.

…le_{get,set}

- Change I18n.config storage from Thread.current[:i18n_config] to
  Thread.current.thread_variable_get/set, which is inherited by Fibers
- Update I18n.config= and middleware to use thread_variable_set
- Update tests to verify I18n.locale preservation in Fiber context
@lee266 lee266 changed the title Fix I18n.locale reset in Fiber context by using Thread#thread_variaable Fix I18n.locale reset in Fiber context by using Thread#thread_variable Oct 3, 2025
@lee266 lee266 changed the title Fix I18n.locale reset in Fiber context by using Thread#thread_variable Fix: I18n.locale reset in Fiber context by using Thread#thread_variable Oct 3, 2025
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

Successfully merging this pull request may close these issues.

1 participant