summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-08-22 16:23:43 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-08-31 21:13:00 +0200
commit973c697960b9538222c5a83dfe643107313097cc (patch)
treee2a99fb0e90e80ebc104397ed5e39534caa83402
parentc34cf3a95286e46a23abdd567aedf2e4a6c72d5e (diff)
downloadgitlab-ce-973c697960b9538222c5a83dfe643107313097cc.tar.gz
Add spec for languages without plurals
-rw-r--r--lib/gitlab/po_linter.rb10
-rw-r--r--spec/fixtures/multiple_plurals.po26
-rw-r--r--spec/fixtures/no_plurals.po24
-rw-r--r--spec/lib/gitlab/po_linter_spec.rb16
4 files changed, 75 insertions, 1 deletions
diff --git a/lib/gitlab/po_linter.rb b/lib/gitlab/po_linter.rb
index 54594949711..721a111e2a0 100644
--- a/lib/gitlab/po_linter.rb
+++ b/lib/gitlab/po_linter.rb
@@ -66,7 +66,11 @@ module Gitlab
def validate_variables(errors, entry)
if entry[:msgid_plural].present?
validate_variables_in_message(errors, entry[:msgid], entry['msgstr[0]'])
- validate_variables_in_message(errors, entry[:msgid_plural], entry['msgstr[1]'])
+
+ # Validate all plurals
+ entry.keys.select { |key_name| key_name =~ /msgstr\[[1-9]\]/ }.each do |plural_key|
+ validate_variables_in_message(errors, entry[:msgid_plural], entry[plural_key])
+ end
else
validate_variables_in_message(errors, entry[:msgid], entry[:msgstr])
end
@@ -80,6 +84,10 @@ module Gitlab
validate_translation(errors, message_id, required_variables)
message_translation = join_message(message_translation)
+
+ # We don't need to validate when the message is empty.
+ # Translations could fallback to the default, or we could be validating a
+ # language that does not have plurals.
unless message_translation.empty?
validate_variable_usage(errors, message_translation, required_variables)
end
diff --git a/spec/fixtures/multiple_plurals.po b/spec/fixtures/multiple_plurals.po
new file mode 100644
index 00000000000..84b17b13ffa
--- /dev/null
+++ b/spec/fixtures/multiple_plurals.po
@@ -0,0 +1,26 @@
+# Arthur Charron <arthur.charron@hotmail.fr>, 2017. #zanata
+# Huang Tao <htve@outlook.com>, 2017. #zanata
+# Kohei Ota <inductor@kela.jp>, 2017. #zanata
+# Taisuke Inoue <taisuke.inoue.jp@gmail.com>, 2017. #zanata
+# Takuya Noguchi <takninnovationresearch@gmail.com>, 2017. #zanata
+# YANO Tethurou <tetuyano+zana@gmail.com>, 2017. #zanata
+msgid ""
+msgstr ""
+"Project-Id-Version: gitlab 1.0.0\n"
+"Report-Msgid-Bugs-To: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"PO-Revision-Date: 2017-08-06 11:23-0400\n"
+"Last-Translator: Taisuke Inoue <taisuke.inoue.jp@gmail.com>\n"
+"Language-Team: Japanese \"Language-Team: Russian (https://translate.zanata.org/"
+"project/view/GitLab)\n"
+"Language: ja\n"
+"X-Generator: Zanata 3.9.6\n"
+"Plural-Forms: nplurals=3; plural=n\n"
+
+msgid "%d commit"
+msgid_plural "%d commits"
+msgstr[0] "%d個のコミット"
+msgstr[1] "%d個のコミット"
+msgstr[2] "missing a variable"
diff --git a/spec/fixtures/no_plurals.po b/spec/fixtures/no_plurals.po
new file mode 100644
index 00000000000..1bfc4ecbb04
--- /dev/null
+++ b/spec/fixtures/no_plurals.po
@@ -0,0 +1,24 @@
+# Arthur Charron <arthur.charron@hotmail.fr>, 2017. #zanata
+# Huang Tao <htve@outlook.com>, 2017. #zanata
+# Kohei Ota <inductor@kela.jp>, 2017. #zanata
+# Taisuke Inoue <taisuke.inoue.jp@gmail.com>, 2017. #zanata
+# Takuya Noguchi <takninnovationresearch@gmail.com>, 2017. #zanata
+# YANO Tethurou <tetuyano+zana@gmail.com>, 2017. #zanata
+msgid ""
+msgstr ""
+"Project-Id-Version: gitlab 1.0.0\n"
+"Report-Msgid-Bugs-To: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"PO-Revision-Date: 2017-08-06 11:23-0400\n"
+"Last-Translator: Taisuke Inoue <taisuke.inoue.jp@gmail.com>\n"
+"Language-Team: Japanese \"Language-Team: Russian (https://translate.zanata.org/"
+"project/view/GitLab)\n"
+"Language: ja\n"
+"X-Generator: Zanata 3.9.6\n"
+"Plural-Forms: nplurals=1; plural=0\n"
+
+msgid "%d commit"
+msgid_plural "%d commits"
+msgstr[0] "%d個のコミット"
diff --git a/spec/lib/gitlab/po_linter_spec.rb b/spec/lib/gitlab/po_linter_spec.rb
index b59cefd294e..75b3163753f 100644
--- a/spec/lib/gitlab/po_linter_spec.rb
+++ b/spec/lib/gitlab/po_linter_spec.rb
@@ -65,6 +65,22 @@ describe Gitlab::PoLinter do
is_expected.to be_empty
end
end
+
+ context 'with missing plurals' do
+ let(:po_path) { 'spec/fixtures/no_plurals.po' }
+
+ it 'has no errors' do
+ is_expected.to be_empty
+ end
+ end
+
+ context 'with multiple plurals' do
+ let(:po_path) { 'spec/fixtures/multiple_plurals.po' }
+
+ it 'has no errors' do
+ is_expected.not_to be_empty
+ end
+ end
end
describe '#parse_po' do