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
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.
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]";
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.).
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");
60 while( $line = <locales
> ) {
61 $line =~ s/[\r\n]*//g; # remove \r and \n
62 if ($line =~ m
|^!define
$AB_CD\_rtl
|) {
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") {
73 $nsisCP =~ s/^CP(.*)$/$1/g;
76 # Create the main NSIS language file with just the codepage, font, and
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";
85 &cpConvert
("nlf.in", "baseLocale.nlf", $langCP);
88 # Create the main NSIS language file
89 $inFile = "$appLocaleDir/override.properties";
91 die "Error $inFile does not exist!";
93 open(infile
, "<$inFile");
94 open(outfile
, ">$configDir/override.properties");
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";
112 &cpConvert
("override.properties", "overrideLocale.nsh", $langCP);
115 # Create the main Modern User Interface language file
116 $inFile = "$appLocaleDir/mui.properties";
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";
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";
142 print outfile
"!insertmacro MOZ_MUI_LANGUAGEFILE_END\r\n";
145 &cpConvert
("mui.properties", "baseLocale.nsh", $langCP);
148 # Create the custom language file for our custom strings
149 $inFile = "$appLocaleDir/custom.properties";
151 die "Error $inFile does not exist!";
153 open(infile
, "<$inFile");
154 open(outfile
, ">$configDir/custom.properties");
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";
173 &cpConvert
("custom.properties", "customLocale.nsh", $langCP);
176 # Converts a file's codepage
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>;