Commit 2c4f9b7a authored by Bob Van Landuyt's avatar Bob Van Landuyt

Check for newlines in different methods on TranslationEntry

parent f35a5d0d
...@@ -71,11 +71,15 @@ module Gitlab ...@@ -71,11 +71,15 @@ module Gitlab
end end
def validate_newlines(errors, entry) 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." errors << "is defined over multiple lines, this breaks some tooling."
end 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." errors << "has translations defined over multiple lines, this breaks some tooling."
end end
end end
......
...@@ -47,6 +47,18 @@ module Gitlab ...@@ -47,6 +47,18 @@ module Gitlab
!plural? || all_translations.size > 1 !plural? || all_translations.size > 1
end 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 private
def plural_translation_keys def plural_translation_keys
......
...@@ -39,3 +39,10 @@ msgstr[2] "" ...@@ -39,3 +39,10 @@ msgstr[2] ""
"with" "with"
"multiple" "multiple"
"lines" "lines"
msgid "multiline plural id"
msgid_plural ""
"Plural"
"Id"
msgstr[0] "first"
msgstr[1] "second"
...@@ -46,6 +46,13 @@ describe Gitlab::I18n::PoLinter do ...@@ -46,6 +46,13 @@ describe Gitlab::I18n::PoLinter do
expect(errors[message_id]).to include(expected_message) expect(errors[message_id]).to include(expected_message)
end 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 end
context 'with an invalid po' do context 'with an invalid po' do
......
...@@ -103,4 +103,31 @@ describe Gitlab::I18n::TranslationEntry do ...@@ -103,4 +103,31 @@ describe Gitlab::I18n::TranslationEntry do
expect(entry).not_to have_singular expect(entry).not_to have_singular
end end
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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment