12
12
# --convert-utf8-utf16le.
14
14
from codecs import BOM_UTF16_LE
15
from os.path import join
15
from os.path import join, isfile
18
def preprocess_locale(argv):
20
Validates command line arguments and displays usage if necessary
22
if len(argv) < 1 or (argv[0] != '--convert-utf8-utf16le' and argv[0] != '--preprocess-locale'):
27
--convert-utf8-utf16le - preprocesses installer locale properties files and
28
creates a basic NSIS nlf file
29
--preprocess-locale - converts a UTF-8 file to a new UTF-16LE file
31
use "preprocess-locale.py <command>" to see the usage for each command
35
if argv[0] == '--convert-utf8-utf16le':
38
Converts a UTF-8 file to UTF-16LE
40
Usage: preprocess-locale.py --convert-utf8-utf16le <src> <dest>
43
<src> \tthe path to the UTF-8 source file to convert
44
<dest>\tthe path to the UTF-16LE destination file to create
47
convert_utf8_utf16le(argv[1], argv[2])
49
if argv[0] == '--preprocess-locale':
52
Preprocesses the installer localized properties files into the format
53
required by NSIS and creates a basic NSIS nlf file.
55
Usage: preprocess-locale.py --preprocess-locale <src> <locale> <code> <dest>
58
<src> \tthe path to top source directory for the toolkit source
59
<locale>\tthe path to the installer's locale files
60
<code> \tthe locale code
61
<dest> \tthe path to the destination directory
64
preprocess_locale_files(argv[1], argv[2], argv[3], argv[4])
17
from optparse import OptionParser
66
19
def open_utf16le_file(path):
111
def preprocess_locale_files(moz_dir, locale_dir, ab_cd, config_dir):
64
def lookup(path, l10ndirs):
66
if isfile(join(d, path)):
68
return join(l10ndirs[-1], path)
70
def preprocess_locale_files(moz_dir, ab_cd, config_dir, l10ndirs):
113
72
Preprocesses the installer localized properties files into the format
114
73
required by NSIS and creates a basic NSIS nlf file.
117
76
moz_dir - the path to top source directory for the toolkit source
118
locale_dir - the path to the installer's locale files
119
77
ab_cd - the locale code
120
78
config_dir - the path to the destination directory
79
l10ndirs - list of paths to search for installer locale files
123
82
# Set the language ID to 0 to make this locale the default locale. An
158
117
# Create the main NSIS language file
159
118
fp = open_utf16le_file(join(config_dir, "overrideLocale.nsh"))
160
locale_strings = get_locale_strings(join(locale_dir, "override.properties"),
119
locale_strings = get_locale_strings(lookup("override.properties", l10ndirs),
161
120
"LangString ^", " " + lang_id + " ", False)
162
121
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
170
129
!insertmacro MOZ_MUI_LANGUAGEFILE_BEGIN \"baseLocale\"
171
130
!define MUI_LANGNAME \"baseLocale\"
172
131
""" % (lang_id)).encode("utf-16-le"))
173
locale_strings = get_locale_strings(join(locale_dir, "mui.properties"),
132
locale_strings = get_locale_strings(lookup("mui.properties", l10ndirs),
174
133
"!define ", " ", True)
175
134
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
176
135
fp.write(u"!insertmacro MOZ_MUI_LANGUAGEFILE_END\n".encode("utf-16-le"))
179
138
# Create the custom language file for our custom strings
180
139
fp = open_utf16le_file(join(config_dir, "customLocale.nsh"))
181
locale_strings = get_locale_strings(join(locale_dir, "custom.properties"),
140
locale_strings = get_locale_strings(lookup("custom.properties", l10ndirs),
182
141
"LangString ", " " + lang_id + " ", True)
183
142
fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
200
159
if __name__ == '__main__':
201
sys.exit(preprocess_locale(sys.argv[1:]))
160
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
169
preprocess-locale.py --preprocess-locale <src> <locale> <code> <dest>
172
<src> \tthe path to top source directory for the toolkit source
173
<locale>\tthe path to the installer's locale files
174
<code> \tthe locale code
175
<dest> \tthe path to the destination directory
178
preprocess-locale.py --convert-utf8-utf16le <src> <dest>
181
<src> \tthe path to the UTF-8 source file to convert
182
<dest>\tthe path to the UTF-16LE destination file to create
184
p = OptionParser(usage=usage)
185
p.add_option("--preprocess-locale", action="store_true", default=False,
187
p.add_option("--l10n-dir", action="append", default=[],
189
help="Add directory to lookup for locale files")
190
p.add_option("--convert-utf8-utf16le", action="store_true", default=False,
193
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")
199
if options.preprocess:
200
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)
215
p.error("--convert-utf8-utf16le needs both of <src> <dest>")
216
convert_utf8_utf16le(*args)