-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix I18n.load_path injection ice_cube would inject its locale files at the end of `I18n.load_path` due to its `IceCube::I18n` module being `autoload`ed and thereby overwrite any customisation the user may have made in other locale files earlier in the load path. i fix this by injecting ice cube locales at gem load time so that the user has a chance to modify locale keys later. this also eliminates a bunch of delegation having a custom I18n module; `IceCube::I18n` is just the same as ::I18n if the i18n gem is available. resolves #489, #432, #431 * use __dir__ expansion instead of __FILE__ * disable linter for I18n gymnastics
- Loading branch information
Showing
4 changed files
with
14 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters