summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-09-01 14:30:43 +0000
committerDouwe Maan <douwe@gitlab.com>2017-09-01 14:30:43 +0000
commitdceb2112d2ec34a947edfb2c9ec4d286fea4661a (patch)
treef1d2f5f7724a6560d88d2a848a0cb6f504aafdb1 /lib/tasks
parentba3cfd07dd9bd0de57239d5a748d98f783507d92 (diff)
parent4761235f6944d1627346ca835a192c1ed32f745e (diff)
downloadgitlab-ce-dceb2112d2ec34a947edfb2c9ec4d286fea4661a.tar.gz
Merge branch 'bvl-validate-po-files' into 'master'
Validate PO files in static analysis See merge request !13000
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/gettext.rake40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
index b48e4dce445..e1491f29b5e 100644
--- a/lib/tasks/gettext.rake
+++ b/lib/tasks/gettext.rake
@@ -19,4 +19,44 @@ namespace :gettext do
Rake::Task['gettext:pack'].invoke
Rake::Task['gettext:po_to_json'].invoke
end
+
+ desc 'Lint all po files in `locale/'
+ task lint: :environment do
+ FastGettext.silence_errors
+ files = Dir.glob(Rails.root.join('locale/*/gitlab.po'))
+
+ linters = files.map do |file|
+ locale = File.basename(File.dirname(file))
+
+ Gitlab::I18n::PoLinter.new(file, locale)
+ end
+
+ pot_file = Rails.root.join('locale/gitlab.pot')
+ linters.unshift(Gitlab::I18n::PoLinter.new(pot_file))
+
+ failed_linters = linters.select { |linter| linter.errors.any? }
+
+ if failed_linters.empty?
+ puts 'All PO files are valid.'
+ else
+ failed_linters.each do |linter|
+ report_errors_for_file(linter.po_path, linter.errors)
+ end
+
+ raise "Not all PO-files are valid: #{failed_linters.map(&:po_path).to_sentence}"
+ end
+ end
+
+ def report_errors_for_file(file, errors_for_file)
+ puts "Errors in `#{file}`:"
+
+ errors_for_file.each do |message_id, errors|
+ puts " #{message_id}"
+ errors.each do |error|
+ spaces = ' ' * 4
+ error = error.lines.join("#{spaces}")
+ puts "#{spaces}#{error}"
+ end
+ end
+ end
end