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