Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use native I18n implementation of lazy loading of i18n data

Christophe Bliardf71b237580b4
diff --git a/spec/support/i18n_lazy_loading.rb b/spec/support/i18n_lazy_loading.rb
index 39a1e430df4..4e2768d1621 100644
--- a/spec/support/i18n_lazy_loading.rb
+++ b/spec/support/i18n_lazy_loading.rb
@@ -26,68 +26,6 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-# Restricts loaded locales to :en to avoid a 2-seconds penalty when locales are
-# loaded.
-#
-# Disable with +TEST_NO_I18N_LAZY_LOADING+ env variable.
-module I18nLazyLoading
- # Load additional locales when calling:
- #
- # - +Redmine::I18n#all_attribute_translations+
- # - +Redmine::I18n#ll+
- module RedmineI18nPatch
- def all_attribute_translations(locale)
- I18nLazyLoading.load_locale(locale)
- super
- end
- end
-
- # Load additional locales when calling:
- #
- # - +I18n.locale=+
- # - +Stringex::Localization.locale=+
- module I18nPatch
- def locale=(locale)
- I18nLazyLoading.load_locale(locale)
- super
- end
-
- def t(*args, **options)
- I18nLazyLoading.load_locale(options[:locale]) if options[:locale]
- super
- end
- end
-
- def self.install
- return if ENV["TEST_NO_I18N_LAZY_LOADING"].present?
- return if ENV["CI"].present?
- return if ENV["EAGER_LOAD"].present?
-
- # copy original I18n load path
- @@original_load_path = I18n.config.load_path.dup
- # restrict available locales to :en
- I18n.config.load_path = load_path(:en)
-
- # patch to load locales on demand
- Redmine::I18n.prepend(RedmineI18nPatch)
- I18n.singleton_class.prepend(I18nPatch)
- Stringex::Localization.singleton_class.prepend(I18nPatch)
- end
-
- def self.load_locale(locale)
- return if locale.nil?
- return if ::I18n.config.available_locales_set.include?(locale)
-
- I18n.backend.load_translations(load_path(locale))
- I18n.config.clear_available_locales_set
- end
-
- def self.load_path(locale)
- file_regex = /\/(js-)?#{locale}[.a-z]+$/i
- @@original_load_path.grep(file_regex)
- end
-end
-
-RSpec.configure do
- I18nLazyLoading.install
-end
+# Lazy loads translations based on the current locale.
+# It avoids a 2 to 4 seconds penalty when all locales are loaded.
+I18n.backend = I18n::Backend::LazyLoadable.new(lazy_load: true)