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
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
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.
53 my @examples= glob "../data/*.logo";
58 #Get the langcode we are translating to
60 if (/logokeywords.(\w+).xml/){
65 open EN_COMMANDS
, "<../data/logokeywords.en_US.xml"
66 or die "Cannot open logokeywords.en_US.xml";
68 while (<EN_COMMANDS
>){
69 if (/<keyword>(.*)<\/keyword
>/){
73 elsif (/<alias>(.*)<\/alias>/){
81 #Get commands for the given language
84 if (/<keyword>(.*)<\/keyword
>/){
85 $mylang_commands[$i]=$1;
86 $commands{$en_commands[$i]}=$mylang_commands[$i];
89 elsif (/<alias>(.*)<\/alias>/){
90 $mylang_commands[$i]=$1;
91 $commands{$en_commands[$i]}=$mylang_commands[$i];
98 #Remove brackets from @en_commands (they aren't needed here)
99 #Brackets will be managed in a different way later
104 #Parse *.logo and generate the homologous for the given language
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;
110 or die "Cannot open $_ \n";
112 #Manage comments (they do not get translated)
114 open TRANSLATION
,">>$filename";
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";
125 #Manage tabulated brackets
126 elsif (/(^\s+)(\p{IsPunct})/){
127 open TRANSLATION
,">>$filename";
131 #Manage any other tabulated line
132 elsif (/(^\s+)(\w+)/){
135 chomp ($line = "$commands{$2}$'");
137 elsif (/([=])(\s+)(\w+)/){
140 chomp ($line = "$`$1$2$commands{$3}$'");
143 elsif (/([=])(\w+)/){
145 chomp ($line = "$`$1$commands{$2}$'");
150 chomp ($line = "$2$'");
152 open TRANSLATION
,">>$filename";
156 #Manage "for .. to .." lines
157 elsif (/(^\bfor\b)(.*)(\bto\b)/){
158 chomp (my $line = "$commands{$1}$2$commands{$3}$'");
159 open TRANSLATION
, ">>$filename";
163 #Manage any other line of code
166 chomp ($line = "$commands{$&}$'");
168 elsif (/([=])(\s+)(\w+)/){
170 chomp ($line = "$`$1$2$commands{$3}$'");
173 elsif (/([=])(\w+)/){
175 chomp ($line = "$`$1$commands{$2}$'");
179 chomp ($line = "$1$'");
181 open TRANSLATION
, ">>$filename";
187 elsif (/\p{IsPunct}/){
188 open TRANSLATION
,">>$filename";
194 open TRANSLATION
,">>$filename";
204 The translation of KTurtle examples is almost DONE...
205 You will need to translate the following by hand:
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?"