Commit 721cf7bd authored by Naba Kumar's avatar Naba Kumar

Added translation status script. Completed find-fixmes.pl script. Fixed

	* plugins/tools/scripts/find-fixmes.pl,
	(new) plugins/tools/scripts/translation-status.pl,
	plugins/tools/scripts/tools-2.xml.in,
	plugins/tools/scripts/Makefile.am,
	plugins/tools/scripts/prepare-changelog.pl: Added translation
	status script. Completed find-fixmes.pl script. Fixed bugs.
parent 8c78fe53
2005-06-15 Naba Kumar <naba@gnome.org>
* plugins/tools/scripts/find-fixmes.pl,
(new) plugins/tools/scripts/translation-status.pl,
plugins/tools/scripts/tools-2.xml.in,
plugins/tools/scripts/Makefile.am,
plugins/tools/scripts/prepare-changelog.pl: Added translation
status script. Completed find-fixmes.pl script. Fixed bugs.
* plugins/tools/scripts/tools-2.xml.in: Fixed prepare-changelog
tool path.
......
......@@ -4,5 +4,6 @@
toolsdir = $(anjuta_data_dir)/tools
tools_SCRIPTS = \
prepare-changelog.pl \
find-fixmes.pl
find-fixmes.pl \
translation-status.pl
tools_DATA = tools-2.xml
#!/usr/bin/perl -w
#!/usr/bin/perl
## Prepare ChangeLog
## find-fixmes.pl
## Copyright (C) Naba Kumar <naba@gnome.org>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Library General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
my ($project_root) = @ARGV;
......@@ -12,56 +27,111 @@ if ($project_root !~ /^\//) {
print STDERR "Error: Project root is not absolute path\n";
exit(1);
}
unless (-f "$project_root/ChangeLog") {
print STDERR "Error: Project does not have a ChangeLog file\n";
exit(1);
}
unless (-d "$project_root/CVS" || -d "$project_root/.svn") {
print STDERR "Error: Project is in neither cvs or subversion working copy.\n";
exit(1);
}
my %data_hr;
process_directory ("", \%data_hr);
sub process_directory
{
my ($dir, $data_hr) = @_;
if ($dir ne "") {
print STDERR "Scanning $dir\n";
print STDERR "Scanning: $dir\n";
} else {
print STDERR "Scanning .\n";
print STDERR "Scanning: .\n";
}
open (ENTRIES, "$project_root/$dir/CVS/Entries") or
die "Can not open $project_root/$dir/CVS/Entries for reading";
my @lines = <ENTRIES>;
@lines = sort @lines;
my (@files, @directories);
if (-f "$project_root/$dir/CVS/Entries") {
open (ENTRIES, "$project_root/$dir/CVS/Entries") or
die "Can not open $project_root/$dir/CVS/Entries for reading";
my @lines = <ENTRIES>;
@lines = sort @lines;
foreach my $line (@lines) {
chomp($line);
if ($line =~ /^\/([^\/]+)\/([^\/]+)\/([^\/]+)/) {
my $file = $1;
my $repo_time = $3;
my $file_time = `date -u -r $project_root/$dir/$file`;
$file_time =~ s/\s+$//sg;
$file_time =~ s/\w+\s+(\d+)$/$1/;
## print "Comparing '$repo_time' and '$file_time'\n";
if ($file_time ne $repo_time) {
my $path = "$dir/$file";
$path =~ s/^\///;
$data_hr->{$path} = "modified";
foreach my $line (@lines) {
chomp($line);
if ($line =~ /^\/([^\/]+)\//) {
push @files, $1;
}
}
foreach my $line (@lines) {
chomp($line);
if ($line =~ /^D\/([^\/]+)/) {
push @directories, $1;
}
}
} else {
opendir (ENTRIES, "$project_root/$dir") or
die "Can not open $project_root/$dir for reading";
my @lines = readdir(ENTRIES);
foreach my $line (@lines) {
next if ($line eq "." || $line eq "..");
if (-d "$project_root/$dir/$line") {
push @directories, $line;
} else {
push @files, $line;
}
}
}
foreach my $file (@files) {
my $file_path = "$project_root/$dir/$file";
$file_path =~ s/\/\//\//g;
process_file ($file_path, $data_hr) if (-f $file_path);
}
foreach my $line (@lines) {
chomp($line);
if ($line =~ /^D\/([^\/]+)/) {
if (-d "$project_root/$dir/$1") {
if ($dir ne "") {
process_directory ("$dir/$1", $data_hr);
} else {
process_directory ("$1", $data_hr);
foreach my $directory (@directories) {
if (-d "$project_root/$dir/$directory") {
if ($dir ne "") {
process_directory ("$dir/$directory", $data_hr);
} else {
process_directory ("$directory", $data_hr);
}
}
}
}
sub process_file
{
my ($path, $data_hr) = @_;
my $content = `cat $path`;
## C/C++ specific search
if ($path =~ /\.(c|cc|cpp|cxx|h|hpp|hxx|hh)$/) {
my @data = $content =~ /(\n|\/\*.*?\*\/|\/\/.*?\n)/sgi;
my $continued = 0;
my $lines = 0;
foreach my $match (@data) {
if ($match eq "\n") {
$continued = 0;
} elsif ($match =~ /\bfixme\b/is) {
print "$path:$lines\n";
$match = "\t$match";
$match =~ s/\n\s*/\n\t/sg;
$match =~ s/\s*$//s;
print "$match\n";
$continued = 1;
} else {
if ($continued == 1 && $match =~ /^(\/\*|\/\/)/) {
$match = "\t$match";
$match =~ s/\n\s*/\n\t/sg;
$match =~ s/\s*$//s;
print "$match\n";
}
}
$lines += $match =~ /(\n)/sg;
}
} else {
my @data = split(/\n/, $content);
my $lines = 0;
foreach my $match (@data) {
if ($match =~ /\bfixme\b/is) {
print "$path:$lines\n";
$match =~ s/^\s*/\t/sg;
print "$match\n";
}
$lines++;
}
}
}
#!/usr/bin/perl -w
#!/usr/bin/perl
## Prepare ChangeLog
## prepare-changelog.pl
## Copyright (C) Naba Kumar <naba@gnome.org>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Library General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
my ($project_root) = @ARGV;
......
<?xml version="1.0"?>
<anjuta-tools>
<tool name="Find with grep">
<command>grep -r -e</command>
<parameter>$(ask_user_string) .</parameter>
<tool name="Prepare ChangeLog">
<command>@ANJUTA_DATA_DIR@/tools/prepare-changelog.pl</command>
<parameter>$(project_root_directory)</parameter>
<working_dir></working_dir>
<enabled>1</enabled>
<autosave>0</autosave>
<run_in_terminal>0</run_in_terminal>
<output>3</output>
<error>1</error>
<input_type>0</input_type>
<shortcut></shortcut>
</tool>
<tool name="Translation status">
<command>@ANJUTA_DATA_DIR@/tools/translation-status.pl</command>
<parameter>$(project_root_directory)</parameter>
<working_dir>$(project_root_directory)</working_dir>
<enabled>1</enabled>
<autosave>0</autosave>
<run_in_terminal>0</run_in_terminal>
<output>1</output>
<error>0</error>
<input_type>4</input_type>
<input>$(file_manager_current_full_filename)</input>
<shortcut>&lt;Control&gt;grave</shortcut>
<icon>/usr/share/pixmaps/gnome-question.png</icon>
<output>3</output>
<error>1</error>
<input_type>0</input_type>
<shortcut></shortcut>
</tool>
<tool name="Find FIXMEs">
<command>sh -c</command>
<parameter>&apos;tree -if | egrep \&apos;\\.(c|cpp|cxx|h|hpp|idl)$\&apos; | xargs grep -n \&apos;FIXME:\&apos;&apos;</parameter>
<command>@ANJUTA_DATA_DIR@/tools/find-fixmes.pl</command>
<parameter>$(project_root_directory)</parameter>
<working_dir>$(project_root_directory)</working_dir>
<enabled>1</enabled>
<autosave>0</autosave>
......@@ -26,17 +36,17 @@
<input_type>0</input_type>
<shortcut></shortcut>
</tool>
<tool name="Translation status">
<command>sh -c</command>
<parameter>&apos;cd po &amp;&amp; ./status.pl&apos;</parameter>
<tool name="Find with grep">
<command>grep -r -e</command>
<parameter>$(ask_user_string) .</parameter>
<working_dir>$(project_root_directory)</working_dir>
<enabled>1</enabled>
<autosave>0</autosave>
<run_in_terminal>0</run_in_terminal>
<output>3</output>
<output>1</output>
<error>0</error>
<input_type>0</input_type>
<shortcut></shortcut>
<shortcut>&lt;Control&gt;grave</shortcut>
</tool>
<tool name="Make distribution">
<command>make dist</command>
......@@ -62,16 +72,4 @@
<input_type>0</input_type>
<shortcut></shortcut>
</tool>
<tool name="Prepare ChangeLog">
<command>@ANJUTA_DATA_DIR@/tools/prepare-changelog.pl</command>
<parameter>$(project_root_directory)</parameter>
<working_dir></working_dir>
<enabled>1</enabled>
<autosave>0</autosave>
<run_in_terminal>0</run_in_terminal>
<output>3</output>
<error>1</error>
<input_type>0</input_type>
<shortcut></shortcut>
</tool>
</anjuta-tools>
#!/usr/bin/perl
## status.pl
## Copyright (C) Naba Kumar <naba@gnome.org>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Library General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
## modified 2001-11-05 Andy Piper <andy.piper@freeuk.com>
## - added further countries to the hash table
## - altered XML file output
## - corrected typos
=head Status.pl
Usage: status.pl
This script shows the status of each po file in the current dir.
The translation status is given as a percentage.
=cut
## Output xml file for translation status
my $translation_file = "translations.xml";
## Country code to country name hash map
## Some contry codes may need to be filled.
my $country_hr = {
"az" => "Azerbaijani",
"br" => "Breton",
"bg" => "Bulgarian",
"ca" => "Catalan",
"cs" => "Czech",
"da" => "Danish",
"de" => "German",
"el" => "Greek",
"en_GB" => "British English",
"en_US" => "American English",
"eo" => "Esperanto",
"es" => "Spanish",
"et" => "Estonian",
"eu" => "Basque",
"fi" => "Finnish",
"fr" => "French",
"he" => "Hebrew",
"hr" => "Croatian",
"hu" => "Hungarian",
"is" => "Icelandic",
"it" => "Italian",
"ja" => "Japanese",
"ko" => "Korean",
"lt" => "Lithuanian",
"ms" => "Malay",
"mk" => "Macedonian",
"nl" => "Dutch",
"nn" => "Norwegian Nynorsk",
"no" => "Norwegian",
"pl" => "Polish",
"pt" => "Portuguese",
"pt_BR" => "Brazilian Portuguese",
"ro" => "Romanian",
"ru" => "Russian",
"sk" => "Slovak",
"sl" => "Slovenian",
"sr" => "Serbian",
"sv" => "Swedish",
"ta" => "Tamil",
"tr" => "Turkish",
"uk" => "Ukrainian",
"vi" => "Vietnamese",
"wa" => "Walloon",
"zh_CN.GB2312" => "Simplified Chinese",
"zh_CN" => "Simplified Chinese",
"zh_TW" => "Traditional Chinese"
};
my ($project_root) = @ARGV;
if (!defined ($project_root) || $project_root eq "") {
print STDERR "Error: No project\n";
exit(1);
}
if ($project_root !~ /^\//) {
print STDERR "Error: Project root is not absolute path\n";
exit(1);
}
unless (-d "$project_root/po") {
print STDERR "Error: Project does not have translations\n";
exit(1);
}
chdir("$project_root/po");
## Generate/update .pot file
system("intltool-update -p");
## Determine missing files.
system("intltool-update --maintain");
## Just take the first pot file found as the reference.
my $pot_file = glob("*.pot");
if ($pot_file eq "") {
print "There is no reference pot file in this directory.\n";
print "Make sure you are running status.pl in a po directory.\n";
print "...... Aborting.\n";
exit (1);
}
## the appname will be the name of the pot file
$appname = $pot_file;
while ($strip ne ".") {
$strip = chop ($appname);
}
## Determine the total messages available in this pot file.
my $output = `msgfmt --statistics $pot_file 2>&1`;
my @strs = split (", ", $output);
my ($pot_fuzzy, $pot_translated, $pot_untranslated) = (0,0,0);
foreach my $term (@strs) {
if ($term =~ /translated/) {
($pot_translated) = split (" ", $term);
} elsif ($term =~ /fuzzy/) {
($pot_fuzzy) = split (" ", $term);
} elsif ($term =~ /untranslated/) {
($pot_untranslated) = split (" ", $term);
}
}
my $total_messages = $pot_translated + $pot_fuzzy + $pot_untranslated;
print "\n";
print "\t\tTRANSLATION STATISTICS\n";
print "\t\tTotal messages: $total_messages\n\n";
print "\tTranslation status given in percentage.\n";
print "+----------------------------------------------------------------------------+\n";
printf ("| Po file | Language | Translated | Fuzzy | Untranslated |\n");
print "+----------------------------------------------------------------------------+\n";
my @po_files = glob("*.po");
my $date_time = gmtime(time());
foreach my $po_file (@po_files) {
if (-f $po_file) {
my $output = `msgfmt --statistics $po_file 2>&1`;
## print $output, "\n";
my ($translated, $fuzzy, $untranslated) = (0,0,0);
my @strs = split (", ", $output);
foreach my $coin (@strs) {
if ($coin =~ /\btranslated\b/) {
($translated) = split (" ", $coin);
} elsif ($coin =~ /\bfuzzy\b/) {
($fuzzy) = split (" ", $coin);
} elsif ($coin =~ /\buntranslated\b/) {
($untranslated) = split (" ", $coin);
}
}
$untranslated = $total_messages - ($translated + $fuzzy);
$untranslated *= 100/$total_messages;
$untranslated = ($untranslated < 0)? 0:$untranslated;
$untranslated = ($untranslated > 100)? 100:$untranslated;
$translated *= 100/$total_messages;
$translated = ($translated < 0)? 0:$translated;
$translated = ($translated > 100)? 100:$translated;
$fuzzy *= 100/$total_messages;
$fuzzy = ($fuzzy < 0)? 0:$fuzzy;
$fuzzy = ($fuzzy > 100)? 100:$fuzzy;
my $country_code = $po_file;
$country_code =~ s/\.po$//;
my $country = $country_hr->{$country_code};
$country = ($country ne "")? $country:"-";
printf ("|%10s |%21s | %6.2f ", $po_file, $country, $translated);
printf ("| %6.2f | %6.2f |\n", $fuzzy, $untranslated);
}
}
print "+----------------------------------------------------------------------------+\n";
__END__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment