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
path: root/spec
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-08-31 14:39:41 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2017-08-31 22:13:02 +0300
commitabe198723d76cea1b7f151a15789d26a3d22ad4d (patch)
tree82cb60da4a5528bf1166e8e2091a921c8ccb5d7f /spec
parent2c4f9b7a73cf5de875b2c77880c040e845960a9a (diff)
Take `nplurals` into account when validating translations.
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/missing_metadata.po4
-rw-r--r--spec/lib/gitlab/i18n/metadata_entry_spec.rb23
-rw-r--r--spec/lib/gitlab/i18n/po_entry_spec.rb18
-rw-r--r--spec/lib/gitlab/i18n/po_linter_spec.rb48
-rw-r--r--spec/lib/gitlab/i18n/translation_entry_spec.rb40
5 files changed, 76 insertions, 57 deletions
diff --git a/spec/fixtures/missing_metadata.po b/spec/fixtures/missing_metadata.po
new file mode 100644
index 00000000000..b1999c933f1
--- /dev/null
+++ b/spec/fixtures/missing_metadata.po
@@ -0,0 +1,4 @@
+msgid "1 commit"
+msgid_plural "%d commits"
+msgstr[0] "1 cambio"
+msgstr[1] "%d cambios"
diff --git a/spec/lib/gitlab/i18n/metadata_entry_spec.rb b/spec/lib/gitlab/i18n/metadata_entry_spec.rb
index 5bc16e1806e..ab71d6454a9 100644
--- a/spec/lib/gitlab/i18n/metadata_entry_spec.rb
+++ b/spec/lib/gitlab/i18n/metadata_entry_spec.rb
@@ -24,5 +24,28 @@ describe Gitlab::I18n::MetadataEntry do
expect(entry.expected_plurals).to eq(2)
end
+
+ it 'returns 0 for the POT-metadata' do
+ data = {
+ msgid: "",
+ msgstr: [
+ "",
+ "Project-Id-Version: gitlab 1.0.0\\n",
+ "Report-Msgid-Bugs-To: \\n",
+ "PO-Revision-Date: 2017-07-13 12:10-0500\\n",
+ "Language-Team: Spanish\\n",
+ "Language: es\\n",
+ "MIME-Version: 1.0\\n",
+ "Content-Type: text/plain; charset=UTF-8\\n",
+ "Content-Transfer-Encoding: 8bit\\n",
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n",
+ "Last-Translator: Bob Van Landuyt <bob@gitlab.com>\\n",
+ "X-Generator: Poedit 2.0.2\\n"
+ ]
+ }
+ entry = described_class.new(data)
+
+ expect(entry.expected_plurals).to eq(0)
+ end
end
end
diff --git a/spec/lib/gitlab/i18n/po_entry_spec.rb b/spec/lib/gitlab/i18n/po_entry_spec.rb
deleted file mode 100644
index 4be1b3d4383..00000000000
--- a/spec/lib/gitlab/i18n/po_entry_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'spec_helper'
-
-describe Gitlab::I18n::PoEntry do
- describe '.build' do
- it 'builds a metadata entry when the msgid is empty' do
- entry = described_class.build(msgid: '')
-
- expect(entry).to be_kind_of(Gitlab::I18n::MetadataEntry)
- end
-
- it 'builds a translation entry when the msgid is empty' do
- entry = described_class.build(msgid: 'Hello world')
-
- expect(entry).to be_kind_of(Gitlab::I18n::TranslationEntry)
- end
-
- end
-end
diff --git a/spec/lib/gitlab/i18n/po_linter_spec.rb b/spec/lib/gitlab/i18n/po_linter_spec.rb
index 0fa4e05c7b1..97a8c105264 100644
--- a/spec/lib/gitlab/i18n/po_linter_spec.rb
+++ b/spec/lib/gitlab/i18n/po_linter_spec.rb
@@ -69,6 +69,14 @@ describe Gitlab::I18n::PoLinter do
end
end
+ context 'with missing metadata' do
+ let(:po_path) { 'spec/fixtures/missing_metadata.po' }
+
+ it 'returns the an error' do
+ is_expected.to include('PO-syntax errors' => a_kind_of(Array))
+ end
+ end
+
context 'with a valid po' do
it 'parses the file' do
expect(linter).to receive(:parse_po).and_call_original
@@ -90,7 +98,7 @@ describe Gitlab::I18n::PoLinter do
context 'with missing plurals' do
let(:po_path) { 'spec/fixtures/missing_plurals.po' }
- it 'has no errors' do
+ it 'has errors' do
is_expected.not_to be_empty
end
end
@@ -136,8 +144,7 @@ describe Gitlab::I18n::PoLinter do
describe '#validate_entries' do
it 'keeps track of errors for entries' do
fake_invalid_entry = Gitlab::I18n::TranslationEntry.new(
- msgid: "Hello %{world}",
- msgstr: "Bonjour %{monde}"
+ { msgid: "Hello %{world}", msgstr: "Bonjour %{monde}" }, 2
)
allow(linter).to receive(:translation_entries) { [fake_invalid_entry] }
@@ -169,9 +176,8 @@ describe Gitlab::I18n::PoLinter do
allow(linter).to receive(:metadata_entry).and_return(fake_metadata)
fake_entry = Gitlab::I18n::TranslationEntry.new(
- msgid: 'the singular',
- msgid_plural: 'the plural',
- 'msgstr[0]' => 'the singular'
+ { msgid: 'the singular', msgid_plural: 'the plural', 'msgstr[0]' => 'the singular' },
+ 2
)
errors = []
@@ -183,27 +189,31 @@ describe Gitlab::I18n::PoLinter do
describe '#validate_variables' do
it 'validates both signular and plural in a pluralized string when the entry has a singular' do
- pluralized_entry = Gitlab::I18n::TranslationEntry.new({
- msgid: 'Hello %{world}',
- msgid_plural: 'Hello all %{world}',
- 'msgstr[0]' => 'Bonjour %{world}',
- 'msgstr[1]' => 'Bonjour tous %{world}'
- })
+ pluralized_entry = Gitlab::I18n::TranslationEntry.new(
+ { msgid: 'Hello %{world}',
+ msgid_plural: 'Hello all %{world}',
+ 'msgstr[0]' => 'Bonjour %{world}',
+ 'msgstr[1]' => 'Bonjour tous %{world}' },
+ 2
+ )
expect(linter).to receive(:validate_variables_in_message)
.with([], 'Hello %{world}', 'Bonjour %{world}')
+ .and_call_original
expect(linter).to receive(:validate_variables_in_message)
.with([], 'Hello all %{world}', 'Bonjour tous %{world}')
+ .and_call_original
linter.validate_variables([], pluralized_entry)
end
it 'only validates plural when there is no separate singular' do
- pluralized_entry = Gitlab::I18n::TranslationEntry.new({
- msgid: 'Hello %{world}',
- msgid_plural: 'Hello all %{world}',
- 'msgstr[0]' => 'Bonjour %{world}'
- })
+ pluralized_entry = Gitlab::I18n::TranslationEntry.new(
+ { msgid: 'Hello %{world}',
+ msgid_plural: 'Hello all %{world}',
+ 'msgstr[0]' => 'Bonjour %{world}' },
+ 1
+ )
expect(linter).to receive(:validate_variables_in_message)
.with([], 'Hello all %{world}', 'Bonjour %{world}')
@@ -213,8 +223,8 @@ describe Gitlab::I18n::PoLinter do
it 'validates the message variables' do
entry = Gitlab::I18n::TranslationEntry.new(
- msgid: 'Hello',
- msgstr: 'Bonjour'
+ { msgid: 'Hello', msgstr: 'Bonjour' },
+ 2
)
expect(linter).to receive(:validate_variables_in_message)
diff --git a/spec/lib/gitlab/i18n/translation_entry_spec.rb b/spec/lib/gitlab/i18n/translation_entry_spec.rb
index e48ba28be0e..d2d3ec03c6d 100644
--- a/spec/lib/gitlab/i18n/translation_entry_spec.rb
+++ b/spec/lib/gitlab/i18n/translation_entry_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::I18n::TranslationEntry do
describe '#singular_translation' do
it 'returns the normal `msgstr` for translations without plural' do
data = { msgid: 'Hello world', msgstr: 'Bonjour monde' }
- entry = described_class.new(data)
+ entry = described_class.new(data, 2)
expect(entry.singular_translation).to eq('Bonjour monde')
end
@@ -16,7 +16,7 @@ describe Gitlab::I18n::TranslationEntry do
'msgstr[0]' => 'Bonjour monde',
'msgstr[1]' => 'Bonjour mondes'
}
- entry = described_class.new(data)
+ entry = described_class.new(data, 2)
expect(entry.singular_translation).to eq('Bonjour monde')
end
@@ -25,7 +25,7 @@ describe Gitlab::I18n::TranslationEntry do
describe '#all_translations' do
it 'returns all translations for singular translations' do
data = { msgid: 'Hello world', msgstr: 'Bonjour monde' }
- entry = described_class.new(data)
+ entry = described_class.new(data, 2)
expect(entry.all_translations).to eq(['Bonjour monde'])
end
@@ -37,7 +37,7 @@ describe Gitlab::I18n::TranslationEntry do
'msgstr[0]' => 'Bonjour monde',
'msgstr[1]' => 'Bonjour mondes'
}
- entry = described_class.new(data)
+ entry = described_class.new(data, 2)
expect(entry.all_translations).to eq(['Bonjour monde', 'Bonjour mondes'])
end
@@ -50,7 +50,7 @@ describe Gitlab::I18n::TranslationEntry do
msgid_plural: 'Hello worlds',
'msgstr[0]' => 'Bonjour monde'
}
- entry = described_class.new(data)
+ entry = described_class.new(data, 1)
expect(entry.plural_translations).to eq(['Bonjour monde'])
end
@@ -63,21 +63,21 @@ describe Gitlab::I18n::TranslationEntry do
'msgstr[1]' => 'Bonjour mondes',
'msgstr[2]' => 'Bonjour tous les mondes'
}
- entry = described_class.new(data)
+ entry = described_class.new(data, 3)
expect(entry.plural_translations).to eq(['Bonjour mondes', 'Bonjour tous les mondes'])
end
end
- describe '#has_singular?' do
+ describe '#has_singular_translation?' do
it 'has a singular when the translation is not pluralized' do
data = {
msgid: 'hello world',
msgstr: 'hello'
}
- entry = described_class.new(data)
+ entry = described_class.new(data, 2)
- expect(entry).to have_singular
+ expect(entry).to have_singular_translation
end
it 'has a singular when plural and singular are separately defined' do
@@ -87,9 +87,9 @@ describe Gitlab::I18n::TranslationEntry do
"msgstr[0]" => 'hello world',
"msgstr[1]" => 'hello worlds'
}
- entry = described_class.new(data)
+ entry = described_class.new(data, 2)
- expect(entry).to have_singular
+ expect(entry).to have_singular_translation
end
it 'does not have a separate singular if the plural string only has one translation' do
@@ -98,34 +98,34 @@ describe Gitlab::I18n::TranslationEntry do
msgid_plural: 'hello worlds',
"msgstr[0]" => 'hello worlds'
}
- entry = described_class.new(data)
+ entry = described_class.new(data, 1)
- expect(entry).not_to have_singular
+ expect(entry).not_to have_singular_translation
end
end
- describe '#msgid_contains_newlines'do
+ 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)
+ entry = described_class.new(data, 2)
expect(entry.msgid_contains_newlines?).to be_truthy
end
end
- describe '#plural_id_contains_newlines'do
+ 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)
+ data = { msgid_plural: %w(hello world) }
+ entry = described_class.new(data, 2)
expect(entry.plural_id_contains_newlines?).to be_truthy
end
end
- describe '#translations_contain_newlines'do
+ 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)
+ entry = described_class.new(data, 2)
expect(entry.translations_contain_newlines?).to be_truthy
end