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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[48451] Include default language in valid languages
Christophe Bliard52303a1fe96f
diff --git a/app/components/settings/text_setting_component.html.erb b/app/components/settings/text_setting_component.html.erbindex 4347267e48e..30677e5cc7a 100644--- a/app/components/settings/text_setting_component.html.erb+++ b/app/components/settings/text_setting_component.html.erb@@ -45,7 +45,7 @@ See COPYRIGHT and LICENSE files for more details.</div></div>-<% Setting.available_languages.each do |lang| %>+<% Redmine::I18n.valid_languages.each do |lang| %><%=hidden_field_tag("settings[#{name}][#{lang}]",diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex 06b068c61c3..118a59e423c 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -212,7 +212,7 @@ class ApplicationController < ActionController::Baseenddef reset_i18n_fallbacks- fallbacks = [I18n.default_locale] + Setting.available_languages.map(&:to_sym)+ fallbacks = [I18n.default_locale] + Redmine::I18n.valid_languages.map(&:to_sym)return if I18n.fallbacks.defaults == fallbacksI18n.fallbacks = nildiff --git a/config/initializers/i18n.rb b/config/initializers/i18n.rbindex 1382533fd72..03cbf2356e8 100644--- a/config/initializers/i18n.rb+++ b/config/initializers/i18n.rb@@ -11,7 +11,7 @@ Rails.application.reloader.to_prepare do# 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 + Setting.available_languages.map(&:to_sym)+ defaults = Set.new(I18n.fallbacks.defaults + Redmine::I18n.valid_languages.map(&:to_sym))I18n.fallbacks.defaults = defaultsendenddiff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rbindex 5f1901598ef..49d7a6c56b6 100644--- a/lib_static/redmine/i18n.rb+++ b/lib_static/redmine/i18n.rb@@ -45,6 +45,10 @@ module Redmine.sortend+ def self.valid_languages+ all_languages & (Setting.available_languages + [Setting.default_language])+ end+def l_or_humanize(s, options = {})k = "#{options[:prefix]}#{s}".to_sym::I18n.t(k, default: s.to_s.humanize)@@ -152,7 +156,7 @@ module Redmineenddef valid_languages- all_languages & Setting.available_languages+ Redmine::I18n.valid_languagesenddef all_languagesdiff --git a/spec/features/auth/omniauth_spec.rb b/spec/features/auth/omniauth_spec.rbindex 85f464ebad7..3ca237e7590 100644--- a/spec/features/auth/omniauth_spec.rb+++ b/spec/features/auth/omniauth_spec.rb@@ -175,8 +175,7 @@ RSpec.describe 'Omniauth authentication' docontext 'register on the fly',with_settings: {self_registration?: true,- self_registration: Setting::SelfRegistration.automatic,- available_languages: ['en']+ self_registration: Setting::SelfRegistration.automatic} dolet(:user) doUser.new(force_password_change: false,diff --git a/spec/features/localization_spec.rb b/spec/features/localization_spec.rbindex 30faf36a478..a21ccc20f3a 100644--- a/spec/features/localization_spec.rb+++ b/spec/features/localization_spec.rb@@ -31,20 +31,28 @@ require 'spec_helper'RSpec.describe 'Localization', with_settings: { login_required?: false,available_languages: %w[de en],default_language: 'en' } do- it 'set localization' do- Capybara.current_session.driver.header('Accept-Language', 'de,de-de;q=0.8,en-us;q=0.5,en;q=0.3')+ context 'with a HTTP header Accept-Language having a valid supported language' do+ before do+ Capybara.current_session.driver.header('Accept-Language', 'de,de-de;q=0.8,en-us;q=0.5,en;q=0.3')+ end- # a french user- visit projects_path+ it 'uses the language from HTTP header Accept-Language' do+ visit projects_path- expect(page)- .to have_content('Projekte')+ expect(page)+ .to have_content('Projekte')+ end+ end++ context 'with a HTTP header Accept-Language having an unsupported language' do+ before do+ Capybara.current_session.driver.header('Accept-Language', 'zz')+ end- # not a supported language: default language should be used- Capybara.current_session.driver.header('Accept-Language', 'zz')- visit projects_path+ it 'uses the default language configured in administration' do+ visit projects_path- expect(page)- .to have_content('Projects')+ expect(page).to have_content('Projects')+ endendenddiff --git a/spec/lib/redmine/i18n_spec.rb b/spec/lib/redmine/i18n_spec.rbindex 3331f9b3213..4057fa8a710 100644--- a/spec/lib/redmine/i18n_spec.rb+++ b/spec/lib/redmine/i18n_spec.rb@@ -97,17 +97,31 @@ module OpenProjectenddescribe 'valid_languages' do- it 'allows only languages that are available' do+ it 'allows languages that are available' dowith_settings(available_languages: ['en'])expect(valid_languages).to eq ['en']end+ it 'allows language which is not in available languages list but is the default language' do+ with_settings(available_languages: ['en'], default_language: 'fr')++ expect(valid_languages).to eq ['en', 'fr']+ end+it 'allows only languages that exist' dowith_settings(available_languages: ['en', 'de', 'klingon'])expect(valid_languages).to contain_exactly('en', 'de')end++ it 'is sorted alphabetically' do+ with_settings(available_languages: ['de', 'en'], default_language: 'fr')+ expect(valid_languages).to eq(valid_languages.sort)++ with_settings(available_languages: ['en', 'fr'], default_language: 'de')+ expect(valid_languages).to eq(valid_languages.sort)+ endenddescribe 'set_language_if_valid' do@@ -141,11 +155,11 @@ module OpenProjectdescribe 'find_language' dobefore do- with_settings(available_languages: ['de'])+ with_settings(available_languages: ['de'], default_language: 'en')end- it 'is nil if language is not active' do- expect(find_language(:en)).to be_nil+ it 'is nil if language is not available nor the default language' do+ expect(find_language(:fr)).to be_nilendit 'is nil if no language is given' do@@ -153,14 +167,21 @@ module OpenProjectexpect(find_language(nil)).to be_nilend- it 'is the language if it is active' do+ it 'is the language if it is in available languages' doexpect(find_language(:de)).to eq 'de'expect(find_language('de')).to eq 'de'end- it 'can be found by uppercase if it is active' do+ it 'is the language if it is the default language' do+ expect(find_language(:en)).to eq 'en'+ expect(find_language('en')).to eq 'en'+ end++ it 'can be found by uppercase' doexpect(find_language(:DE)).to eq 'de'expect(find_language('DE')).to eq 'de'+ expect(find_language(:EN)).to eq 'en'+ expect(find_language('EN')).to eq 'en'endit 'is nil if non valid string is passed' do