Commit 3b5ce694 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Validate PO-variable usage in message ids

That way we can detect incorrect usage before the strings are added to
Crowdin for translation
parent ca065e49
......@@ -109,10 +109,14 @@ module Gitlab
def validate_variables(errors, entry)
if entry.has_singular_translation?
validate_variables_in_message(errors, entry.msgid, entry.msgid)
validate_variables_in_message(errors, entry.msgid, entry.singular_translation)
end
if entry.has_plural?
validate_variables_in_message(errors, entry.plural_id, entry.plural_id)
entry.plural_translations.each do |translation|
validate_variables_in_message(errors, entry.plural_id, translation)
end
......
......@@ -220,6 +220,10 @@ describe Gitlab::I18n::PoLinter do
end
describe '#validate_variables' do
before do
allow(linter).to receive(:validate_variables_in_message).and_call_original
end
it 'validates both singular and plural in a pluralized string when the entry has a singular' do
pluralized_entry = fake_translation(
id: 'Hello %{world}',
......@@ -259,6 +263,24 @@ describe Gitlab::I18n::PoLinter do
linter.validate_variables([], entry)
end
it 'validates variable usage in message ids' do
entry = fake_translation(
id: 'Hello %{world}',
translation: 'Bonjour %{world}',
plural_id: 'Hello all %{world}',
plurals: ['Bonjour tous %{world}']
)
expect(linter).to receive(:validate_variables_in_message)
.with([], 'Hello %{world}', 'Hello %{world}')
.and_call_original
expect(linter).to receive(:validate_variables_in_message)
.with([], 'Hello all %{world}', 'Hello all %{world}')
.and_call_original
linter.validate_variables([], entry)
end
end
describe '#validate_variables_in_message' do
......
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