mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Do not use all available languages as i18n fallbacks
The files downloaded from Crowdin are always complete, and already fall back to english in the YML. We still need I18n fallback mechanism for at least 2 use cases: - during development when we are adding strings to the translation files and we are not using the English locale. (Only after crowdin took its turn, does a locale key exist everywhere) - for `Settings::Email#localized_emails_header` and `Settings::Email#localized_emails_footer`: translations are set by the admins and some languages do not have a localized version. We use the fallback mechanism to get translations from other locales if there is none for the current locale. As we have `:en` as the default locale, `I18n` automatically falls back to our default locale. No need to set `I18n.fallbacks.defaults` ourselves.
This commit is contained in:
@@ -152,7 +152,6 @@ class ApplicationController < ActionController::Base
|
||||
:tag_request,
|
||||
:check_if_login_required,
|
||||
:log_requesting_user,
|
||||
:reset_i18n_fallbacks,
|
||||
:check_session_lifetime,
|
||||
:stop_if_feeds_disabled,
|
||||
:set_cache_buster,
|
||||
@@ -224,14 +223,6 @@ class ApplicationController < ActionController::Base
|
||||
string.gsub(/[^0-9a-zA-Z@._\-"'!?=\/ ]{1}/, "#")
|
||||
end
|
||||
|
||||
def reset_i18n_fallbacks
|
||||
fallbacks = [I18n.default_locale] + Redmine::I18n.valid_languages.map(&:to_sym)
|
||||
return if I18n.fallbacks.defaults == fallbacks
|
||||
|
||||
I18n.fallbacks = nil
|
||||
I18n.fallbacks.defaults = fallbacks
|
||||
end
|
||||
|
||||
def set_localization
|
||||
# 1. Use completely authenticated user
|
||||
# 2. Use user with some authenticated stages not completed.
|
||||
|
||||
@@ -33,15 +33,13 @@
|
||||
require "open_project/translations/pluralization_backend"
|
||||
I18n::Backend::Simple.include OpenProject::Translations::PluralizationBackend
|
||||
|
||||
# Adds fallback to default locale for untranslated strings
|
||||
# Adds fallback to default locale for untranslated strings. Useful for instance
|
||||
# during development when adding new strings and using another locale than
|
||||
# English. For production, that's less useful as files downloaded from Crowdin
|
||||
# already contain fallback English translations.
|
||||
#
|
||||
# Also we can't completly remove the fallback mechanism: we still need the it to
|
||||
# get translated versions of email header and footer as they are supplied by the
|
||||
# admins and may not be provided for all configured languages. (See
|
||||
# `Setting#localized_emails_header` and `Setting#localized_emails_footer`.)
|
||||
I18n::Backend::Simple.include I18n::Backend::Fallbacks
|
||||
|
||||
Rails.application.reloader.to_prepare do
|
||||
# As we enabled +config.i18n.fallbacks+, Rails will fall back
|
||||
# to the default locale.
|
||||
# When other locales are available, fall back to them.
|
||||
if Setting.table_exists? # don't want to prevent migrations
|
||||
defaults = Set.new(I18n.fallbacks.defaults + Redmine::I18n.valid_languages.map(&:to_sym))
|
||||
I18n.fallbacks.defaults = defaults
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user