Check for newlines in different methods on TranslationEntry
This commit is contained in:
parent
f35a5d0d99
commit
2c4f9b7a73
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -39,3 +39,10 @@ msgstr[2] ""
|
|||
"with"
|
||||
"multiple"
|
||||
"lines"
|
||||
|
||||
msgid "multiline plural id"
|
||||
msgid_plural ""
|
||||
"Plural"
|
||||
"Id"
|
||||
msgstr[0] "first"
|
||||
msgstr[1] "second"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue