moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kturtle / scripts / i18n_examples.pl
blob9329a0f9d784752466aeb6b101138e5381edcc01
1 #!/usr/bin/perl -w
3 # Copyright (C) 2004-2005 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 generate localized KTurtle logo code.
26 # Usage: ./i18n_examples.pl logokeywords.YOURLANGCODE.xml
28 # e.g.:
29 # $./i18n_examples.pl logokeywords.es.xml
31 # arrow.logo -> arrow.es.LOGO
32 # canvascolors.logo -> canvascolors.es.LOGO
33 # curly.logo -> curly.es.LOGO
35 # NOTES:
36 # - You'll need logokeywords.YOURLANGCODE.xml under kturtle/scripts
37 # - Commented lines, variable names, and strings like
38 # "What's your name?" must be translated by hand.
39 # - You might want to rename the resulting files to something
40 # into your own language e.g. arrow.es.LOGO to flecha.LOGO
41 # - Please, if the script is not working for you report it to
42 # KDE-Edu mailing list.
46 use strict;
48 my @en_commands;
49 my $langcode;
50 my @mylang_commands;
51 my %commands;
52 my $i;
53 my @examples= glob "../data/*.logo";
54 my $filename;
55 my $line;
58 #Get the langcode we are translating to
59 $_ = $ARGV[0];
60 if (/logokeywords.(\w+).xml/){
61 $langcode = $1;
64 #Get en_US commands
65 open EN_COMMANDS, "<../data/logokeywords.en_US.xml"
66 or die "Cannot open logokeywords.en_US.xml";
67 $i=0;
68 while (<EN_COMMANDS>){
69 if (/<keyword>(.*)<\/keyword>/){
70 $en_commands[$i]=$1;
71 $i++;
73 elsif (/<alias>(.*)<\/alias>/){
74 $en_commands[$i]=$1;
75 $i++;
79 close EN_COMMANDS;
81 #Get commands for the given language
82 $i=0;
83 while(<>){
84 if (/<keyword>(.*)<\/keyword>/){
85 $mylang_commands[$i]=$1;
86 $commands{$en_commands[$i]}=$mylang_commands[$i];
87 $i++;
89 elsif (/<alias>(.*)<\/alias>/){
90 $mylang_commands[$i]=$1;
91 $commands{$en_commands[$i]}=$mylang_commands[$i];
92 $i++;
98 #Remove brackets from @en_commands (they aren't needed here)
99 #Brackets will be managed in a different way later
100 shift @en_commands;
101 shift @en_commands;
104 #Parse *.logo and generate the homologous for the given language
105 foreach (@examples){
106 if (m%^../data/(\w+).logo%){$filename="$1".".$langcode."."logo";}
107 else{die "Error: Check if you have ../data/*.logo files";}
108 printf "\n%-25s > ./%s \n", $_, $filename;
109 open EXAMPLE,"<$_"
110 or die "Cannot open $_ \n";
111 while (<EXAMPLE>){
112 #Manage comments (they do not get translated)
113 if (/^#(.*)/){
114 open TRANSLATION,">>$filename";
115 select TRANSLATION;
116 print "#$1\n";
117 select STDOUT;}
118 #Manage tabulated "for .. to .." lines
119 elsif (/(^\s+)(\bfor\b)(.*)(\bto\b)/){
120 chomp ($line = "$1$commands{$2}$3$commands{$4}$'");
121 open TRANSLATION, ">>$filename";
122 select TRANSLATION;
123 print "$line \n";
124 select STDOUT;}
125 #Manage tabulated brackets
126 elsif (/(^\s+)(\p{IsPunct})/){
127 open TRANSLATION,">>$filename";
128 select TRANSLATION;
129 print "$1$2\n";
130 select STDOUT;}
131 #Manage any other tabulated line
132 elsif (/(^\s+)(\w+)/){
133 my $tab=$1;
134 if ($commands{$2}){
135 chomp ($line = "$commands{$2}$'");
137 elsif (/([=])(\s+)(\w+)/){
138 if ($commands{$3}){
139 $tab="";
140 chomp ($line = "$`$1$2$commands{$3}$'");
143 elsif (/([=])(\w+)/){
144 if ($commands{$2}){
145 chomp ($line = "$`$1$commands{$2}$'");
148 else
150 chomp ($line = "$2$'");
152 open TRANSLATION,">>$filename";
153 select TRANSLATION;
154 print "$tab$line\n";
155 select STDOUT;}
156 #Manage "for .. to .." lines
157 elsif (/(^\bfor\b)(.*)(\bto\b)/){
158 chomp (my $line = "$commands{$1}$2$commands{$3}$'");
159 open TRANSLATION, ">>$filename";
160 select TRANSLATION;
161 print "$line\n";
162 select STDOUT;}
163 #Manage any other line of code
164 elsif (/(^\w+)/){
165 if ($commands{$&}){
166 chomp ($line = "$commands{$&}$'");
168 elsif (/([=])(\s+)(\w+)/){
169 if ($commands{$3}){
170 chomp ($line = "$`$1$2$commands{$3}$'");
173 elsif (/([=])(\w+)/){
174 if ($commands{$2}){
175 chomp ($line = "$`$1$commands{$2}$'");
178 else{
179 chomp ($line = "$1$'");
181 open TRANSLATION, ">>$filename";
182 select TRANSLATION;
183 print "$line \n";
184 select STDOUT;
186 #Manage brackets
187 elsif (/\p{IsPunct}/){
188 open TRANSLATION,">>$filename";
189 select TRANSLATION;
190 print "$&\n";
191 select STDOUT;}
192 #Manage empty lines
193 elsif (/^\s+/){
194 open TRANSLATION,">>$filename";
195 select TRANSLATION;
196 print "\n";
197 select STDOUT;}
202 print <<EOF;
204 The translation of KTurtle examples is almost DONE...
205 You will need to translate the following by hand:
206 1) Commented lines,
207 2) Variable names (if any of them is named in english or represents a reserved word in your language),
208 3) Strings like "What's your name?"
209 4) File names
211 Thanks a lot!