Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-08-30 10:53:23 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2017-08-31 22:13:02 +0300
commit2c4f9b7a73cf5de875b2c77880c040e845960a9a (patch)
tree8e4bdd898c7ca19d2eded2ca1fd27bdb2be873c0
parentf35a5d0d9919810b14d95808f099a3c652fb17b9 (diff)
Check for newlines in different methods on TranslationEntry
-rw-r--r--lib/gitlab/i18n/po_linter.rb8
-rw-r--r--lib/gitlab/i18n/translation_entry.rb12
-rw-r--r--spec/fixtures/newlines.po7
-rw-r--r--spec/lib/gitlab/i18n/po_linter_spec.rb7
-rw-r--r--spec/lib/gitlab/i18n/translation_entry_spec.rb27
5 files changed, 59 insertions, 2 deletions
diff --git a/lib/gitlab/i18n/po_linter.rb b/lib/gitlab/i18n/po_linter.rb
index 0dc96ac7b9b..f5ffc6669e4 100644
--- a/lib/gitlab/i18n/po_linter.rb
+++ b/lib/gitlab/i18n/po_linter.rb
@@ -71,11 +71,15 @@ module Gitlab
end
def validate_newlines(errors, entry)
- if entry.msgid.is_a?(Array)
+ if entry.msgid_contains_newlines?
errors << "is defined over multiple lines, this breaks some tooling."
end
- if entry.all_translations.any? { |translation| translation.is_a?(Array) }
+ if entry.plural_id_contains_newlines?
+ errors << "plural is defined over multiple lines, this breaks some tooling."
+ end
+
+ if entry.translations_contain_newlines?
errors << "has translations defined over multiple lines, this breaks some tooling."
end
end
diff --git a/lib/gitlab/i18n/translation_entry.rb b/lib/gitlab/i18n/translation_entry.rb
index 98095177994..4fe8f569f9c 100644
--- a/lib/gitlab/i18n/translation_entry.rb
+++ b/lib/gitlab/i18n/translation_entry.rb
@@ -47,6 +47,18 @@ module Gitlab
!plural? || all_translations.size > 1
end
+ def msgid_contains_newlines?
+ msgid.is_a?(Array)
+ end
+
+ def plural_id_contains_newlines?
+ plural_id.is_a?(Array)
+ end
+
+ def translations_contain_newlines?
+ all_translations.any? { |translation| translation.is_a?(Array) }
+ end
+
private
def plural_translation_keys
diff --git a/spec/fixtures/newlines.po b/spec/fixtures/newlines.po
index 773d9b23db8..f5bc86f39a7 100644
--- a/spec/fixtures/newlines.po
+++ b/spec/fixtures/newlines.po
@@ -39,3 +39,10 @@ msgstr[2] ""
"with"
"multiple"
"lines"
+
+msgid "multiline plural id"
+msgid_plural ""
+"Plural"
+"Id"
+msgstr[0] "first"
+msgstr[1] "second"
diff --git a/spec/lib/gitlab/i18n/po_linter_spec.rb b/spec/lib/gitlab/i18n/po_linter_spec.rb
index c40e8ff63bb..0fa4e05c7b1 100644
--- a/spec/lib/gitlab/i18n/po_linter_spec.rb
+++ b/spec/lib/gitlab/i18n/po_linter_spec.rb
@@ -46,6 +46,13 @@ describe Gitlab::I18n::PoLinter do
expect(errors[message_id]).to include(expected_message)
end
+
+ it 'raises an error when the plural id is defined over multiple lines' do
+ message_id = 'multiline plural id'
+ expected_message = "plural is defined over multiple lines, this breaks some tooling."
+
+ expect(errors[message_id]).to include(expected_message)
+ end
end
context 'with an invalid po' do
diff --git a/spec/lib/gitlab/i18n/translation_entry_spec.rb b/spec/lib/gitlab/i18n/translation_entry_spec.rb
index 7d97942a1d5..e48ba28be0e 100644
--- a/spec/lib/gitlab/i18n/translation_entry_spec.rb
+++ b/spec/lib/gitlab/i18n/translation_entry_spec.rb
@@ -103,4 +103,31 @@ describe Gitlab::I18n::TranslationEntry do
expect(entry).not_to have_singular
end
end
+
+ describe '#msgid_contains_newlines'do
+ it 'is true when the msgid is an array' do
+ data = { msgid: %w(hello world) }
+ entry = described_class.new(data)
+
+ expect(entry.msgid_contains_newlines?).to be_truthy
+ end
+ end
+
+ describe '#plural_id_contains_newlines'do
+ it 'is true when the msgid is an array' do
+ data = { plural_id: %w(hello world) }
+ entry = described_class.new(data)
+
+ expect(entry.plural_id_contains_newlines?).to be_truthy
+ end
+ end
+
+ describe '#translations_contain_newlines'do
+ it 'is true when the msgid is an array' do
+ data = { msgstr: %w(hello world) }
+ entry = described_class.new(data)
+
+ expect(entry.translations_contain_newlines?).to be_truthy
+ end
+ end
end