2014-12-20 12:20:23 -07:00
|
|
|
#!/usr/bin/env python3
|
2014-12-16 09:02:26 -07:00
|
|
|
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import sys
|
2014-12-19 13:31:11 -07:00
|
|
|
from io import open
|
2014-12-16 09:02:26 -07:00
|
|
|
from shutil import rmtree
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
2014-12-19 13:31:11 -07:00
|
|
|
if len(sys.argv) == 1 or not sys.argv[1]:
|
|
|
|
raise SystemExit('Build dir missing.')
|
2014-12-16 09:02:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
def mkdirs(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
finally:
|
|
|
|
return os.path.exists(path)
|
|
|
|
|
|
|
|
pj = os.path.join
|
|
|
|
|
|
|
|
build_dir = os.path.abspath(sys.argv[1])
|
|
|
|
source_locale_dir = pj(build_dir, '_locales')
|
|
|
|
target_locale_dir = pj(build_dir, 'locale')
|
|
|
|
language_codes = []
|
2015-01-27 04:44:35 -07:00
|
|
|
descriptions = OrderedDict({})
|
2015-05-14 17:04:15 -06:00
|
|
|
title_case_strings = ['pickerContextMenuEntry']
|
2014-12-16 09:02:26 -07:00
|
|
|
|
2015-01-11 10:41:52 -07:00
|
|
|
for alpha2 in sorted(os.listdir(source_locale_dir)):
|
2014-12-16 09:02:26 -07:00
|
|
|
locale_path = pj(source_locale_dir, alpha2, 'messages.json')
|
|
|
|
with open(locale_path, encoding='utf-8') as f:
|
2015-02-04 23:51:03 -07:00
|
|
|
strings = json.load(f, object_pairs_hook=OrderedDict)
|
2014-12-16 09:02:26 -07:00
|
|
|
|
|
|
|
alpha2 = alpha2.replace('_', '-')
|
2015-02-04 23:51:03 -07:00
|
|
|
descriptions[alpha2] = strings['extShortDesc']['message']
|
|
|
|
del strings['extShortDesc']
|
2014-12-16 09:02:26 -07:00
|
|
|
|
|
|
|
language_codes.append(alpha2)
|
|
|
|
|
|
|
|
mkdirs(pj(target_locale_dir, alpha2))
|
|
|
|
|
|
|
|
locale_path = pj(target_locale_dir, alpha2, 'messages.properties')
|
|
|
|
with open(locale_path, 'wt', encoding='utf-8', newline='\n') as f:
|
2015-02-04 23:51:03 -07:00
|
|
|
for string_name in strings:
|
|
|
|
string = strings[string_name]['message']
|
|
|
|
|
|
|
|
if alpha2 == 'en' and string_name in title_case_strings:
|
|
|
|
string = string.title()
|
|
|
|
|
2014-12-16 09:02:26 -07:00
|
|
|
f.write(string_name)
|
2014-12-20 01:27:53 -07:00
|
|
|
f.write(u'=')
|
2015-02-04 23:51:03 -07:00
|
|
|
f.write(string.replace('\n', r'\n'))
|
2014-12-20 01:27:53 -07:00
|
|
|
f.write(u'\n')
|
2014-12-16 09:02:26 -07:00
|
|
|
|
|
|
|
# generate chrome.manifest file
|
|
|
|
chrome_manifest = pj(build_dir, 'chrome.manifest')
|
|
|
|
|
|
|
|
with open(chrome_manifest, 'at', encoding='utf-8', newline='\n') as f:
|
2014-12-20 01:27:53 -07:00
|
|
|
f.write(u'\nlocale ublock en ./locale/en/\n')
|
2014-12-16 09:02:26 -07:00
|
|
|
|
|
|
|
for alpha2 in language_codes:
|
2015-01-27 04:44:35 -07:00
|
|
|
if alpha2 == 'en':
|
|
|
|
continue
|
|
|
|
|
|
|
|
f.write(u'locale ublock ' + alpha2 + ' ./locale/' + alpha2 + '/\n')
|
2014-12-16 09:02:26 -07:00
|
|
|
|
|
|
|
rmtree(source_locale_dir)
|
|
|
|
|
|
|
|
# update install.rdf
|
|
|
|
proj_dir = pj(os.path.split(os.path.abspath(__file__))[0], '..')
|
|
|
|
chromium_manifest = pj(proj_dir, 'platform', 'chromium', 'manifest.json')
|
|
|
|
|
|
|
|
with open(chromium_manifest, encoding='utf-8') as m:
|
|
|
|
manifest = json.load(m)
|
|
|
|
|
2015-04-08 16:17:06 -06:00
|
|
|
manifest['homepage'] = 'https://github.com/chrisaljoudi/uBlock'
|
2015-01-27 04:44:35 -07:00
|
|
|
manifest['description'] = descriptions['en']
|
|
|
|
del descriptions['en']
|
|
|
|
manifest['localized'] = []
|
2014-12-16 09:02:26 -07:00
|
|
|
|
2015-01-27 04:44:35 -07:00
|
|
|
t = ' '
|
|
|
|
t3 = 3 * t
|
2014-12-16 09:02:26 -07:00
|
|
|
|
2015-01-27 04:44:35 -07:00
|
|
|
for alpha2 in descriptions:
|
|
|
|
if alpha2 == 'en':
|
|
|
|
continue
|
|
|
|
|
|
|
|
manifest['localized'].append(
|
|
|
|
'\n' + t*2 + '<localized><r:Description>\n' +
|
|
|
|
t3 + '<locale>' + alpha2 + '</locale>\n' +
|
|
|
|
t3 + '<name>' + manifest['name'] + '</name>\n' +
|
|
|
|
t3 + '<description>' + descriptions[alpha2] + '</description>\n' +
|
|
|
|
t3 + '<creator>' + manifest['author'] + '</creator>\n' +
|
|
|
|
# t3 + '<translator>' + ??? + '</translator>\n' +
|
|
|
|
t3 + '<homepageURL>' + manifest['homepage'] + '</homepageURL>\n' +
|
|
|
|
t*2 + '</r:Description></localized>'
|
|
|
|
)
|
|
|
|
|
|
|
|
manifest['localized'] = '\n'.join(manifest['localized'])
|
|
|
|
|
|
|
|
install_rdf = pj(build_dir, 'install.rdf')
|
2014-12-16 09:02:26 -07:00
|
|
|
with open(install_rdf, 'r+t', encoding='utf-8', newline='\n') as f:
|
|
|
|
install_rdf = f.read()
|
|
|
|
f.seek(0)
|
|
|
|
|
|
|
|
f.write(install_rdf.format(**manifest))
|