aboutsummaryrefslogtreecommitdiffstats
path: root/help/update_translation.pl
blob: 0023b069d19bb2519793edfaf7802f6c03c425fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/perl -w 
#
#  Script that translates .sgml files using the .po files generated from
#  the script update_po.pl
#
#  Copyright (C) 2001 Héctor García Álvarez.
#
#  This library 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 script 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
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this library; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
#  Authors: Héctor García Álvarez <hector@scouts-es.org>

## Loaded modules
use File::Basename;
use Getopt::Long;

my $LANG = $ARGV[0];

my %string;
my $texto_original="";
my $texto_traducido="";

if (! $LANG){
    print "Usage: update_translation.pl LANGCODE\n";
    exit;
}

chdir ("./C");

## Reading the po file
#print "Loading ".$LANG.".po\n";
#&load_translated_strings ($LANG.".po");

## Checking for the lang dir
if ( !(-d "../".$LANG) ) { mkdir ("../".$LANG, 0755) ; }

open FILES, "<POTFILES.in" ;
while (<FILES>) {
    undef %string;
    s/\n//g;
    $Original_file = $_ ;
    s/.\///g;
    $Translated_file = "../".$LANG."/".$_;
#   print $Original_file."\n";
#   print $Translated_file."\n";
    &load_translated_strings ("../".$LANG.".po/".$_.".po");
    print "Translating ".$Original_file ;
    system "rm -f $Translated_file";
    &translate_file ($Translated_file , $Original_file);
    print ".\n";
}
close FILES;                                

exit 0;




sub load_translated_strings () 
{
    my $FILE=$_[0];
    open (IN, "<$FILE") || die "I can't find $FILE";

    while (<IN>) {
            if ( /#: /) {
            &original;
            &traduccion;
#               print "Original \n##".$texto_original."##\n";
#               print "Traducción \n##".$texto_traducido."##\n";
                    $string{$texto_original} = $texto_traducido;
        }
    }
    close (IN);
}

sub translate_file ()
{
    my $OUTFILE=$_[0];
    my $INFILE=$_[1];
    
    open OUT, ">>$OUTFILE";
    open (IN, "<$INFILE") || die "can't open $INFILE: $!";

    while (<IN>) {
        my $imprimir = 0;
        if ( /<!--/ ) {
            $Salida =  $_ ;
            if ( !(/-->/) ) {
                while (<IN>) {
                    $Salida .=  $_ ;
                    if ( /-->/ ) { last ; }
                }
            }
            $imprimir = 1;
        }
        elsif ( /<para>/ ) {
            my $number_of_para = 1;
            $Salida = $_ ;
            if ( !(/<\/para>/) ) {
                while (<IN>) {
                    if ( /<para>/ ) { $number_of_para++; }
                    $Salida .=  $_ ;
                    if ( /<\/para>/ ) {
                        $number_of_para--;
                        if ( $number_of_para==0) {last ; }
                    }
                }
            }
            $imprimir = 1;
        }
        elsif ( /<title>/ ) {
            $Salida = $_ ;
            if ( !(/<\/title>/) ) {
                while (<IN>) {
                    $Salida .=  $_ ;
                    if ( /<\/title>/ ) { last ; }
                }
            }
            $imprimir = 1;
        }
        elsif ( /<glossterm>/ ) {
            $Salida = $_ ;
            if ( !(/<\/glossterm>/) ) {
                while (<IN>) {
                    $Salida .=  $_ ;
                    if ( /<\/glossterm>/ ) { last ; }
                }
            }
            $imprimir = 1;
        }
        elsif ( /<guilabel>/ ) {
            $Salida = $_ ;
            if ( !(/<\/guilabel>/) ) {
                while (<IN>) {
                    $Salida .=  $_ ;
                    if ( /<\/guilabel>/ ) { last ; }
                }
            }
            $imprimir = 1;
        }
            if ( $imprimir == 0 ) {  print (OUT $_); }
        else { 
            my $impreso=0;
            foreach my $theMessage (sort keys %string) {
                if (!($theMessage cmp $Salida)) {
                    my $tag = $string{$Salida} ;
                    
                    if ( $tag cmp "") {
                        $tag =~ s/\\"/"/mg ;
                        print (OUT $tag);
                    }
                    else {
                        print (OUT $Salida);
                    }
                    $impreso=1;
                }
            }
            if ( $impreso == 0) {
                print "No lo encuentro\n##".$Salida."##\n";
                $impreso=0;
            } 
            $imprimir = 0;
        }
    }
    close IN;
    close OUT;
}
#exit 0;

sub original () 
{
    my $tmp = "";
    while (<IN>) {
        if ( !(/^#: /) ) {
            if ( /msgid ""/) { s/msgid ""\n//; }
            if ( /msgstr/) {
                $tmp =~ s/\\n/\n/sg ;
                $tmp =~ s/\\t/\t/sg ;
                $tmp =~ s/\\"/"/sg ;
                $texto_original = $tmp;
                last ;
            }
            s/msgid "//;
            s/\s*"// ;
            s/"\n// ;
            s/\n// ;
            $tmp .=  $_;
        }
    }
}
        
sub traduccion ()
{
        my $tmp = "";
    my $first = 0;
    if ( /msgstr "/) {
        if ( /msgstr ""/) {
            $tmp = "";
            $first = 1;
        } else {
            $tmp = $_;
            $tmp =~ s/msgstr "//;
            $tmp =~ s/"\n// ;
        }
    }
    while (<IN>) {
    
        if ( !($_ cmp "\n") )  {
            $tmp =~ s/\\n/\n/sg ;
            $tmp =~ s/\\t/\t/sg ;
            $tmp =~ s/\"/"/sg ;
            if ( $first == 1 ) { $texto_traducido = "" ; }
            else { $texto_traducido = $tmp; }
            last ;
        }
        $first = 0;
        s/msgstr "//;
        s/"\n// ;
        s/\s*"// ;
        $tmp .=  $_;    
    }
    if ( eof IN ) {
        $tmp =~ s/\\n/\n/sg ;
        $tmp =~ s/\\t/\t/sg ;
        $tmp =~ s/\"/"/sg ;
        $texto_traducido = $tmp; 
    }
}
5-06 22:21:51 +0800'>2004-05-062-1/+23 * don't depend on perl when build WITHOUT_PERL.eik2004-05-061-1/+4 * update to exim 4.33 + exiscan 20eik2004-05-058-557/+27 * upgrade to exiscan-acl version 19:eik2004-05-012-8/+4 * - update to exiscan-acl version 18eik2004-04-297-34/+609 * Update to Exim release 4.32 + exiscan 17eik2004-04-152-6/+6 * - update to Exim 4.31:eik2004-04-013-9/+17 * - update exiscan-acl to version -16eik2004-03-103-4/+6 * Hand over to eik, who will give the port the attention it deserves. Ifsheldonh2004-03-091-1/+1 * Enabled passwd lookups by default; while the world is moving away fromsheldonh2004-02-181-3/+9 * USE_ICONV.sheldonh2004-02-041-1/+1 * Fix creation of /var/log/exim, which I botched when making EXIM_USERsheldonh2004-01-313-12/+12 * Provide support for Berkeley DB 4.2, through WITH_BDB_VER=42.sheldonh2004-01-211-3/+7 * Silence two portlint warnings.sheldonh2004-01-121-6/+5 * 1) Fix build for the WITHOUT_ALT_CONFIG_PREFIX case.sheldonh2004-01-124-11/+24 * Look for WITHOUT_DNSDB as advertised, not WITH_DNSDB.sheldonh2004-01-071-1/+1 * Update to 4.30.sheldonh2004-01-064-36/+22 * Don't disclose FreeBSD version in Received headers; just disclose thatsheldonh2003-11-121-2/+2 * Suggest uncommenting ScanMail in POST-INSTALL-NOTES.clamd.sheldonh2003-11-042-1/+2 * Fix patch path problem in previous delta. *blush*sheldonh2003-10-301-2/+2 * * Remove old saslauthd bugfix, included in 4.24.sheldonh2003-10-293-49/+18 * Update to exiscan-acl-4.24-13, which is a bugfix release.sheldonh2003-10-222-2/+7 * Correct misspelt exim-postgresql conflict.sheldonh2003-10-141-1/+1 * WARNING: See caution at the end of this bullet list.sheldonh2003-09-298-218/+185 * Fix another SASLAUTHD segfault.sheldonh2003-09-101-0/+12 * Bring the Exim port closer to use as an install-time sendmailsheldonh2003-09-1010-61/+245 * Update to exiscan-acl patch -12:sheldonh2003-09-042-3/+3 * Exim updates:sheldonh2003-09-022-22/+11 * Add a wishlist patch that introduces new expansion operator eqi, whichsheldonh2003-08-311-0/+90 * Don't core dump on saslauthd lookups without service and realm.sheldonh2003-08-302-0/+13 * Import my exiscan-acl clamd virus scanner integration notes.sheldonh2003-08-254-1/+82 * Add support for Cyrus SASL authentication daemon, enabled if WITH_SASLAUTHDsheldonh2003-08-241-2/+14 * This file should have gone away when the second update to 4.21 occurred.sheldonh2003-08-191-10/+0 * Update to exim-4.22:sheldonh2003-08-19