67
67
return join(d, path)
68
68
return join(l10ndirs[-1], path)
70
def preprocess_locale_files(moz_dir, ab_cd, config_dir, l10ndirs):
70
def preprocess_locale_files(config_dir, l10ndirs):
72
72
Preprocesses the installer localized properties files into the format
73
73
required by NSIS and creates a basic NSIS nlf file.
76
config_dir - the path to the destination directory
77
l10ndirs - list of paths to search for installer locale files
80
# Create the main NSIS language file
81
fp = open_utf16le_file(join(config_dir, "overrideLocale.nsh"))
82
locale_strings = get_locale_strings(lookup("override.properties",
87
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
90
# Create the Modern User Interface language file
91
fp = open_utf16le_file(join(config_dir, "baseLocale.nsh"))
92
fp.write((u""";NSIS Modern User Interface - Language File
93
;Compatible with Modern UI 1.68
94
;Language: baseLocale (0)
95
!insertmacro MOZ_MUI_LANGUAGEFILE_BEGIN \"baseLocale\"
96
!define MUI_LANGNAME \"baseLocale\"
97
""").encode("utf-16-le"))
98
locale_strings = get_locale_strings(lookup("mui.properties", l10ndirs),
99
"!define ", " ", True)
100
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
101
fp.write(u"!insertmacro MOZ_MUI_LANGUAGEFILE_END\n".encode("utf-16-le"))
104
# Create the custom language file for our custom strings
105
fp = open_utf16le_file(join(config_dir, "customLocale.nsh"))
106
locale_strings = get_locale_strings(lookup("custom.properties",
111
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
114
def create_nlf_file(moz_dir, ab_cd, config_dir):
116
Create a basic NSIS nlf file.
76
119
moz_dir - the path to top source directory for the toolkit source
77
120
ab_cd - the locale code
78
121
config_dir - the path to the destination directory
79
l10ndirs - list of paths to search for installer locale files
82
# Set the language ID to 0 to make this locale the default locale. An
83
# actual ID will need to be used to create a multi-language installer
84
# (e.g. for CD distributions, etc.).
88
125
# Check whether the locale is right to left from locales.nsi.
89
fp = open(join(moz_dir, "toolkit/mozapps/installer/windows/nsis/locales.nsi"), "r")
126
fp = open(join(moz_dir,
127
"toolkit/mozapps/installer/windows/nsis/locales.nsi"),
91
130
line = line.strip()
92
131
if line == "!define " + ab_cd + "_rtl":
112
151
# RTL - anything else than RTL means LTR
114
""" % (lang_id, rtl)).encode("utf-16-le"))
117
# Create the main NSIS language file
118
fp = open_utf16le_file(join(config_dir, "overrideLocale.nsh"))
119
locale_strings = get_locale_strings(lookup("override.properties", l10ndirs),
120
"LangString ^", " " + lang_id + " ", False)
121
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
124
# Create the Modern User Interface language file
125
fp = open_utf16le_file(join(config_dir, "baseLocale.nsh"))
126
fp.write((u""";NSIS Modern User Interface - Language File
127
;Compatible with Modern UI 1.68
128
;Language: baseLocale (%s)
129
!insertmacro MOZ_MUI_LANGUAGEFILE_BEGIN \"baseLocale\"
130
!define MUI_LANGNAME \"baseLocale\"
131
""" % (lang_id)).encode("utf-16-le"))
132
locale_strings = get_locale_strings(lookup("mui.properties", l10ndirs),
133
"!define ", " ", True)
134
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
135
fp.write(u"!insertmacro MOZ_MUI_LANGUAGEFILE_END\n".encode("utf-16-le"))
153
""" % rtl).encode("utf-16-le"))
156
def preprocess_locale_file(config_dir,
161
Preprocesses a single localized properties file into the format
162
required by NSIS and creates a basic NSIS nlf file.
165
config_dir - the path to the destination directory
166
l10ndirs - list of paths to search for installer locale files
167
properties_filename - the name of the properties file to search for
168
output_filename - the output filename to write
138
171
# Create the custom language file for our custom strings
139
fp = open_utf16le_file(join(config_dir, "customLocale.nsh"))
140
locale_strings = get_locale_strings(lookup("custom.properties", l10ndirs),
141
"LangString ", " " + lang_id + " ", True)
172
fp = open_utf16le_file(join(config_dir, output_filename))
173
locale_strings = get_locale_strings(lookup(properties_filename,
142
178
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
145
182
def convert_utf8_utf16le(in_file_path, out_file_path):
147
184
Converts a UTF-8 file to a new UTF-16LE file
160
197
usage = """usage: %prog command <args>
163
--convert-utf8-utf16le - preprocesses installer locale properties files and
164
creates a basic NSIS nlf file
165
--preprocess-locale - Preprocesses the installer localized properties files
166
into the format required by NSIS and creates a basic
200
--convert-utf8-utf16le - Preprocesses installer locale properties files
201
--preprocess-locale - Preprocesses the installer localized properties
202
files into the format required by NSIS and
203
creates a basic NSIS nlf file.
204
--preprocess-single-file - Preprocesses a single properties file into the
205
format required by NSIS
206
--create-nlf-file - Creates a basic NSIS nlf file
169
208
preprocess-locale.py --preprocess-locale <src> <locale> <code> <dest>
175
214
<dest> \tthe path to the destination directory
217
preprocess-locale.py --preprocess-single-file <src>
224
<src> \tthe path to top source directory for the toolkit source
225
<locale> \tthe path to the installer's locale files
226
<dest> \tthe path to the destination directory
227
<infile> \tthe properties file to process
228
<outfile>\tthe nsh file to write
231
preprocess-locale.py --create-nlf-file <src>
236
<src> \tthe path to top source directory for the toolkit source
237
<code> \tthe locale code
238
<dest> \tthe path to the destination directory
178
241
preprocess-locale.py --convert-utf8-utf16le <src> <dest>
181
244
<src> \tthe path to the UTF-8 source file to convert
182
245
<dest>\tthe path to the UTF-16LE destination file to create
248
preprocess_locale_args_help_string = """\
249
Arguments to --preprocess-locale should be:
250
<src> <locale> <code> <dest>
252
<src> <code> <dest> --l10n-dir <dir> [--l10n-dir <dir> ...]"""
254
preprocess_single_file_args_help_string = """\
255
Arguments to --preprocess-single_file should be:
256
<src> <locale> <code> <dest> <infile> <outfile>
258
<src> <locale> <code> <dest> <infile> <outfile>
259
--l10n-dir <dir> [--l10n-dir <dir>...]"""
261
create_nlf_args_help_string = """\
262
Arguments to --create-nlf-file should be:
263
<src> <code> <dest>"""
184
265
p = OptionParser(usage=usage)
185
266
p.add_option("--preprocess-locale", action="store_true", default=False,
186
267
dest='preprocess')
268
p.add_option("--preprocess-single-file", action="store_true", default=False,
269
dest='preprocessSingle')
270
p.add_option("--create-nlf-file", action="store_true", default=False,
187
272
p.add_option("--l10n-dir", action="append", default=[],
188
273
dest="l10n_dirs",
189
274
help="Add directory to lookup for locale files")
193
278
options, args = p.parse_args()
195
if ((not (options.preprocess or options.convert)) or
196
(options.preprocess and options.convert)):
197
p.error("You need to specify either --preprocess-locale or --convert-utf-utf16le")
281
if (options.preprocess):
283
if (options.convert):
285
p.error("More than one command specified")
288
if (options.preprocessSingle):
290
p.error("More than one command specified")
293
if (options.createNlf):
295
p.error("More than one command specified")
300
p.error("No command specified")
199
302
if options.preprocess:
200
303
if len(args) not in (3,4):
201
p.error("--preprocess-locale needs all of <src> <locale> <code> <dest>")
204
l10n_dirs = [args[1]]
207
if not options.l10n_dirs:
208
p.error("--preprocess-locale needs either <locale> or --l10ndir")
209
l10n_dirs = options.l10n_dirs
211
pargs.append(l10n_dirs)
212
preprocess_locale_files(*pargs)
304
p.error(preprocess_locale_args_help_string)
310
l10n_dirs = [pargs[1]]
313
if not options.l10n_dirs:
314
p.error(preprocess_locale_args_help_string)
315
l10n_dirs = options.l10n_dirs
317
config_dir = pargs[2]
319
# Create the output files
320
create_nlf_file(moz_dir, ab_cd, config_dir)
321
preprocess_locale_files(config_dir, l10n_dirs)
322
elif options.preprocessSingle:
323
if len(args) not in (4,5):
324
p.error(preprocess_single_file_args_help_string)
330
l10n_dirs = [pargs[1]]
333
if not options.l10n_dirs:
334
p.error(preprocess_single_file_args_help_string)
335
l10n_dirs = options.l10n_dirs
336
config_dir = pargs[1]
340
# Create the output files
341
preprocess_locale_file(config_dir,
345
elif options.createNlf:
347
p.error(create_nlf_args_help_string)
353
config_dir = pargs[2]
355
# Create the output files
356
create_nlf_file(moz_dir, ab_cd, config_dir)
357
elif options.convert:
214
358
if len(args) != 2:
215
359
p.error("--convert-utf8-utf16le needs both of <src> <dest>")
216
360
convert_utf8_utf16le(*args)