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

fix I18n.load_path injection #546

Merged
merged 3 commits into from
May 30, 2024
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Removed use of `delegate` method added in [66f1d797](https://github.com/ice-cube-ruby/ice_cube/commit/66f1d797092734563bfabd2132c024c7d087f683) , reverting to previous implementation. ([#522](https://github.com/ice-cube-ruby/ice_cube/pull/522)) by [@pacso](https://github.com/pacso)
- Updated supported versions of Ruby and Rails and fixed standardrb lint issues. ([#552](https://github.com/ice-cube-ruby/ice_cube/pull/552)) by [@pacso](https://github.com/pacso)
- Fixed `I18n.load_path` injection ([#546](https://github.com/ice-cube-ruby/ice_cube/pull/546)) by [@glaszig](https://github.com/glaszig)

### Fixed
- Fix for weekly interval results when requesting `occurrences_between` on a narrow range ([#487](https://github.com/seejohnrun/ice_cube/pull/487)) by [@jakebrady5](https://github.com/jakebrady5)
Expand Down
3 changes: 2 additions & 1 deletion lib/ice_cube.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module IceCube

autoload :TimeUtil, "ice_cube/time_util"
autoload :FlexibleHash, "ice_cube/flexible_hash"
autoload :I18n, "ice_cube/i18n"

require "ice_cube/i18n"

autoload :Rule, "ice_cube/rule"
autoload :Schedule, "ice_cube/schedule"
Expand Down
31 changes: 10 additions & 21 deletions lib/ice_cube/i18n.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
require "ice_cube/null_i18n"

module IceCube
module I18n
LOCALES_PATH = File.expand_path(File.join("..", "..", "..", "config", "locales"), __FILE__)

def self.t(*args, **kwargs)
backend.t(*args, **kwargs)
end

def self.l(*args, **kwargs)
backend.l(*args, **kwargs)
end

def self.backend
@backend ||= detect_backend!
end

def self.detect_backend!
::I18n.load_path += Dir[File.join(LOCALES_PATH, "*.yml")]
::I18n
rescue NameError
NullI18n
end
LOCALES_PATH = File.expand_path(File.join("..", "..", "config", "locales"), __dir__)

# rubocop:disable Naming/ConstantName
I18n = begin
require "i18n"
::I18n.load_path += Dir[File.join(LOCALES_PATH, "*.yml")]
::I18n
rescue LoadError
NullI18n
end
# rubocop:enable Naming/ConstantName
end
2 changes: 1 addition & 1 deletion spec/examples/to_s_en_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
before(:each) { I18n.locale = :en }

it "uses I18n" do
expect(IceCube::I18n.backend).to eq(I18n)
expect(IceCube::I18n).to eq ::I18n
end

it_behaves_like "to_s in English"
Expand Down
Loading