From 9eb5793c8d7567c03cfa3aa9b5eac59da8c77f9f Mon Sep 17 00:00:00 2001 From: Stephen Souness Date: Fri, 19 Jun 2015 08:22:51 +0100 Subject: [PATCH] Added warning flag to shebang line, corrected string formatting, minor spelling and grammar fixes to comments. --- translation-tool.pl | 71 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/translation-tool.pl b/translation-tool.pl index 2b4a6bbfde..95ca0c59de 100755 --- a/translation-tool.pl +++ b/translation-tool.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # The MIT License # # Copyright (c) 2004-, Kohsuke Kawaguchi, Sun Microsystems, Inc., and a number of other of contributers @@ -24,28 +24,28 @@ # Author: Manuel Carrasco # Date: 20 Mar 2010 -# Perl script to generate missing translation keys and missing properties files, -# to remove unused keys, and to convert utf8 properties files to iso or ascii. +# Perl script to generate missing translation keys and missing properties files, +# to remove unused keys, and to convert utf8 properties files to iso or ascii. # -# 1.- It recursively looks for files in a folder, and analizes them to extract the -# keys being used in the application. +# 1.- It recursively looks for files in a folder, and analizes them to extract the +# keys being used in the application. # 2.- If --add=true, it generates the appropriate file for the desired language and adds # these keys to it, adding the english text as a reference. # If the properties file already exists the script update it with the new keys. # 3.- When --remove=true and there are unused keys in our file, the script removes them. # 4.- If an editor is passed as argument, the script edits each modified file after adding new keys. -# 5.- Finally, when --toiso=true or --toascii=true, the script is able to convert utf-8 -# properties files to iso or unicode hex representation is ascii. -# +# 5.- Finally, when --toiso=true or --toascii=true, the script is able to convert utf-8 +# properties files to iso or unicode hex representation is ascii. +# -# Note, while the migration to Jenkins this file will report the keys which should point +# Note, while the migration to Jenkins this file will report the keys which should point # to Jenkins instead of the old name. use strict; use File::Find; my ($lang, $editor, $dir, $toiso, $toascii, $add, $remove, $reuse) = (undef, undef, "./", undef, undef, undef, undef, undef); -my ($tfiles, $tkeys, $tmissing, $tunused, $tempty, $tsame, $tnojenkins) = (0, 0, 0, 0, 0, 0); +my ($tfiles, $tkeys, $tmissing, $tunused, $tempty, $tsame, $tnojenkins) = (0, 0, 0, 0, 0, 0, 0); ## read arguments foreach (@ARGV) { if (/^--lang=(.*)$/) { @@ -62,7 +62,7 @@ foreach (@ARGV) { $remove = 1; } elsif (/^--reuse=(.*)$/) { $reuse = $1; - } else { + } else { $dir=$_; } } @@ -75,7 +75,7 @@ if (!$lang || $lang eq "en") { } print STDERR "\rWait ..."; -## look for Message.properties and *.jelly files in the provided folder +## look for Message.properties and *.jelly files in the provided folder my @files = findTranslatableFiles($dir); ## load a cache with keys already translated to utilize in the case the same key is used @@ -106,10 +106,9 @@ if ($tkeys != 0) { $psame = $tsame/$tkeys*100; $pnojenkins = $tnojenkins/$tkeys*100; } -printf ("\nTOTAL: Files: %d Keys: %d Done: %d(%.2f\%)\n Missing: %d(%.2f\%) Orphan: %d(%.2f\%) Empty: %d(%.2f\%) Same: %d(%.2f\%) NoJenkins: %d(%.2f\%)\n\n", - $tfiles, $tkeys, $tdone, $pdone, - $tmissing, $pmissing, $tunused, $punused, - $tempty, $pempty, $tsame, $psame, $tnojenkins, $pnojenkins); + +my @formatParameters = ($tfiles, $tkeys, $tdone, $pdone, $tmissing, $pmissing, $tunused, $punused, $tempty, $pempty, $tsame, $psame, $tnojenkins, $pnojenkins); +printf "\nTOTAL: Files: %d Keys: %d Done: %d(%.2f%%)\n Missing: %d(%.2f%%) Orphan: %d(%.2f%%) Empty: %d(%.2f%%) Same: %d(%.2f%%) NoJenkins: %d(%.2f%%)\n\n", (@formatParameters); ## end exit(); @@ -117,7 +116,7 @@ exit(); ### This is the main method with is run for each file sub processFile { - # ofile -> output file in the current language, + # ofile -> output file in the current language, # efile -> english file my $file = shift; my ($ofile, $efile) = ($file, $file); @@ -154,7 +153,7 @@ sub processFile { } } - # calculate old keys in the file which are currently unused + # calculate old keys in the file which are currently unused my $unused = ""; foreach (keys %okeys) { if (!defined $keys{$_}) { @@ -163,7 +162,7 @@ sub processFile { } } - # calculate keys which has the same value in english + # calculate keys which have the same value in English my $same = ""; foreach (keys %okeys) { if ($okeys{$_} && $ekeys{$_} && $okeys{$_} eq $ekeys{$_}) { @@ -179,9 +178,9 @@ sub processFile { $tnojenkins ++; } } - - # Show Alerts + + # Show Alerts print "\nFile: $ofile\n$missing$unused$same$nj" if ($missing ne "" || $unused ne '' || $same ne '' || $nj ne ''); # write new keys in our file adding the English translation as a reference @@ -198,14 +197,14 @@ sub processFile { } close(F); } - - # open the editor if the user has especified it and there are changes to manage + + # open the editor if the user has specified it and there are changes to manage system("$editor $ofile") if ($editor && $add && ($missing ne "" || $same ne "" || $nj ne '')); # write new keys in our file adding the English translation as a reference removeUnusedKeys($ofile, %keys) if ($remove && $unused ne ""); - - # convert the language file to ISO or ACII which are + + # convert the language file to ISO or ASCII which are # the charsets which Jenkins supports right now convert($ofile, $toiso, $toascii) if ( -f $ofile ); } @@ -248,7 +247,7 @@ sub loadJellyFile { my $line = $_; while ($line =~ /^.*?\$\{\%([^\(\}]+)(.*)$/ || $line=~ /^.*?\$\{.*?['"]\%([^\(\}\"\']+)(.*)$/ ) { $line = $2; - my $word = $1; + my $word = $1; $word =~ s/\(.+$//g; $word =~ s/'+/''/g; $word =~ s/ /\\ /g; @@ -307,9 +306,9 @@ sub removeUnusedKeys { } close(FI); close(FO); - unlink($back); + unlink($back); } -} +} # convert a UTF-8 file to either ISO-8859 or ASCII sub convert { @@ -322,9 +321,9 @@ sub convert { if ($toiso) { s/([\xC2\xC3])([\x80-\xBF])/chr(ord($1)<<6&0xC0|ord($2)&0x3F)/eg; } else { - s/([\xC0-\xDF])([\x80-\xBF])/sprintf('\\u%04x', + s/([\xC0-\xDF])([\x80-\xBF])/sprintf('\\u%04x', unpack("c",$1)<<6&0x07C0|unpack("c",$2)&0x003F)/ge; - s/([\xE0-\xEF])([\x80-\xBF])([\x80-\xBF])/sprintf('\\u%04x', + s/([\xE0-\xEF])([\x80-\xBF])([\x80-\xBF])/sprintf('\\u%04x', unpack("c",$1)<<12&0xF000|unpack("c",$2)<<6&0x0FC0|unpack("c",$3)&0x003F)/ge; s/([\xF0-\xF7])([\x80-\xBF])([\x80-\xBF])([\x80-\xBF])/sprintf('\\u%04x', unpack("c",$1)<<18&0x1C0000|unpack("c",$2)<<12&0x3F000| @@ -384,11 +383,11 @@ sub trim($) return $string; } -### Usage +### Usage sub usage { print " Translation Tool for Jenkins - + Usage: $0 --lang=xx [options] [dir] dir: -> source folder for searching files (default current) @@ -403,14 +402,14 @@ Usage: $0 --lang=xx [options] [dir] order to utilize them when the same key appears Examples: - - Look for Spanish files with incomplete keys in the 'main' folder, + - Look for Spanish files with incomplete keys in the 'main' folder, edit them with gedit, and finally convert them to ISO-8859 $0 --lang=es --editor=gedit --toiso main - Convert all Japanese files in the current folder encoded with UTF-8 to ASCII $0 --lang=ja --toascii . - - Remove all orphand keys from German files which are in the current file - $0 --lang=de --remove . - + - Remove all orphaned keys from German files which are in the current file + $0 --lang=de --remove . + "; exit(); }