Commit 1da594d3 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Check newlines in translations

parent 973c6979
......@@ -61,6 +61,10 @@ module Gitlab
if entry[:msgid].is_a?(Array)
errors << "<#{message_id}> is defined over multiple lines, this breaks some tooling."
end
if translations_in_entry(entry).any? { |translation| translation.is_a?(Array) }
errors << "<#{message_id}> has translations defined over multiple lines, this breaks some tooling."
end
end
def validate_variables(errors, entry)
......@@ -172,5 +176,17 @@ module Gitlab
def join_message(message)
Array(message).join
end
def translations_in_entry(entry)
if entry[:msgid_plural].present?
entry.fetch_values(*plural_translation_keys_in_entry(entry))
else
[entry[:msgstr]]
end
end
def plural_translation_keys_in_entry(entry)
entry.keys.select { |key| key =~ /msgstr\[\d*\]/ }
end
end
end
......@@ -30,3 +30,12 @@ msgstr ""
"Va a eliminar %{group_name}.\n"
"¡El grupo eliminado NO puede ser restaurado!\n"
"¿Estás TOTALMENTE seguro?"
msgid "With plural"
msgid_plural "with plurals"
msgstr[0] "first"
msgstr[1] "second"
msgstr[2] ""
"with"
"multiple"
"lines"
......@@ -26,11 +26,25 @@ describe Gitlab::PoLinter do
context 'for a translations with newlines' do
let(:po_path) { 'spec/fixtures/newlines.po' }
it 'has an error' do
it 'has an error for a normal string' do
message_id = "You are going to remove %{group_name}.\\nRemoved groups CANNOT be restored!\\nAre you ABSOLUTELY sure?"
expected_message = "<#{message_id}> is defined over multiple lines, this breaks some tooling."
is_expected.to include(message_id => [expected_message])
expect(errors[message_id]).to include(expected_message)
end
it 'has an error when a translation is defined over multiple lines' do
message_id = "You are going to remove %{group_name}.\\nRemoved groups CANNOT be restored!\\nAre you ABSOLUTELY sure?"
expected_message = "<#{message_id}> has translations defined over multiple lines, this breaks some tooling."
expect(errors[message_id]).to include(expected_message)
end
it 'raises an error when a plural translation is defined over multiple lines' do
message_id = 'With plural'
expected_message = "<#{message_id}> has translations defined over multiple lines, this breaks some tooling."
expect(errors[message_id]).to include(expected_message)
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