Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / toolkit / mozapps / installer / windows / nsis / preprocess-locale.pl
blob1c50c73a4081623c74c1c6935ec3b3844e2309d0
1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
12 # License.
14 # The Original Code is Mozilla installer build scripts.
16 # The Initial Developer of the Original Code is Mozilla Foundation
17 # Portions created by the Initial Developer are Copyright (C) 2006
18 # the Initial Developer. All Rights Reserved.
20 # Contributor(s):
21 # Robert Strong <robert.bugzilla@gmail.com>
23 # Alternatively, the contents of this file may be used under the terms of
24 # either the GNU General Public License Version 2 or later (the "GPL"), or
25 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 # in which case the provisions of the GPL or the LGPL are applicable instead
27 # of those above. If you wish to allow use of your version of this file only
28 # under the terms of either the GPL or the LGPL, and not to allow others to
29 # use your version of this file under the terms of the MPL, indicate your
30 # decision by deleting the provisions above and replace them with the notice
31 # and other provisions required by the GPL or the LGPL. If you do not delete
32 # the provisions above, a recipient may use your version of this file under
33 # the terms of any one of the MPL, the GPL or the LGPL.
35 # ***** END LICENSE BLOCK *****
37 my $topsrcdir = "$ARGV[0]";
38 my $appLocaleDir = "$ARGV[1]";
39 my $AB_CD = "$ARGV[2]";
40 my $langCP = "$ARGV[3]";
41 my $configDir = "$ARGV[4]";
42 my $nsisVer = "v6";
43 # Set the language ID to 0 to make this locale the default locale. An actual
44 # ID will need to be used to create a multi-language installer (e.g. for CD
45 # distributions, etc.).
46 my $langID = 0;
47 my $nsisCP = "-";
48 my $fontName = "-";
49 my $fontSize = "-";
50 my $RTL = "-";
51 my $line;
52 my $lnum;
54 # Read the codepage for the locale and the optional font name, font size, and
55 # whether the locale is right to left from locales.nsi.
56 my $inFile = "$topsrcdir/toolkit/mozapps/installer/windows/nsis/locales.nsi";
57 open(locales, "<$inFile");
59 $lnum = 1;
60 while( $line = <locales> ) {
61 $line =~ s/[\r\n]*//g; # remove \r and \n
62 if ($line =~ m|^!define $AB_CD\_rtl|) {
63 $RTL = "RTL";
65 $lnum++;
67 close locales;
69 # In NSIS codepage CP1252 is specified with a '-'. For all other locales
70 # specify the number for the locales codepage.
71 if ($langCP ne "CP1252") {
72 $nsisCP = $langCP;
73 $nsisCP =~ s/^CP(.*)$/$1/g;
76 # Create the main NSIS language file with just the codepage, font, and
77 # RTL information
78 open(outfile, ">$configDir/nlf.in");
79 print outfile "# Header, don't edit\r\nNLF $nsisVer\r\n# Start editing here\r\n";
80 print outfile "# Language ID\r\n$langID\r\n";
81 print outfile "# Font and size - dash (-) means default\r\n$fontName\r\n$fontSize\r\n";
82 print outfile "# Codepage - dash (-) means ANSI code page\r\n$nsisCP\r\n";
83 print outfile "# RTL - anything else than RTL means LTR\r\n$RTL\r\n";
84 close outfile;
85 &cpConvert("nlf.in", "baseLocale.nlf", $langCP);
88 # Create the main NSIS language file
89 $inFile = "$appLocaleDir/override.properties";
90 if (!-e $inFile) {
91 die "Error $inFile does not exist!";
93 open(infile, "<$inFile");
94 open(outfile, ">$configDir/override.properties");
95 $lnum = 1;
96 while( $line = <infile> ) {
97 $line =~ s/[\r\n]*//g; # remove \r and \n
98 next if ($line =~ m|^#|);
99 my @values = split('=', $line, 2);
100 next if (@values[0] eq undef) || (@values[1] eq undef);
101 my $value = @values[1];
102 $value =~ s/^\s+//; # trim whitespace from the beginning of the string
103 $value =~ s/\s+$//; # trim whitespace from the end of the string
104 $value =~ s/^"(.*)"$/$1/g; # remove " at the beginning and end of the value
105 $value =~ s/(")/\$\\$1/g; # prefix " with $\
106 $value =~ s/…/.../g; # replace … (unicode ellipsis) with ...
107 print outfile "LangString ^@values[0] $langID \"$value\"\r\n";
108 $lnum++;
110 close infile;
111 close outfile;
112 &cpConvert("override.properties", "overrideLocale.nsh", $langCP);
115 # Create the main Modern User Interface language file
116 $inFile = "$appLocaleDir/mui.properties";
117 if (!-e $inFile) {
118 die "Error $inFile does not exist!";
120 open(infile, "<$inFile");
121 open(outfile, ">$configDir/mui.properties");
122 print outfile ";NSIS Modern User Interface - Language File\r\n";
123 print outfile ";Compatible with Modern UI 1.68\r\n";
124 print outfile ";Language: baseLocale ($langID)\r\n";
125 print outfile "!insertmacro MOZ_MUI_LANGUAGEFILE_BEGIN \"baseLocale\"\r\n";
126 print outfile "!define MUI_LANGNAME \"baseLocale\"\r\n";
128 $lnum = 1;
129 while( $line = <infile> ) {
130 $line =~ s/[\r\n]*//g; # remove \r and \n
131 next if ($line =~ m|^#|) || ($line eq "");
132 my @values = split('=', $line, 2);
133 next if (@values[0] eq undef) || (@values[1] eq undef);
134 my $value = @values[1];
135 $value =~ s/(")/\$\\$1/g; # prefix " with $\
136 $value =~ s/(\\n)/\\r$1/g; # insert \\r before each occurence of \\n
137 $value =~ s/(\\r)\\r/$1/g; # replace all ocurrences of \\r\\r with \\r
138 $value =~ s/…/.../g; # replace … (unicode ellipsis) with ...
139 print outfile "!define @values[0] \"$value\"\r\n";
140 $lnum++;
142 print outfile "!insertmacro MOZ_MUI_LANGUAGEFILE_END\r\n";
143 close infile;
144 close outfile;
145 &cpConvert("mui.properties", "baseLocale.nsh", $langCP);
148 # Create the custom language file for our custom strings
149 $inFile = "$appLocaleDir/custom.properties";
150 if (!-e $inFile) {
151 die "Error $inFile does not exist!";
153 open(infile, "<$inFile");
154 open(outfile, ">$configDir/custom.properties");
156 $lnum = 1;
157 while( $line = <infile> ) {
158 $line =~ s/[\r\n]*//g; # remove \r and \n
159 next if ($line =~ m|^#|) || ($line eq "");
160 my @values = split('=', $line, 2);
161 next if (@values[0] eq undef) || (@values[1] eq undef);
162 my $string = @values[1];
163 $string =~ s/"/\$\\"/g; # replace " with $\"
164 $string =~ s/(\\n)/\\r$1/g; # insert \\r before each occurence of \\n
165 $string =~ s/(\\r)\\r/$1/g; # replace all ocurrences of \\r\\r with \\r
166 $string =~ s/(\\[rn])/\$$1/g; # prefix all occurences of \\r and \\n with $
167 $string =~ s/…/.../g; # replace … (unicode ellipsis) with ...
168 print outfile "LangString @values[0] $langID \"$string\"\r\n";
169 $lnum++;
171 close infile;
172 close outfile;
173 &cpConvert("custom.properties", "customLocale.nsh", $langCP);
176 # Converts a file's codepage
177 sub cpConvert
179 my $srcFile = $_[0];
180 my $targetFile = $_[1];
181 my $targetCodepage = $_[2];
182 print "iconv -f UTF-8 -t $targetCodepage $configDir/$srcFile > $configDir/$targetFile\n";
183 system("iconv -f UTF-8 -t $targetCodepage $configDir/$srcFile > $configDir/$targetFile") &&
184 die "Error converting codepage to $targetCodepage for $configDir/$srcFile";
185 unlink <$configDir/$srcFile>;