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