|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 # ============================================================================ |
|
17 # Name : gen_localization_iby.pl |
|
18 # Part of : generate iby fole to select correct localised resources for ROM |
|
19 # Origin : S60,NMP |
|
20 # Created : Tue May 26 11:32:47 2007 |
|
21 # Description: |
|
22 # |
|
23 |
|
24 use strict; |
|
25 use File::Find; # for finding |
|
26 use File::Basename; # for fileparse |
|
27 use Getopt::Long; |
|
28 |
|
29 # |
|
30 # Variables... |
|
31 # |
|
32 my $version = "V0.1"; |
|
33 my $outputfile = "localized_resources.iby"; # exclude file for cenrep |
|
34 my $input; # inputfile |
|
35 my @lang_ids; |
|
36 |
|
37 my %macro_definitions = ( |
|
38 "RESOURCE_FILES_LOCALIZED" => "data\=DATAZ_\\RESOURCE_FILES_DIR\\\#\# NAME \#\# .r \#\# ID RESOURCE_FILES_DIR\\\#\# NAME \#\# .r \#\# ID", |
|
39 "APP_RESOURCE_LOCALIZED" => "data\=DATAZ_\\APP_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID APP_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID", |
|
40 "ECOM_RESOURCE_LOCALIZED" => "data\=DATAZ_\\ECOM_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID ECOM_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID", |
|
41 "MTM_RESOURCE_LOCALIZED" => "data\=DATAZ_\\MTM_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID MTM_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID", |
|
42 "MTM_INFO_FILE_LOCALIZED" => "data\=DATAZ_\\MTM_INFO_FILE_DIR\\\#\# NAME \#\# .r \#\# ID MTM_INFO_FILE_DIR\\\#\# NAME \#\# .r \#\# ID", |
|
43 "CONTACTS_RESOURCE_LOCALIZED" => "data\=DATAZ_\\CONTACTS_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID CONTACTS_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID", |
|
44 "FEP_RESOURCES_LOCALIZED" => "data\=DATAZ_\\FEP_RESOURCES_DIR\\\#\# NAME \#\# .r \#\# ID FEP_RESOURCES_DIR\\\#\# NAME \#\# .r \#\# ID", |
|
45 "UIKLAF_RESOURCE_LOCALIZED" => "data\=DATAZ_\\UIKLAF_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID UIKLAF_RESOURCE_DIR\\\#\# NAME \#\# .r \#\# ID", |
|
46 "HELP_FILE_LOCALIZED" => "data\=DATAZ_\\HELP_FILE_DIR\\\#\# NAME \#\# .r \#\# ID HELP_FILE_DIR\\\#\# NAME \#\# .r \#\# ID" |
|
47 ); |
|
48 # END Variation Table |
|
49 |
|
50 |
|
51 my $result = GetOptions('i=s' => \$input); |
|
52 |
|
53 if (!$result){die("Required Argument(s) are missing or wrong");} |
|
54 |
|
55 if ($input eq "") { |
|
56 my $given_cmd=$0; |
|
57 $given_cmd =~ s/.*\\(\w+\.\w+)$/$1/; |
|
58 |
|
59 print "This is localization_resource.iby generator\n"; |
|
60 print "This generate localization_resource.iby base on language ids.\n"; |
|
61 print "\tUsed language ids can given in input file where all ids are listed\n"; |
|
62 print "\tor input can be a path where all langage ids are listed as folder\n"; |
|
63 print "Usage :\n"; |
|
64 print "Usage : $given_cmd -i <input file>\n"; |
|
65 print "Usage : $given_cmd -i <input folder>\n"; |
|
66 exit 0; |
|
67 } |
|
68 |
|
69 if (!get_lang_ids()){die("No input file or folder exists!");} |
|
70 |
|
71 open (OUTPUT,">$outputfile") or die("Cannot open $outputfile"); |
|
72 |
|
73 create_iby(); |
|
74 close OUTPUT; |
|
75 |
|
76 sub create_iby { |
|
77 usage(); |
|
78 macros(); |
|
79 language_switch(); |
|
80 } |
|
81 |
|
82 sub usage { |
|
83 my $given_command=$0; |
|
84 $given_command =~ s/.*\\(\w+\.\w+)$/$1/; |
|
85 print OUTPUT "\/*\n"; |
|
86 print OUTPUT "* This has generated by $given_command. Do not edit manually.\n*\n"; |
|
87 |
|
88 print OUTPUT "* This file selected correct localised resources for ROM image base on languages\n"; |
|
89 print OUTPUT "* This file should be used only for localised resources\n*\n"; |
|
90 |
|
91 print OUTPUT "* Define user localized macro to get correct localized resources to ROM image\n"; |
|
92 print OUTPUT "* All paltform supported languages are included by default\n"; |
|
93 print OUTPUT "* Macros LANGUAGE_<id> or NO_LANGUAGE_<id> can be used to change supported component languages\n"; |
|
94 print OUTPUT "* First define used macro and after macro definition should include this file\n"; |
|
95 print OUTPUT "* All user defined macros are undefineded end of this file\n"; |
|
96 |
|
97 print OUTPUT "*\n* Usage in iby file:\n"; |
|
98 print OUTPUT "* \#define \[user localized macro\] \[resource file name\]\n"; |
|
99 print OUTPUT "* \#include \<Variant\/localized_resources.iby\>\n"; |
|
100 |
|
101 print OUTPUT "*\n* How to include correct localised 'example' resources in 'example_variant.iby':\n"; |
|
102 print OUTPUT "* \#define USER_APP_RESOURCE_LOCALIZED example\n"; |
|
103 print OUTPUT "* \#include \<Variant\/localized_resources.iby\>\n"; |
|
104 |
|
105 print OUTPUT "*\n* How to specify languages that component support\n"; |
|
106 print OUTPUT "* \#define USER_APP_RESOURCE_LOCALIZED example\n"; |
|
107 print OUTPUT "* \#define LANGUAGE_01\n"; |
|
108 print OUTPUT "* \#define LANGUAGE_02\n"; |
|
109 print OUTPUT "* \#include \<Variant\/localized_resources.iby\>\n"; |
|
110 |
|
111 |
|
112 print OUTPUT "*\n* How to exclude languages that component do not support\n"; |
|
113 print OUTPUT "* \#define USER_APP_RESOURCE_LOCALIZED example\n"; |
|
114 print OUTPUT "* \#define NO_LANGUAGE_29\n"; |
|
115 print OUTPUT "* \#define NO_LANGUAGE_159\n"; |
|
116 print OUTPUT "* \#include \<Variant\/localized_resources.iby\>\n"; |
|
117 |
|
118 print OUTPUT "*\n* Supported user localized macros (source=<path in environment>,target=<path in ROM image>):\n"; |
|
119 |
|
120 foreach my $macro (sort keys %macro_definitions) { |
|
121 my $paths = $macro_definitions{$macro}; |
|
122 $paths =~ s/^data=//i; |
|
123 |
|
124 my $src = $paths; |
|
125 $src =~ s/\#.*//i; |
|
126 $paths =~ s/.*ID\s+//i; |
|
127 |
|
128 my $trg = $paths; |
|
129 $trg =~ s/\#.*//i; |
|
130 |
|
131 print OUTPUT "* USER_${macro}\t(source=$src,target=$trg)\n"; |
|
132 } |
|
133 |
|
134 print OUTPUT "*\/\n\n"; |
|
135 } |
|
136 |
|
137 sub macros { |
|
138 my $postfix = "_INTERNAL"; |
|
139 |
|
140 print OUTPUT "\n\/\/ Define macros used in this file\n"; |
|
141 |
|
142 foreach my $macro (sort keys %macro_definitions) { |
|
143 print OUTPUT "\#define ${macro}${postfix}(NAME,ID) $macro_definitions{$macro}\n"; |
|
144 print OUTPUT "\#define ${macro}(NAME,ID) ${macro}${postfix}(NAME,ID)\n"; |
|
145 } |
|
146 |
|
147 print OUTPUT "\n"; |
|
148 } |
|
149 |
|
150 sub language_switch { |
|
151 my $use_selected_macro = "USE_SELECTED_LANGUAGES"; |
|
152 my $locales = "__LOCALES_%ID%_IBY__"; # |
|
153 my $lang = "LANGUAGE_"; # + id |
|
154 my $no_lang = "NO_LANGUAGE_"; # + id |
|
155 |
|
156 |
|
157 #check if only some languages should include |
|
158 |
|
159 print OUTPUT "\n\/\/ Check is only some languages in use\n"; |
|
160 |
|
161 my $counter = 0; |
|
162 foreach my $id (@lang_ids) { |
|
163 if (!$counter) { |
|
164 print OUTPUT "\#if defined(${lang}${id})"; |
|
165 } |
|
166 else { |
|
167 print OUTPUT "\ || defined(${lang}${id})"; |
|
168 } |
|
169 $counter++; |
|
170 } |
|
171 |
|
172 print OUTPUT "\n \#define ${use_selected_macro}\n\#endif\n\n"; |
|
173 |
|
174 #define macros by language |
|
175 print OUTPUT "\/\/ Selectors for language macros\n"; |
|
176 foreach my $id (@lang_ids) { |
|
177 my $line = "\#if defined(${locales}) && (!defined(${use_selected_macro}) || defined(${lang}${id})) && !defined(${no_lang}${id})\n"; |
|
178 $line =~ s/%ID%/${id}/; |
|
179 print OUTPUT "$line"; |
|
180 |
|
181 my $predef = " \#if defined"; |
|
182 foreach my $macro (sort keys %macro_definitions) { |
|
183 print OUTPUT "${predef} USER_${macro}\n"; |
|
184 $predef = " \#elif defined"; |
|
185 print OUTPUT " ${macro}(USER_${macro}, ". lc $id .")\n"; |
|
186 } |
|
187 # end macro definition |
|
188 print OUTPUT " \#endif\n"; |
|
189 |
|
190 # end language definition |
|
191 print OUTPUT "\#endif\n"; |
|
192 print OUTPUT "\#undef ${no_lang}${id}\n"; |
|
193 print OUTPUT "\#undef ${lang}${id}\n\n"; |
|
194 } |
|
195 |
|
196 |
|
197 |
|
198 print OUTPUT "\/\/ Undefine user macros\n"; |
|
199 # print OUTPUT "\n\#endif\n\n"; |
|
200 foreach my $macro (sort keys %macro_definitions) { |
|
201 print OUTPUT "\#undef USER_${macro}\n"; |
|
202 } |
|
203 |
|
204 print OUTPUT "\#undef ${use_selected_macro}\n"; |
|
205 } |
|
206 |
|
207 sub get_lang_ids { |
|
208 if (-f $input) { |
|
209 open (INPUT,"$input") or die("Cannot open file $input"); |
|
210 while (<INPUT>) { |
|
211 chomp; #Remove line feed and carriage return |
|
212 next if (/^\/\//); # Skip comment lines |
|
213 next if (/^#/); # Skip comment lines |
|
214 next if (/^ *$/); # Skip empty lines |
|
215 |
|
216 $_ =~ s/\s//gi; # remove white spaces |
|
217 |
|
218 push (@lang_ids,uc $_); # for zipping |
|
219 } |
|
220 |
|
221 close INPUT; |
|
222 return 1; |
|
223 } |
|
224 elsif (-d $input) { |
|
225 opendir(SDIR, $input) or die("can not read folder $input\n"); |
|
226 my @folders = grep !/^\.\.?$/, readdir SDIR; |
|
227 closedir(SDIR); |
|
228 |
|
229 push (@lang_ids,"SC"); |
|
230 |
|
231 foreach (@folders) { |
|
232 next if (!/^\d+$/); |
|
233 |
|
234 push (@lang_ids,uc $_); |
|
235 } |
|
236 return 1; |
|
237 } |
|
238 |
|
239 return 0; |
|
240 } |