[Pkg-mozext-commits] [itsalltext] 417/459: Rake now verifies translations

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:44 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository itsalltext.

commit daf47231b6504a27a3145700f24c0ba1a04735cf
Author: Christian Höltje <docwhat at gerf.org>
Date:   Sat May 18 16:50:28 2013 -0400

    Rake now verifies translations
---
 Rakefile | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 79 insertions(+), 1 deletion(-)

diff --git a/Rakefile b/Rakefile
index 788872a..a258b2c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,5 @@
 require 'paint'
+require 'set'
 
 VERSION="1.8.0"
 XPI_FILENAME = "itsalltext-#{VERSION}.xpi"
@@ -14,6 +15,9 @@ FIREFOX_SOURCE_EXTENSIONS = [
   'xul',
 ]
 FIREFOX_SOURCES = FIREFOX_SOURCE_EXTENSIONS.map { |x| Dir["src/**/*.#{x}"] }.flatten.freeze
+LOCALE_DIR = 'src/chrome/locale'
+FAVORED_LANGUAGE = 'en-US'
+LANGUAGES = Dir["#{LOCALE_DIR}/*"].select { |p| File.directory?(p) }.map { |p| File.basename(p) }.select { |p| p =~ %r{[a-z]{2}-[A-Z]{2}} && p != FAVORED_LANGUAGE }.sort.freeze
 
 task :default => :build
 
@@ -33,6 +37,80 @@ task :clean do
   rm_rf 'final'
 end
 
+desc "Verify all translations are in place"
+task :verify do
+  errors = []
+  LANGUAGES.each { |language| errors << diff_locale(language) }
+  errors = errors.flatten.select { |e| !e.nil? }
+  if errors.size > 0
+    errors.each { |error| puts "ERROR: #{error}" }
+    raise "There were problems with the translations."
+  end
+end
+
+def load_dtd_entities file
+  Set.new(File.readlines(file).map do |line|
+    $1.to_s if line =~ %r{^<!ENTITY\s+(\S+)}
+  end.select { |e| !e.nil? })
+end
+
+def find_dtd_errors source_file, file_to_check
+  source  = load_dtd_entities source_file
+  checkee = load_dtd_entities file_to_check
+
+  errors = []
+  if (source - checkee).size > 0
+    errors << "You're missing entities in #{file_to_check}: #{(source - checkee).to_a.join(', ')}"
+  end
+  if (checkee - source).size > 0
+    errors << "You have extra entities in #{file_to_check}: #{(checkee - source).to_a.join(', ')}"
+  end
+
+  errors
+end
+
+def load_properties_entities file
+  Set.new(File.readlines(file).map do |line|
+    $1.to_s if line =~ %r{^\s*(\S+)\s*=}
+  end.select { |e| !e.nil? })
+end
+
+def find_properties_errors source_file, file_to_check
+  source  = load_properties_entities source_file
+  checkee = load_properties_entities file_to_check
+
+  errors = []
+  if (source - checkee).size > 0
+    errors << "You're missing props in #{file_to_check}: #{(source - checkee).to_a.join(', ')}"
+  end
+  if (checkee - source).size > 0
+    errors << "You have extra props in #{file_to_check}: #{(checkee - source).to_a.join(', ')}"
+  end
+
+  errors
+end
+
+def diff_locale language
+  errors = []
+
+  Dir[File.join LOCALE_DIR, FAVORED_LANGUAGE, '*'].each do |fav_file|
+    other_file = File.join LOCALE_DIR, language, File.basename(fav_file)
+    extension = File.extname fav_file
+    if ! File.exists?(other_file)
+      errors << "The file #{other_file} is missing!"
+      next
+    end
+
+    if extension == '.dtd'
+      errors << find_dtd_errors(fav_file, other_file)
+    elsif extension == '.properties'
+      errors << find_properties_errors(fav_file, other_file)
+    end
+  end
+
+  errors.flatten.select { |e| !e.nil? }
+end
+
 file "final" => FIREFOX_SOURCES do |t|
   rm_rf 'final'
   t.prerequisites.each do |src|
@@ -50,7 +128,7 @@ file "final" => FIREFOX_SOURCES do |t|
   end
 end
 
-file XPI_FILENAME => ["final"] do |t|
+file XPI_FILENAME => [:verify, "final"] do |t|
   rm_f t.name
   xpi_path = File.expand_path(t.name)
   Dir.chdir "final" do

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git



More information about the Pkg-mozext-commits mailing list