diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2019-06-20 08:41:34 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2019-06-20 08:41:34 +0000 |
commit | 3878f39216297988e70425f89ab841a32f57aed9 (patch) | |
tree | 1afb2c1ab9fd42a18050c1c44566725b1aaf61d7 /lib/redmine | |
parent | 638dbbea95559852d00b4fe149a0ce19cd6c41d8 (diff) | |
download | redmine-3878f39216297988e70425f89ab841a32f57aed9.tar.gz redmine-3878f39216297988e70425f89ab841a32f57aed9.zip |
Removes lazy loading of i18n files for 18n 1.6.0 compat (#31384).
git-svn-id: http://svn.redmine.org/redmine/trunk@18286 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r-- | lib/redmine/i18n.rb | 56 |
1 files changed, 1 insertions, 55 deletions
diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb index 7756b4975..5621be68c 100644 --- a/lib/redmine/i18n.rb +++ b/lib/redmine/i18n.rb @@ -147,71 +147,17 @@ module Redmine end # Custom backend based on I18n::Backend::Simple with the following changes: - # * lazy loading of translation files # * available_locales are determined by looking at translation file names - class Backend - (class << self; self; end).class_eval { public :include } - + class Backend < ::I18n::Backend::Simple module Implementation - include ::I18n::Backend::Base include ::I18n::Backend::Pluralization - # Stores translations for the given locale in memory. - # This uses a deep merge for the translations hash, so existing - # translations will be overwritten by new ones only at the deepest - # level of the hash. - def store_translations(locale, data, options = {}) - locale = locale.to_sym - translations[locale] ||= {} - data = data.deep_symbolize_keys - translations[locale].deep_merge!(data) - end - # Get available locales from the translations filenames def available_locales @available_locales ||= ::I18n.load_path.map {|path| File.basename(path, '.*')}.uniq.sort.map(&:to_sym) end - - # Clean up translations - def reload! - @translations = nil - @available_locales = nil - super - end - - protected - - def init_translations(locale) - locale = locale.to_s - paths = ::I18n.load_path.select {|path| File.basename(path, '.*') == locale} - load_translations(paths) - translations[locale] ||= {} - end - - def translations - @translations ||= {} - end - - # Looks up a translation from the translations hash. Returns nil if - # eiher key is nil, or locale, scope or key do not exist as a key in the - # nested translations hash. Splits keys or scopes containing dots - # into multiple keys, i.e. <tt>currency.format</tt> is regarded the same as - # <tt>%w(currency format)</tt>. - def lookup(locale, key, scope = [], options = {}) - init_translations(locale) unless translations.key?(locale) - keys = ::I18n.normalize_keys(locale, key, scope, options[:separator]) - - keys.inject(translations) do |result, _key| - _key = _key.to_sym - return nil unless result.is_a?(Hash) && result.has_key?(_key) - result = result[_key] - result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol) - result - end - end end - include Implementation # Adds fallback to default locale for untranslated strings include ::I18n::Backend::Fallbacks end |