Skip to content

Add a new I18n.isolation_scope= option to explicitly use threads or fibers#730

Closed
travisbell wants to merge 2 commits intoruby-i18n:masterfrom
travisbell:master
Closed

Add a new I18n.isolation_scope= option to explicitly use threads or fibers#730
travisbell wants to merge 2 commits intoruby-i18n:masterfrom
travisbell:master

Conversation

@travisbell
Copy link
Copy Markdown

After the update on #723 (#724) I18n became incompatible with web servers like Falcon, that serve every request in a new fiber. You can read my comment on that issue for a bit more context.

This PR introduces a new option called I18n.isolation_scope which allows you to configure where you'd like the instance of I18n::Config to be stored. By default it stays as a thread variable, but it can be changed to use fibers like so:

I18n.isolation_scope = :fiber

By using :fiber we store the config in a fiber local Fiber[:i18n_config] instead of thread local Thread.current.thread_variable_get.

@travisbell
Copy link
Copy Markdown
Author

P.S. I looked into using the value from ActiveSupport::IsolatedExecutionState.isolation_level but since ActiveSupport is not a hard requirement for I18n, I don't think it made sense. For any apps using fibers like this, they'll just need to set both values. That is, unless we add some complexity to the check.

@travisbell
Copy link
Copy Markdown
Author

Closing in favour of a more complete implementation: #731

@travisbell travisbell closed this Feb 23, 2026
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