1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22 23 24my $completelangiso_var = $ENV{COMPLETELANGISO_VAR}; 25my $lastcompletelangiso_var;; 26my $outfile = ""; 27 28if ( !defined $completelangiso_var) { 29 print STDERR "ERROR: No language defined!\n"; 30 exit 1; 31} 32 33my $poorhelplocalizations_var = $ENV{WITH_POOR_HELP_LOCALIZATIONS}; 34my %poorhelplocalizations; 35foreach $lang (split (/ /, $poorhelplocalizations_var)) { 36 $poorhelplocalizations{$lang}++; 37} 38 39startup_check(); 40if ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) { 41 print STDERR "No new languages. Keeping old file\n"; 42 exit 0; 43} 44 45my @completelangiso = split " +", $completelangiso_var; 46 47open OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n"; 48 49print OUTFILE "// generated file, do not edit\n\n"; 50print OUTFILE "// languages used for last time generation\n"; 51print OUTFILE "// completelangiso: $completelangiso_var\n\n"; 52write_ALL_LANG(); 53write_OTHER_LANGS(); 54write_DIR_ISOLANGUAGE_ALL_LANG_2(); 55write_DIR_ISOLANGUAGE_ALL_LANG(); 56write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ(); 57write_DIR_IDENT_ALL_LANG(); 58write_EXTRA_ALL_LANG(); 59write_EXTRA_ALL_LANG_BUT_EN_US(); 60write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG(); 61write_EXTRA_IDENT_ALL_LANG(); 62write_RESFILE_ALL_LANG(); 63write_SHORT_RESFILE_ALL_LANG(); 64write_README_ALL_LANG(); 65write_README_TXT_ALL_LANG(); 66write_VALUE_ALL_LANG_LETTER_DIR(); 67write_KEY_ALL_LANG_LETTER(); 68write_FILE_ALL_LANG_LETTER(); 69 70close OUTFILE; 71 72 73sub write_ALL_LANG 74{ 75 print OUTFILE "#define ALL_LANG(ident, resid) "; 76 foreach $lang (@completelangiso) { 77 print OUTFILE "\\\n\tident ($lang) = resid"; 78 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 79 } 80 print OUTFILE "\n\n"; 81} 82 83sub write_OTHER_LANGS 84{ 85 print OUTFILE "#define OTHER_LANGS "; 86 foreach $lang (@completelangiso) { 87 next if ( $lang eq "en-US"); 88 print OUTFILE "\\\n\tDosName ($lang) = \"$lang\""; 89 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 90 } 91 print OUTFILE "\n\n"; 92} 93 94sub write_DIR_ISOLANGUAGE_ALL_LANG_2 95{ 96 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_2 "; 97 print OUTFILE "\\\n\tDosName (en-US) = \"en-US\"; \\\n\t"; 98 print OUTFILE "OTHER_LANGS"; 99 print OUTFILE "\n\n"; 100} 101 102sub write_DIR_ISOLANGUAGE_ALL_LANG 103{ 104 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG "; 105 print OUTFILE "\\\n\tDosName (en-US) = \"en\"; \\\n\t"; 106 print OUTFILE "OTHER_LANGS"; 107 print OUTFILE "\n\n"; 108} 109 110sub write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ 111{ 112 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_LPROJ "; 113 foreach $lang (@completelangiso) { 114 my $speciallang = $lang; 115 if ( $speciallang eq "en-US" ) { $speciallang = "en"; } 116 print OUTFILE "\\\n\tDosName ($lang) = \"$speciallang.lproj\""; 117 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 118 } 119 print OUTFILE "\n\n"; 120} 121 122sub write_DIR_IDENT_ALL_LANG 123{ 124 print OUTFILE "#define DIR_IDENT_ALL_LANG(name) "; 125 foreach $lang (@completelangiso) { 126 print OUTFILE "\\\n\tDosName ($lang) = STRING(name)"; 127 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 128 } 129 print OUTFILE "\n\n"; 130} 131 132sub write_EXTRA_ALL_LANG 133{ 134 print OUTFILE "#define EXTRA_ALL_LANG(name,ext) "; 135 foreach $lang (@completelangiso) { 136 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)"; 137 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 138 } 139 print OUTFILE "\n\n"; 140} 141 142sub write_EXTRA_ALL_LANG_BUT_EN_US 143{ 144 print OUTFILE "#define EXTRA_ALL_LANG_BUT_EN_US(name,ext) "; 145 my $first = 1; 146 foreach $lang (@completelangiso) { 147 if ($lang ne "en-US") { 148 print OUTFILE "; " unless $first; 149 $first = 0; 150 print OUTFILE 151 "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)"; 152 } 153 } 154 print OUTFILE "\n\n"; 155} 156 157sub write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG 158{ 159 my $first = 1; 160 print OUTFILE "#define EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG(name) "; 161 foreach $lang (@completelangiso) { 162 next if ( $poorhelplocalizations{$lang} ); 163 print OUTFILE ";" unless $first; 164 $first = 0; 165 print OUTFILE "\\\n\tName ($lang) = EXTRAFILENAME(name,_$lang)"; 166 } 167 print OUTFILE "\n\n"; 168} 169 170sub write_EXTRA_IDENT_ALL_LANG 171{ 172 print OUTFILE "#define EXTRA_IDENT_ALL_LANG(name) "; 173 foreach $lang (@completelangiso) { 174 print OUTFILE "\\\n\tName ($lang) = STRING(name)"; 175 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 176 } 177 print OUTFILE "\n\n"; 178} 179 180sub write_RESFILE_ALL_LANG 181{ 182 print OUTFILE "#define RESFILE_ALL_LANG(name) "; 183 foreach $lang (@completelangiso) { 184 print OUTFILE "\\\n\tName ($lang) = RESFILENAME(name,$lang)"; 185 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 186 } 187 print OUTFILE "\n\n"; 188} 189 190sub write_SHORT_RESFILE_ALL_LANG 191{ 192 print OUTFILE "#define SHORT_RESFILE_ALL_LANG(name) "; 193 foreach $lang (@completelangiso) { 194 print OUTFILE "\\\n\tName ($lang) = SHORTRESFILENAME(name,$lang)"; 195 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 196 } 197 print OUTFILE "\n\n"; 198} 199 200sub write_README_ALL_LANG 201{ 202 print OUTFILE "#define README_ALL_LANG(key, name) "; 203 foreach $lang (@completelangiso) { 204 print OUTFILE "\\\n\tkey ($lang) = READMEFILENAME(name,_$lang)"; 205 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 206 } 207 print OUTFILE "\n\n"; 208} 209 210sub write_README_TXT_ALL_LANG 211{ 212 print OUTFILE "#define README_TXT_ALL_LANG(key, name, ext) "; 213 foreach $lang (@completelangiso) { 214 print OUTFILE "\\\n\tkey ($lang) = READMETXTFILENAME(name,_$lang,ext)"; 215 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 216 } 217 print OUTFILE "\n\n"; 218} 219 220# FIXME: Not used at all in OOo?, #i38597# 221sub write_VALUE_ALL_LANG_LETTER_DIR 222{ 223 print OUTFILE "#define VALUE_ALL_LANG_LETTER_DIR "; 224 print OUTFILE "\\\n\tValue (en-US) = STRING(en);"; 225 foreach $lang (@completelangiso) { 226 next if ( $lang eq "en-US"); 227 print OUTFILE "\\\n\tValue ($lang) = STRING($lang)"; 228 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 229 } 230 print OUTFILE "\n\n"; 231} 232 233sub write_KEY_ALL_LANG_LETTER 234{ 235 print OUTFILE "#define KEY_ALL_LANG_LETTER "; 236 foreach $lang (@completelangiso) { 237 print OUTFILE "\\\n\tKey ($lang) = STRING($lang)"; 238 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 239 } 240 print OUTFILE "\n\n"; 241} 242 243sub write_FILE_ALL_LANG_LETTER 244{ 245 print OUTFILE "#define FILE_ALL_LANG_LETTER(name, ext) "; 246 foreach $lang (@completelangiso) { 247 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,$lang,ext)"; 248 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]); 249 } 250 print OUTFILE "\n\n"; 251} 252 253sub startup_check 254{ 255 my $i; 256 for ( $i=0; $i <= $#ARGV; $i++) { 257 if ( "$ARGV[$i]" eq "-o" ) { 258 if ( defined $ARGV[ $i + 1] ) { 259 $outfile = $ARGV[ $i + 1]; 260 } else { 261 usage(); 262 } 263 } 264 } 265 usage() if $i<2; 266 usage() if "$outfile" eq ""; 267 if ( -f "$outfile" ) { 268 # changed script - run allways 269 return if (stat($0))[9] > (stat("$outfile"))[9] ; 270 271 open OLDFILE, "$outfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n"; 272 while ( $line = <OLDFILE> ) { 273 if ( $line =~ /^\/\/.*completelangiso:/ ) { 274 $lastcompletelangiso_var = $line; 275 chomp $lastcompletelangiso_var; 276 $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//; 277 last; 278 } 279 280 } 281 close OLDFILE; 282 } 283} 284 285sub usage 286{ 287 print STDERR "Generate language dependend macros use in *.scp files\n"; 288 print STDERR "perl $0 -o outputfile\n"; 289 exit 1; 290} 291