[Pkg-mozext-commits] [adblock-plus] 358/464: Chrome: import Firefox strings on build, not manually
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:33 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit a575d588210f05321c7d75347ff38775699f090a
Author: Wladimir Palant <trev at adblockplus.org>
Date: Fri Jan 25 10:33:19 2013 +0100
Chrome: import Firefox strings on build, not manually
---
build.py | 16 -------
localeSyncChrome.py | 135 ----------------------------------------------------
localeTools.py | 11 -----
packagerChrome.py | 87 +++++++++++++++++++++++++++++++++
4 files changed, 87 insertions(+), 162 deletions(-)
diff --git a/build.py b/build.py
index 971c121..e4ba797 100644
--- a/build.py
+++ b/build.py
@@ -405,16 +405,6 @@ def runReleaseAutomation(baseDir, scriptName, opts, args, type):
import buildtools.releaseAutomationGecko as releaseAutomation
releaseAutomation.run(baseDir, version, keyFile, downloadsRepo)
-def syncLocales(baseDir, scriptName, opts, args, type):
- if len(args) == 0:
- print 'Please specify the directory of the source Firefox extension as a parameter'
- usage(scriptName, type, 'synclocales')
- return
- sourceDir = args[0]
-
- import buildtools.localeSyncChrome as localeSync
- localeSync.run(baseDir, sourceDir)
-
def updatePSL(baseDir, scriptName, opts, args, type):
import buildtools.publicSuffixListUpdater as publicSuffixListUpdater
publicSuffixListUpdater.updatePSL(baseDir)
@@ -495,12 +485,6 @@ with addCommand(runReleaseAutomation, 'release') as command:
command.params = '[options] <version>'
command.supportedTypes = ('gecko')
-with addCommand(syncLocales, 'synclocales') as command:
- command.shortDescription = 'Sync locales with a Firefox extension'
- command.description = 'Updates locale files with strings from a Firefox extension corresponding to the entries in [locale_sync] metadata section.'
- command.params = '<firefox_addon_directory>'
- command.supportedTypes = ('chrome')
-
with addCommand(updatePSL, 'updatepsl') as command:
command.shortDescription = 'Updates Public Suffix List'
command.description = 'Downloads Public Suffix List (see http://publicsuffix.org/) and generates lib/publicSuffixList.js from it.'
diff --git a/localeSyncChrome.py b/localeSyncChrome.py
deleted file mode 100644
index f80f196..0000000
--- a/localeSyncChrome.py
+++ /dev/null
@@ -1,135 +0,0 @@
-#!/usr/bin/env python
-# coding: utf-8
-
-# This file is part of the Adblock Plus build tools,
-# Copyright (C) 2006-2012 Eyeo GmbH
-#
-# Adblock Plus is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 3 as
-# published by the Free Software Foundation.
-#
-# Adblock Plus is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
-
-import sys, os, json, re, codecs
-import buildtools.localeTools as localeTools
-
-firefoxToChrome = {
- 'ar': 'ar',
- 'bg': 'bg',
- 'ca': 'ca',
- 'cs': 'cs',
- 'da': 'da',
- 'de': 'de',
- 'el': 'el',
- 'en-US': 'en_US',
- 'en-GB': 'en_GB',
- 'es-ES': 'es',
- 'es-AR': 'es_419',
- 'et': 'et',
- 'fi': 'fi',
-# '': 'fil', ???
- 'fr': 'fr',
- 'he': 'he',
- 'hi-IN': 'hi',
- 'hr': 'hr',
- 'hu': 'hu',
- 'id': 'id',
- 'it': 'it',
- 'ja': 'ja',
- 'ko': 'ko',
- 'lt': 'lt',
- 'lv': 'lv',
- 'nl': 'nl',
-# 'nb-NO': 'no', ???
- 'pl': 'pl',
- 'pt-BR': 'pt_BR',
- 'pt-PT': 'pt_PT',
- 'ro': 'ro',
- 'ru': 'ru',
- 'sk': 'sk',
- 'sl': 'sl',
- 'sr': 'sr',
- 'sv-SE': 'sv',
- 'th': 'th',
- 'tr': 'tr',
- 'uk': 'uk',
- 'vi': 'vi',
- 'zh-CN': 'zh_CN',
- 'zh-TW': 'zh_TW',
-}
-
-def syncLocales(sourceLocales, targetLocales, removed, imported):
- for source, target in firefoxToChrome.iteritems():
- targetFile = os.path.join(targetLocales, target, 'messages.json')
- hasSource = os.path.exists(os.path.join(sourceLocales, source))
- if hasSource and os.path.exists(os.path.join(sourceLocales, source, '.incomplete')):
- hasSource = False
- if not hasSource and not os.path.exists(targetFile):
- continue
-
- data = {}
- if os.path.exists(targetFile):
- file = codecs.open(targetFile, 'rb', encoding='utf-8')
- data = json.load(file)
- file.close()
-
- for entry in removed:
- if entry in data:
- del data[entry]
-
- if hasSource:
- for fileName, stringIDs in imported:
- sourceFile = os.path.join(sourceLocales, source, fileName)
- try:
- sourceData = localeTools.readFile(sourceFile)
- for stringID in stringIDs:
- if stringID in sourceData:
- key = re.sub(r'\..*', '', fileName) + '_' + re.sub(r'\W', '_', stringID)
- data[key] = {'message': sourceData[stringID]}
- except:
- pass
-
- sourceFile = os.path.join(sourceLocales, source, 'meta.properties')
- try:
- sourceData = localeTools.readFile(sourceFile)
- if 'name' in sourceData:
- data['name'] = {'message': sourceData['name']}
- except:
- pass
-
- try:
- os.makedirs(os.path.dirname(targetFile))
- except:
- pass
- file = codecs.open(targetFile, 'wb', encoding='utf-8')
- json.dump(data, file, ensure_ascii=False, sort_keys=True, indent=2, separators=(',', ': '))
- print >>file
- file.close()
-
-def run(baseDir, sourceDir):
- import buildtools.packagerGecko as packagerGecko
- import buildtools.packagerChrome as packagerChrome
-
- sourceLocales = packagerGecko.getLocalesDir(sourceDir)
- if not os.path.isdir(sourceLocales):
- raise IOError('Directory %s not found' % sourceLocales)
- targetLocales = os.path.join(baseDir, '_locales')
-
- metadata = packagerChrome.readMetadata(baseDir)
- removed = []
- if metadata.has_option('locale_sync', 'remove'):
- for key in re.split(r'\s+', metadata.get('locale_sync', 'remove')):
- removed.append(key)
-
- imported = []
- for file, keys in metadata.items('locale_sync'):
- if file == 'remove':
- continue
- imported.append((file, re.split(r'\s+', keys)))
- syncLocales(sourceLocales, targetLocales, removed, imported)
diff --git a/localeTools.py b/localeTools.py
index a1582d6..606acc1 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -246,17 +246,6 @@ def preprocessChromeLocale(path, metadata, isMaster):
data = json.load(fileHandle)
fileHandle.close()
- # Remove synced keys, these don't need to be translated
- if metadata.has_section('locale_sync'):
- for file, stringIDs in metadata.items('locale_sync'):
- for stringID in re.split(r'\s+', stringIDs):
- if file == 'remove':
- key = stringID
- else:
- key = re.sub(r'\..*', '', file) + '_' + re.sub(r'\W', '_', stringID)
- if key in data:
- del data[key]
-
for key, value in data.iteritems():
if isMaster:
# Make sure the key name is listed in the description
diff --git a/packagerChrome.py b/packagerChrome.py
index 69ec5e8..2e13749 100644
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -131,6 +131,90 @@ def convertJS(params, files):
sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourceFiles)
files[file] = doRewrite(sourceFiles, args)
+def importGeckoLocales(params, files):
+ import localeTools
+
+ localeCodeMapping = {
+ 'ar': 'ar',
+ 'bg': 'bg',
+ 'ca': 'ca',
+ 'cs': 'cs',
+ 'da': 'da',
+ 'de': 'de',
+ 'el': 'el',
+ 'en-US': 'en_US',
+ 'en-GB': 'en_GB',
+ 'es-ES': 'es',
+ 'es-AR': 'es_419',
+ 'et': 'et',
+ 'fi': 'fi',
+ # '': 'fil', ???
+ 'fr': 'fr',
+ 'he': 'he',
+ 'hi-IN': 'hi',
+ 'hr': 'hr',
+ 'hu': 'hu',
+ 'id': 'id',
+ 'it': 'it',
+ 'ja': 'ja',
+ 'ko': 'ko',
+ 'lt': 'lt',
+ 'lv': 'lv',
+ 'nl': 'nl',
+ # 'nb-NO': 'no', ???
+ 'pl': 'pl',
+ 'pt-BR': 'pt_BR',
+ 'pt-PT': 'pt_PT',
+ 'ro': 'ro',
+ 'ru': 'ru',
+ 'sk': 'sk',
+ 'sl': 'sl',
+ 'sr': 'sr',
+ 'sv-SE': 'sv',
+ 'th': 'th',
+ 'tr': 'tr',
+ 'uk': 'uk',
+ 'vi': 'vi',
+ 'zh-CN': 'zh_CN',
+ 'zh-TW': 'zh_TW',
+ }
+
+ for source, target in localeCodeMapping.iteritems():
+ targetFile = '_locales/%s/messages.json' % target
+
+ for fileName, keys in params['metadata'].items('import_locales'):
+ parts = map(lambda n: source if n == '*' else n, fileName.split('/'))
+ sourceFile = os.path.join(params['baseDir'], *parts)
+ incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete')
+ if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker):
+ continue
+
+ data = {}
+ if targetFile in files:
+ data = json.loads(files[targetFile].decode('utf-8'))
+
+ try:
+ sourceData = localeTools.readFile(sourceFile)
+ for stringID in re.split(r'\s+', keys):
+ noMangling = False
+ if stringID.startswith('='):
+ stringID = stringID[1:]
+ noMangling = True
+
+ if stringID in sourceData:
+ if noMangling:
+ key = stringID
+ else:
+ key = re.sub(r'\..*', '', parts[-1]) + '_' + re.sub(r'\W', '_', stringID)
+ if key in data:
+ print 'Warning: locale string %s defined multiple times' % key
+ data[key] = {'message': sourceData[stringID]}
+ except Exception, e:
+ print 'Warning: error importing locale data from %s: %s' % (sourceFile, e)
+
+ files[targetFile] = json.dumps(data, ensure_ascii=False, sort_keys=True,
+ indent=2, separators=(',', ': ')).encode('utf-8') + '\n'
+
def signBinary(zipdata, keyFile):
import M2Crypto
if not os.path.exists(keyFile):
@@ -180,6 +264,9 @@ def createBuild(baseDir, outFile=None, buildNum=None, releaseBuild=False, keyFil
if metadata.has_section('convert_js'):
convertJS(params, files)
+ if metadata.has_section('import_locales'):
+ importGeckoLocales(params, files)
+
if devenv:
files['devenvPoller__.js'] = createPoller(params)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list