I18n/German: translations_report.pl

File translations_report.pl, 8.4 kB (added by pwalker, 3 years ago)

translations_report.pl (version for de_DE); copy/wget to /var/www/html

Line 
1 #!/usr/bin/perl -w
2
3
4 # apt-get install libtime-format-perl libfile-slurp-perl
5 # yum install perl-File-Fetch perl-File-Slurp perl-Math-Round perl-Text-ASCIITable, perl-TimeDate((not working!!!???)
6 # cpan: File::Fetch, File::Slurp, Math::Round, Text::ASCIITable Time::Format
7
8 use strict;
9 use Cwd 'realpath';
10 use File::Basename;
11 use File::Copy;
12 use File::Fetch;
13 use File::Path;
14 use File::Slurp;
15 use Math::Round qw(round);
16 use Text::ASCIITable;
17 use Term::ANSIColor qw(:constants);
18 use Time::Format;
19
20 my $language = "de_DE";
21 my $dir   = realpath( dirname($0) );
22 my $date  = $time{"yyyy-mm-dd_hh-mm-ss"};
23 my $show_obsoletes = 0;
24
25
26
27
28
29 my $svn_repo = "http://svn.freepbx.org";
30 my $svn_path = "branches/2.5";
31 my @modules = (
32     "announcement",
33     "asterisk-cli",
34     "asteriskinfo",
35     "backup",
36     "blacklist",
37     "callback",
38     "callforward",
39     "callwaiting",
40     "cidlookup",
41     "conferences",
42     "customappsreg",
43     "customerdb",
44     "dashboard",
45     "daynight",
46     "dictate",
47     "disa",
48     "donotdisturb",
49     "dundicheck",
50     "featurecodeadmin",
51     "findmefollow",
52     "fw_langpacks",
53     "gabcast",
54     "infoservices",
55     "inventorydb",
56     "irc",
57     "ivr",
58     "javassh",
59     "languages",
60     "logfiles",
61     "manager",
62     "miscapps",
63     "miscdests",
64     "music",
65     "paging",
66     "parking",
67     "pbdirectory",
68     "phonebook",
69     "phpagiconf",
70     "phpinfo",
71     "pinsets",
72     "printextensions",
73     "queueprio",
74     "queues",
75     "recordings",
76     "ringgroups",
77     "speeddial",
78     "timeconditions",
79     "vmblast",
80     "voicemail",
81          );
82
83
84
85
86 ##########################################################################################################################################################
87 ##########################################################################################################################################################
88 ##########################################################################################################################################################
89
90 # Inicio del proceso
91
92 @modules = sort(@modules);
93 my @result;
94 my $total = 0;
95 my $total_translated = 0;
96 my $total_untranslated = 0;
97 my $total_fuzzy = 0;
98 my $total_obsolete = 0;
99
100 my $t = Text::ASCIITable->new({ headingText => "Translation Status" });
101 if ($show_obsoletes == 1)
102 {
103   $t->setCols("Application/Module", "strings", "translated", "not translated", "fuzzy", "obsolete");
104 }
105 else
106 {
107   $t->setCols("Application/Module", "strings", "translated", "not translated", "obsolete");
108 }
109 $t->setOptions('allowANSI', 1);
110
111 # Procesar las aplicaciones y los módulos
112
113 # Aplicación principal
114 if ( -e "$dir/admin/i18n/${language}/LC_MESSAGES/amp.po" )
115 {
116   @result = &process_file("core", "$dir/admin/i18n/${language}/LC_MESSAGES/amp.po");
117   $total += $result[1];
118   $total_translated += $result[2];
119   $total_untranslated += $result[3];
120   $total_fuzzy += $result[4];
121   $total_obsolete += $result[5];
122   $t->addRow( $result[0] );
123 }
124
125 # Aplicación recordings
126 if ( -e "$dir/recordings/locale/${language}/LC_MESSAGES/ari.po" )
127 {
128   @result = &process_file("ARI / User Portal", "$dir/recordings/locale/${language}/LC_MESSAGES/ari.po");
129   $total += $result[1];
130   $total_translated += $result[2];
131   $total_untranslated += $result[3];
132   $total_fuzzy += $result[4];
133   $total_obsolete += $result[5];
134   $t->addRow( $result[0] );
135 }
136
137 # Módulos
138 for (my $i=0; $i < @modules; $i++ )
139 {
140   if ( -e "$dir/admin/modules/${modules[$i]}/i18n/${language}/LC_MESSAGES/${modules[$i]}.po" )
141   {
142     #@result = &process_file("Módulo ${modules[$i]}", "$dir/modules/${modules[$i]}/i18n/${language}/LC_MESSAGES/${modules[$i]}.po");
143     @result = &process_file("${modules[$i]}", "$dir/admin/modules/${modules[$i]}/i18n/${language}/LC_MESSAGES/${modules[$i]}.po");
144     $total += $result[1];
145     $total_translated += $result[2];
146     $total_untranslated += $result[3];
147     $total_fuzzy += $result[4];
148     $total_obsolete += $result[5];
149     $t->addRow( $result[0] );
150   }
151 }
152
153 # Añadir línea de separación
154 $t->addRowLine();
155
156 my $title = "TOTAL";
157 my $title_ret = $title;
158 my $total_ret = "";
159 my $total_translated_ret = "";
160 my $total_untranslated_ret = "";
161 my $total_fuzzy_ret = "";
162 my $total_obsolete_ret = "";
163
164 $title_ret    = BOLD GREEN  $title, RESET;
165 $title_ret    = BOLD YELLOW $title, RESET if ($total_obsolete > 0);
166 $title_ret    = BOLD DARK BLUE   $title, RESET if ($total_fuzzy > 0);
167 $title_ret    = BOLD RED    $title, RESET if ($total_untranslated > 0);
168
169 $total_ret        = BOLD GREEN  $total, RESET;
170 $total_ret        = BOLD YELLOW $total, RESET if ($total_obsolete > 0);
171 $total_ret        = BOLD DARK BLUE   $total, RESET if ($total_fuzzy > 0);
172 $total_ret        = BOLD RED    $total, RESET if ($total_untranslated > 0);
173
174 $total_translated_ret   = BOLD GREEN  $total_translated . " (" . round($total_translated*100/$total) . "%)", RESET;
175
176 $total_untranslated_ret = BOLD GREEN  $total_untranslated . " (" . round($total_untranslated*100/$total) . "%)", RESET if ($total_untranslated <= 0);
177 $total_untranslated_ret = BOLD RED    $total_untranslated . " (" . round($total_untranslated*100/$total) . "%)", RESET if ($total_untranslated > 0);
178
179 $total_fuzzy_ret        = BOLD GREEN  $total_fuzzy . " (" . round($total_fuzzy*100/$total) . "%)", RESET if ($total_fuzzy <= 0);
180 $total_fuzzy_ret        = BOLD DARK BLUE   $total_fuzzy . " (" . round($total_fuzzy*100/$total) . "%)", RESET if ($total_fuzzy > 0);
181
182 $total_obsolete_ret     = BOLD GREEN  $total_obsolete . " (" . round($total_obsolete*100/$total) . "%)", RESET if ($total_obsolete <= 0);
183 $total_obsolete_ret     = BOLD YELLOW $total_obsolete . " (" . round($total_obsolete*100/$total) . "%)", RESET if ($total_obsolete > 0);
184
185 if ($show_obsoletes == 1)
186 {
187   $t->addRow([$title_ret, $total_ret, $total_translated_ret, $total_untranslated_ret, $total_fuzzy_ret, $total_obsolete_ret]);
188 }
189 else
190 {
191   $t->addRow([$title_ret, $total_ret, $total_translated_ret, $total_untranslated_ret, $total_fuzzy_ret]);
192 }
193
194 print "\n";
195 print $t;
196 print "\n";
197
198 ##########################################################################################################################################################
199
200 # Rutinas
201
202
203 sub process_file
204 {
205
206   my($appmodule, $lang_po_file) = @_;
207
208   if ( -e $lang_po_file )
209   {
210
211     # Comprobar el número de palabras sin traducir
212     my $total        = `msgattrib --stringtable-output "$lang_po_file" | grep \"^\\\"" | wc -l`;
213     my $translated   = `msgattrib --stringtable-output --translated "$lang_po_file" | grep \"^\\\"\" | wc -l`;
214     my $untranslated = `msgattrib --stringtable-output --untranslated "$lang_po_file" | grep \"^\\\"\" | wc -l`;
215     my $fuzzy        = `msgattrib --stringtable-output --only-fuzzy "$lang_po_file" | grep \"^\\\"" | wc -l`;
216     my $obsolete     = `msgattrib --stringtable-output --only-obsolete "$lang_po_file" | grep \"^\\\"" | wc -l`;
217
218     chomp($total);
219     chomp($translated);
220     chomp($untranslated);
221     chomp($fuzzy);
222     chomp($obsolete);
223
224     my ($appmodule_ret, $total_ret, $translated_ret, $untranslated_ret, $fuzzy_ret, $obsolete_ret);
225
226     $appmodule_ret    = BOLD GREEN  $appmodule, RESET;
227     $appmodule_ret    = BOLD YELLOW $appmodule, RESET if ($obsolete > 0);
228     $appmodule_ret    = BOLD DARK BLUE   $appmodule, RESET if ($fuzzy > 0);
229     $appmodule_ret    = BOLD RED    $appmodule, RESET if ($untranslated > 0);
230
231     $total_ret        = BOLD GREEN  $total, RESET;
232     $total_ret        = BOLD YELLOW $total, RESET if ($obsolete > 0);
233     $total_ret        = BOLD DARK BLUE   $total, RESET if ($fuzzy > 0);
234     $total_ret        = BOLD RED    $total, RESET if ($untranslated > 0);
235
236     $translated_ret   = BOLD GREEN  $translated . " (" . round($translated*100/$total) . "%)", RESET;
237
238     $untranslated_ret = BOLD GREEN  $untranslated . " (" . round($untranslated*100/$total) . "%)", RESET if ($untranslated <= 0);
239     $untranslated_ret = BOLD RED    $untranslated . " (" . round($untranslated*100/$total) . "%)", RESET if ($untranslated > 0);
240
241     $fuzzy_ret        = BOLD GREEN  $fuzzy . " (" . round($fuzzy*100/$total) . "%)", RESET if ($fuzzy <= 0);
242     $fuzzy_ret        = BOLD DARK BLUE   $fuzzy . " (" . round($fuzzy*100/$total) . "%)", RESET if ($fuzzy > 0);
243
244     $obsolete_ret     = BOLD GREEN  $obsolete . " (" . round($obsolete*100/$total) . "%)", RESET if ($obsolete <= 0);
245     $obsolete_ret     = BOLD YELLOW $obsolete . " (" . round($obsolete*100/$total) . "%)", RESET if ($obsolete > 0);
246
247     if ($show_obsoletes == 1)
248     {
249       return ([$appmodule_ret, $total_ret, $translated_ret, $untranslated_ret, $fuzzy_ret, $obsolete_ret], $total, $translated, $untranslated, $fuzzy, $obsolete);
250     }
251     else
252     {
253       return ([$appmodule_ret, $total_ret, $translated_ret, $untranslated_ret, $fuzzy_ret], $total, $translated, $untranslated, $fuzzy, $obsolete);
254     }
255
256   }
257
258 }