moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kturtle / scripts / i18n_highlighting.pl
blob8c3622a1371adca03d083915e20b813266bb01a8
1 #!/usr/bin/perl -w
3 # Copyright (C) 2004 Rafael Beccar <rafael.beccar ! kdemail.net>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of version 2 of the GNU General
7 # Public License as published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public
15 # License along with this program; if not, write to the
16 # Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # Author: Rafael Beccar <rafael.beccar ! kdemail.net>
22 # Bs.As. November 2004
24 # Automagically gen. localized highlighting for KTurtle commands
26 # Usage:
27 # ./i18n_highlighting.pl logokeywords.YOURLANG.xml
29 # E.g.
30 # ./i18n_highlighting.pl logokeywords.es.xml
32 # NOTES:
33 # - You'll need logokeywords.YOURLANGCODE.xml under kturtle/scripts
35 # - The script search for logokeywords.en_US.xml under ../data/
36 # and writes the resulting files under current directory
40 use strict;
42 my $langcode;
43 my @en_commands;
44 my @mylang_commands;
45 my %commands;
46 my $i;
47 my $line;
49 #Give message if no parameter passed
50 if (! $ARGV[0]){
51 die "Usage:\n ./i18n_highlighting.pl logokeywords.YOURLANG.xml";}
53 #Get the langcode we are translating to
54 $_ = $ARGV[0];
55 if (/logokeywords.(\w+).xml/){
56 $langcode = $1;
59 #Get en_US commands
60 open EN_COMMANDS, "<../data/logokeywords.en_US.xml"
61 or die "Cannot open ../data/logokeywords.en_US.xml";
62 $i=0;
63 while (<EN_COMMANDS>){
64 if (/<keyword>(.*)<\/keyword>/){
65 $en_commands[$i]=$1;
66 $i++;
68 elsif (/<alias>(.*)<\/alias>/){
69 $en_commands[$i]=$1;
70 $i++;
74 close EN_COMMANDS;
76 #Get commands for the given language
77 $i=0;
78 while(<>){
79 if (/<keyword>(.*)<\/keyword>/){
80 $mylang_commands[$i]=$1;
81 $commands{$en_commands[$i]}=$mylang_commands[$i];
82 $i++;
84 elsif (/<alias>(.*)<\/alias>/){
85 $mylang_commands[$i]=$1;
86 $commands{$en_commands[$i]}=$mylang_commands[$i];
87 $i++;
91 #Remove brackets from @en_commands (they are not needed here)
92 #Brackets will be managed in a different way later
93 shift @en_commands;
94 shift @en_commands;
96 #Set destination
97 my $filename = "logohighlightstyle.${langcode}.xml";
100 #Parse logohighlightstyle.en_US.xml and generate the homologous for the given language
101 open HIGHLIGHT,"<../data/logohighlightstyle.en_US.xml"
102 or die "Cannot open $_ \n";
103 while (<HIGHLIGHT>){
104 #Manage language tag
105 if (m%(en_US)%){
106 open TRANSLATION,">>$filename";
107 select TRANSLATION;
108 print "$`${langcode}$'";
109 select STDOUT;}
110 #Manage translatable lines
111 elsif (m%<item> (\w+) </item>%){
112 if ($commands{$1}){
113 $line = "\t<item> $commands{$1} </item>";}
114 open TRANSLATION,">>$filename";
115 select TRANSLATION;
116 print "$line \n";
117 select STDOUT;
119 #Manage not translatable lines
120 else{
121 open TRANSLATION,">>$filename";
122 select TRANSLATION;
123 print "$_";}
124 select STDOUT;
126 close TRANSLATION;
127 print "DONE... The translated file is:\n $filename \n";