From 76a168b85eb0237179363e8ad8ff3317464802ab Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Fri, 21 Jul 2023 21:31:26 -0300 Subject: [PATCH] Fix locale setting (#2734) * Add back `@locale` class variable * Add thread unsafe `locale!` method * Update lib/faker.rb * Update lib/faker.rb * Update lib/faker.rb --------- Co-authored-by: Stefanni Brasil --- lib/faker.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/faker.rb b/lib/faker.rb index dbe8da6449..ad286e67f0 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -11,14 +11,18 @@ module Faker module Config + @default_locale = nil + class << self + attr_writer :default_locale + def locale=(new_locale) Thread.current[:faker_config_locale] = new_locale end def locale # Because I18n.locale defaults to :en, if we don't have :en in our available_locales, errors will happen - Thread.current[:faker_config_locale] || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first) + Thread.current[:faker_config_locale] || @default_locale || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first) end def own_locale