Skip to content

Commit

Permalink
Fix locale setting (#2734)
Browse files Browse the repository at this point in the history
* 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 <stefannibrasil@gmail.com>
  • Loading branch information
mateusdeap and stefannibrasil committed Jul 22, 2023
1 parent 56fc3c8 commit 76a168b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76a168b

Please sign in to comment.