Updated Traditional Chinese translation.
[evolution.git] / help / update_translation.pl
blob0023b069d19bb2519793edfaf7802f6c03c425fc
1 #!/usr/bin/perl -w
3 # Script that translates .sgml files using the .po files generated from
4 # the script update_po.pl
6 # Copyright (C) 2001 Héctor García Álvarez.
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of the
11 # License, or (at your option) any later version.
13 # This script is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this library; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # Authors: Héctor García Álvarez <hector@scouts-es.org>
25 ## Loaded modules
26 use File::Basename;
27 use Getopt::Long;
29 my $LANG = $ARGV[0];
31 my %string;
32 my $texto_original="";
33 my $texto_traducido="";
35 if (! $LANG){
36 print "Usage: update_translation.pl LANGCODE\n";
37 exit;
40 chdir ("./C");
42 ## Reading the po file
43 #print "Loading ".$LANG.".po\n";
44 #&load_translated_strings ($LANG.".po");
46 ## Checking for the lang dir
47 if ( !(-d "../".$LANG) ) { mkdir ("../".$LANG, 0755) ; }
49 open FILES, "<POTFILES.in" ;
50 while (<FILES>) {
51 undef %string;
52 s/\n//g;
53 $Original_file = $_ ;
54 s/.\///g;
55 $Translated_file = "../".$LANG."/".$_;
56 # print $Original_file."\n";
57 # print $Translated_file."\n";
58 &load_translated_strings ("../".$LANG.".po/".$_.".po");
59 print "Translating ".$Original_file ;
60 system "rm -f $Translated_file";
61 &translate_file ($Translated_file , $Original_file);
62 print ".\n";
64 close FILES;
66 exit 0;
71 sub load_translated_strings ()
73 my $FILE=$_[0];
74 open (IN, "<$FILE") || die "I can't find $FILE";
76 while (<IN>) {
77 if ( /#: /) {
78 &original;
79 &traduccion;
80 # print "Original \n##".$texto_original."##\n";
81 # print "Traducción \n##".$texto_traducido."##\n";
82 $string{$texto_original} = $texto_traducido;
85 close (IN);
88 sub translate_file ()
90 my $OUTFILE=$_[0];
91 my $INFILE=$_[1];
93 open OUT, ">>$OUTFILE";
94 open (IN, "<$INFILE") || die "can't open $INFILE: $!";
96 while (<IN>) {
97 my $imprimir = 0;
98 if ( /<!--/ ) {
99 $Salida = $_ ;
100 if ( !(/-->/) ) {
101 while (<IN>) {
102 $Salida .= $_ ;
103 if ( /-->/ ) { last ; }
106 $imprimir = 1;
108 elsif ( /<para>/ ) {
109 my $number_of_para = 1;
110 $Salida = $_ ;
111 if ( !(/<\/para>/) ) {
112 while (<IN>) {
113 if ( /<para>/ ) { $number_of_para++; }
114 $Salida .= $_ ;
115 if ( /<\/para>/ ) {
116 $number_of_para--;
117 if ( $number_of_para==0) {last ; }
121 $imprimir = 1;
123 elsif ( /<title>/ ) {
124 $Salida = $_ ;
125 if ( !(/<\/title>/) ) {
126 while (<IN>) {
127 $Salida .= $_ ;
128 if ( /<\/title>/ ) { last ; }
131 $imprimir = 1;
133 elsif ( /<glossterm>/ ) {
134 $Salida = $_ ;
135 if ( !(/<\/glossterm>/) ) {
136 while (<IN>) {
137 $Salida .= $_ ;
138 if ( /<\/glossterm>/ ) { last ; }
141 $imprimir = 1;
143 elsif ( /<guilabel>/ ) {
144 $Salida = $_ ;
145 if ( !(/<\/guilabel>/) ) {
146 while (<IN>) {
147 $Salida .= $_ ;
148 if ( /<\/guilabel>/ ) { last ; }
151 $imprimir = 1;
153 if ( $imprimir == 0 ) { print (OUT $_); }
154 else {
155 my $impreso=0;
156 foreach my $theMessage (sort keys %string) {
157 if (!($theMessage cmp $Salida)) {
158 my $tag = $string{$Salida} ;
160 if ( $tag cmp "") {
161 $tag =~ s/\\"/"/mg ;
162 print (OUT $tag);
164 else {
165 print (OUT $Salida);
167 $impreso=1;
170 if ( $impreso == 0) {
171 print "No lo encuentro\n##".$Salida."##\n";
172 $impreso=0;
174 $imprimir = 0;
177 close IN;
178 close OUT;
180 #exit 0;
182 sub original ()
184 my $tmp = "";
185 while (<IN>) {
186 if ( !(/^#: /) ) {
187 if ( /msgid ""/) { s/msgid ""\n//; }
188 if ( /msgstr/) {
189 $tmp =~ s/\\n/\n/sg ;
190 $tmp =~ s/\\t/\t/sg ;
191 $tmp =~ s/\\"/"/sg ;
192 $texto_original = $tmp;
193 last ;
195 s/msgid "//;
196 s/\s*"// ;
197 s/"\n// ;
198 s/\n// ;
199 $tmp .= $_;
204 sub traduccion ()
206 my $tmp = "";
207 my $first = 0;
208 if ( /msgstr "/) {
209 if ( /msgstr ""/) {
210 $tmp = "";
211 $first = 1;
212 } else {
213 $tmp = $_;
214 $tmp =~ s/msgstr "//;
215 $tmp =~ s/"\n// ;
218 while (<IN>) {
220 if ( !($_ cmp "\n") ) {
221 $tmp =~ s/\\n/\n/sg ;
222 $tmp =~ s/\\t/\t/sg ;
223 $tmp =~ s/\"/"/sg ;
224 if ( $first == 1 ) { $texto_traducido = "" ; }
225 else { $texto_traducido = $tmp; }
226 last ;
228 $first = 0;
229 s/msgstr "//;
230 s/"\n// ;
231 s/\s*"// ;
232 $tmp .= $_;
234 if ( eof IN ) {
235 $tmp =~ s/\\n/\n/sg ;
236 $tmp =~ s/\\t/\t/sg ;
237 $tmp =~ s/\"/"/sg ;
238 $texto_traducido = $tmp;