FIX: I18n regression due to recent ruby-i18n update

In DEPS: Bump i18n from 1.14.8 to 1.15.2 - Pull Request #41242 - discourse/discourse - GitHub, we
updated the ruby-i18n to 1.15.x, however, this version has a defection.

Upstream Update Analysis

First, configuration is now stored on the Fiber:

Fiber[:i18n_config]

The new implementation detects when a Fiber inherited a configuration owned by another Fiber:

if current.respond_to?(:owned_by?) && !current.owned_by?(Fiber.current)
  current = current.dup
  Fiber[:i18n_config] = current
end

The problem is in I18n::Config#initialize_copy:

def initialize_copy(other)
  @owner = Fiber.current
end

It changes the owner of the copied configuration, but it does not clear the copied @locale, i.e., Child Fiber inherits parent’s explicit @locale.

So if the parent Fiber currently has:

I18n.locale == :zh_CN

a child Fiber can inherit a copied configuration that still contains:

@locale == :zh_CN

even though that child Fiber now represents a different request that should resolve to English.

This cause a problem in discourse. When the user is using a display language different from the default language. Say, Chinese as the site default language and English as the display language, pages may accidentally display in Chinese, or a combination of English and Chinese.

Raise a commit to rollback the version update and added some spec, maybe pausing the update until upstream fix that will be a great idea.

4 Likes

Thanks for the report, I’m having a look.

4 Likes