diff --git a/platform/safari/Info.plist b/platform/safari/Info.plist index dab006b6f..c5291ca14 100644 --- a/platform/safari/Info.plist +++ b/platform/safari/Info.plist @@ -13,7 +13,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleShortVersionString - 0.7.2.0 + 0.8.1.2 CFBundleVersion 1 Chrome diff --git a/platform/safari/update_safariextz.plist b/platform/safari/update_safariextz.plist index f82911e17..c171e8689 100644 --- a/platform/safari/update_safariextz.plist +++ b/platform/safari/update_safariextz.plist @@ -10,7 +10,7 @@ Developer Identifier CFBundleShortVersionString - 0.7.0.11 + 0.8.1.2 CFBundleVersion 1 URL diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index f7f1a6405..505815b5c 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -77,9 +77,9 @@ vAPI.getURL = function(path) { // supported languages // first language is the default vAPI.i18nData = [ - "en", "ar", "cs", "da", "de", "el", "es", "et", "fi", "fr", "he", "hi", - "hr", "hu", "id", "it", "ja", "mr", "nb", "nl", "pl", "pt_BR", "pt_PT", - "ro", "ru", "sv", "tr", "uk", "vi", "zh_CN" + 'en', 'ar', 'cs', 'da', 'de', 'el', 'es', 'et', 'fi', 'fil', 'fr', 'he', + 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'mr', 'nb', 'nl', 'pl', 'pt_BR', + 'pt_PT', 'ro', 'ru', 'sv', 'tr', 'uk', 'vi', 'zh_CN' ]; vAPI.i18n = navigator.language.replace('-', '_'); @@ -96,14 +96,10 @@ setScriptDirection(vAPI.i18n); var xhr = new XMLHttpRequest; xhr.overrideMimeType('application/json;charset=utf-8'); -xhr.open('GET', './_locales/' + vAPI.i18n + '/messages.json', false); +xhr.open('GET', './_locales/' + vAPI.i18n + '.json', false); xhr.send(); vAPI.i18nData = JSON.parse(xhr.responseText); -for (var i18nKey in vAPI.i18nData) { - vAPI.i18nData[i18nKey] = vAPI.i18nData[i18nKey].message; -} - vAPI.i18n = function(s) { return this.i18nData[s] || s; }; diff --git a/tools/make-locale-safari.py b/tools/make-locale-safari.py new file mode 100644 index 000000000..62c819850 --- /dev/null +++ b/tools/make-locale-safari.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import os +import json +import sys +from shutil import rmtree +from collections import OrderedDict + +if not sys.argv[1]: + raise SystemExit('Build dir missing.') + + +def mkdirs(path): + try: + os.makedirs(path) + finally: + return os.path.exists(path) + + +build_dir = os.path.abspath(sys.argv[1]) +locale_dir = os.path.join(build_dir, '_locales') + +for alpha2 in os.listdir(locale_dir): + locale_path = os.path.join(locale_dir, alpha2, 'messages.json') + with open(locale_path, encoding='utf-8') as f: + string_data = json.load(f, object_pairs_hook=OrderedDict) + + for string_name in string_data: + string_data[string_name] = string_data[string_name]['message'] + + rmtree(os.path.join(locale_dir, alpha2)) + + alpha2 = alpha2.replace('_', '-') + locale_path = os.path.join(locale_dir, alpha2 + '.json') + + mkdirs(os.path.join(locale_dir)) + + with open(locale_path, 'wt', encoding='utf-8', newline='\n') as f: + json.dump(string_data, f, ensure_ascii=False) diff --git a/tools/make-safari.sh b/tools/make-safari.sh index 89f89942a..1b9840af8 100644 --- a/tools/make-safari.sh +++ b/tools/make-safari.sh @@ -18,4 +18,8 @@ cp src/img/icon_128.png $DES/Icon.png cp platform/safari/*.js $DES/js/ cp platform/safari/Info.plist $DES/ cp platform/safari/Settings.plist $DES/ + +echo "*** uBlock_xpi: Generating locales" +python tools/make-locale-safari.py $DES/ + echo "*** uBlock.safariextension: Package done."