[Pkg-mozext-commits] [adblock-plus] 307/464: Moved locale sync from Firefox to Chrome to the buildtools repository (can be called via build.py now)

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:28 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 840448b48cb3ff2fc6ef2a97998151302795860d
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Thu Oct 18 12:38:21 2012 +0200

    Moved locale sync from Firefox to Chrome to the buildtools repository (can be called via build.py now)
---
 build.py            |  16 +++++++
 localeSyncChrome.py | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)

diff --git a/build.py b/build.py
index 2035a26..71c6d88 100644
--- a/build.py
+++ b/build.py
@@ -350,6 +350,16 @@ def runReleaseAutomation(baseDir, scriptName, opts, args, type):
     import buildtools.releaseAutomationKMeleon as releaseAutomation
     releaseAutomation.run(baseDir, downloadsRepo, buildtoolsRepo)
 
+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)
+
 with addCommand(lambda baseDir, scriptName, opts, args, type: usage(scriptName, type), ('help', '-h', '--help')) as command:
   command.shortDescription = 'Show this message'
 
@@ -416,6 +426,12 @@ with addCommand(runReleaseAutomation, 'release') as command:
   command.params = '[options] <version>'
   command.supportedTypes = ('gecko', 'kmeleon')
 
+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_extension_directory>'
+  command.supportedTypes = ('chrome')
+
 def processArgs(baseDir, args, type='gecko'):
   global commands
 
diff --git a/localeSyncChrome.py b/localeSyncChrome.py
new file mode 100644
index 0000000..1a626b0
--- /dev/null
+++ b/localeSyncChrome.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+# This Source Code is subject to the terms of the Mozilla Public License
+# version 2.0 (the "License"). You can obtain a copy of the License at
+# http://mozilla.org/MPL/2.0/.
+
+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',
+  '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'] + ' (Beta)'}
+      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)
+    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)

-- 
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