Skip to content

Commit

Permalink
Rollback PR #2169 and bump 2.15.1 (#2203)
Browse files Browse the repository at this point in the history
* Rollback PR #2169

* Add changelog

* Bump version to 2.15.1
  • Loading branch information
vbrazo committed Nov 25, 2020
1 parent aaf047c commit 2b52e7a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 43 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Change Log

## [v2.15.1](https://github.com/faker-ruby/faker/tree/v2.15.1) (2020-11-24)

- Rollback PR #2169 and bump 2.15.1 [#2203](https://github.com/faker-ruby/faker/pull/2203) @vbrazo

------------------------------------------------------------------------------

## [v2.15.0](https://github.com/faker-ruby/faker/tree/v2.15.0) (2020-11-24)

## Bug/Fixes
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
faker (2.15.0)
faker (2.15.1)
i18n (>= 1.6, < 2)

GEM
Expand Down
29 changes: 3 additions & 26 deletions lib/faker.rb
Expand Up @@ -8,27 +8,10 @@

Dir.glob(File.join(mydir, 'helpers', '*.rb')).sort.each { |file| require file }

module Faker
@i18n_loaded = nil

class << self
def load_i18n
return if @i18n_loaded

if I18n.available_locales&.any?
# We expect all locale .yml files to have the locale name in its filename
I18n.load_path += ::Dir[::File.join(__dir__, 'locales', "{#{I18n.available_locales.join(',')}}.yml")]
# Or to be located in a directory with the locale name
I18n.load_path += ::Dir[::File.join(__dir__, 'locales', "{#{I18n.available_locales.join(',')}}/*.yml")]
else
I18n.load_path += ::Dir[::File.join(__dir__, 'locales', '**/*.yml')]
end

I18n.reload! if I18n.backend.initialized?
@i18n_loaded = true
end
end
I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')]
I18n.reload! if I18n.backend.initialized?

module Faker
module Config
@locale = nil
@random = nil
Expand All @@ -37,8 +20,6 @@ class << self
attr_writer :locale, :random

def locale
Faker.load_i18n

# Because I18n.locale defaults to :en, if we don't have :en in our available_locales, errors will happen
@locale || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first)
end
Expand Down Expand Up @@ -168,8 +149,6 @@ def parse(key)
# Call I18n.translate with our configured locale if no
# locale is specified
def translate(*args, **opts)
Faker.load_i18n

opts[:locale] ||= Faker::Config.locale
opts[:raise] = true
I18n.translate(*args, **opts)
Expand All @@ -186,8 +165,6 @@ def translate(*args, **opts)

# Executes block with given locale set.
def with_locale(tmp_locale = nil, &block)
Faker.load_i18n

current_locale = Faker::Config.own_locale
Faker::Config.locale = tmp_locale

Expand Down
2 changes: 1 addition & 1 deletion lib/faker/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Faker #:nodoc:
VERSION = '2.15.0'
VERSION = '2.15.1'
end
15 changes: 0 additions & 15 deletions test/test_locale.rb
Expand Up @@ -78,19 +78,4 @@ def test_regex
def test_available_locales
assert I18n.locale_available?('en-GB')
end

def test_load_i18n
Faker.instance_variable_set :@i18n_loaded, nil
available_locales_was = I18n.available_locales

I18n.available_locales = %i[en ja id]
Faker.load_i18n
I18n.eager_load!

assert Faker.instance_variable_get(:@i18n_loaded)
assert_equal %i[en id ja], I18n.backend.translations.keys.sort
ensure
I18n.available_locales = available_locales_was
Faker.instance_variable_set :@i18n_loaded, nil
end
end

0 comments on commit 2b52e7a

Please sign in to comment.