Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance: remove unnecessary i18n locale reload #2723

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Dir.glob(File.join(mydir, 'helpers', '*.rb')).sort.each { |file| require file }

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

module Faker
module Config
Expand Down
42 changes: 42 additions & 0 deletions test/test_i18n_reload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require 'test_helper'
require 'open3'

class TestI18nLoad < Test::Unit::TestCase
def test_faker_i18n
# run this code in a subshell to test require faker
# and proper initialization of i18n.
code = <<-RUBY
require 'bundler/inline'

gemfile do
source 'https://rubygems.org'
gem 'minitest'
gem 'i18n'
end

require 'minitest/autorun'
require 'i18n'

class TestI18nLoad < Minitest::Test
def test_faker_i18n
I18n.available_locales = [:en]
refute_predicate I18n.backend, :initialized?
I18n.translate('doesnt matter just triggering a lookup')

assert_predicate I18n.backend, :initialized?

assert require File.expand_path('#{File.dirname(__FILE__)}/../lib/faker')

assert Faker::Name.name
end
end
RUBY

cmd = %( ruby -e "#{code}" )
output, status = Open3.capture2e(cmd)

assert_equal 0, status, output
end
end