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

Test that all locales have a translated language name

Christophe Bliard6d857c629987
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 45881a7b8a6..5287989507b 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -29,9 +29,6 @@
require 'spec_helper'
describe ApplicationHelper do
- include ApplicationHelper
- include WorkPackagesHelper
-
describe '.link_to_if_authorized' do
let(:project) { create :valid_project }
let(:project_member) do
@@ -175,4 +172,48 @@ describe ApplicationHelper do
end
end
end
+
+ describe '.all_lang_options_for_select' do
+ it 'has all languages translated ("English" should appear only once)' do
+ impostor_locales =
+ all_lang_options_for_select(false)
+ .reject { |_lang, locale| locale == 'en' }
+ .select { |lang, _locale| lang == "English" }
+ .map { |_lang, locale| locale }
+ expect(impostor_locales.count).to eq(0), <<~ERR
+ The locales #{impostor_locales.to_sentence} display themselves as "English"!
+
+ Probably because new languages were added, and the translation for their language is not
+ available, so it fallbacks to the English translation.
+
+ To fix it, generate translation files from CLDR by running
+
+ script/i18n/generate_languages_translations
+
+ And commit the yml files added in "config/locales/generated/*.yml".
+ ERR
+ end
+
+ it 'has distinct languages translation' do
+ duplicate_langs =
+ all_lang_options_for_select(false)
+ .map { |lang, _locale| lang }
+ .tally
+ .reject { |_lang, count| count == 1 }
+ .map { |lang, _count| lang }
+ duplicate_options =
+ all_lang_options_for_select(false)
+ .filter { |lang, _locale| duplicate_langs.include?(lang) }
+ .sort
+
+ expect(duplicate_options.count).to eq(0), <<~ERR
+ Some identical language names are used for different locales!
+
+ duplicates: #{duplicate_options}
+
+ To fix it, inspect translation files located in "config/locales/generated/*.yml".
+ You can also try running the script "script/i18n/generate_languages_translations".
+ ERR
+ end
+ end
end