[Pkg-mozext-commits] [adblock-plus] 03/24: Issue 1321 - Truncate extension name and description at build time instead of only truncating descriptions when importing locales

David Prévot taffit at moszumanska.debian.org
Mon Oct 20 02:15:22 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 f3f8692f82e5712294b81cbc8dd6299fe7b3b00c
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Wed Sep 3 20:42:34 2014 +0200

    Issue 1321 - Truncate extension name and description at build time instead of only truncating descriptions when importing locales
---
 localeTools.py    | 10 ----------
 packagerChrome.py | 25 +++++++++++++++++++++----
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/localeTools.py b/localeTools.py
index f0dd721..895590a 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -268,11 +268,6 @@ def preprocessChromeLocale(path, metadata, isMaster):
 
   return json.dumps(data, ensure_ascii=False, sort_keys=True, indent=2)
 
-def truncate(text, length_limit):
-  if len(text) <= length_limit:
-    return text
-  return text[:length_limit - 1].rstrip() + u"\u2026"
-
 def postprocessChromeLocale(path, data):
   parsed = json.loads(data)
   if isinstance(parsed, list):
@@ -283,11 +278,6 @@ def postprocessChromeLocale(path, data):
     if "description" in value:
       del value["description"]
 
-  # Crop Chrome description, we need to enforce the length limit
-  if "description_chrome" in parsed:
-    description_chrome = parsed["description_chrome"]
-    description_chrome["message"] = truncate(description_chrome["message"], 132)
-
   file = codecs.open(path, 'wb', encoding='utf-8')
   json.dump(parsed, file, ensure_ascii=False, sort_keys=True, indent=2, separators=(',', ': '))
   file.close()
diff --git a/packagerChrome.py b/packagerChrome.py
index 30c3855..b9130b5 100644
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -288,14 +288,28 @@ def importGeckoLocales(params, files):
           files[operaFile] = files[chromeFile]
         del files[chromeFile]
 
-def fixMissingTranslations(files):
-  # Chrome requires messages used in manifest.json to be given in all languages
+def truncate(text, length_limit):
+  if len(text) <= length_limit:
+    return text
+  return text[:length_limit - 1].rstrip() + u"\u2026"
+
+def fixTranslationsForCWS(files):
+  # Chrome Web Store requires messages used in manifest.json to be present in
+  # all languages. It also enforces length limits for extension names and
+  # descriptions.
   defaults = {}
   data = json.loads(files['_locales/%s/messages.json' % defaultLocale])
   for match in re.finditer(r'__MSG_(\S+)__', files['manifest.json']):
     name = match.group(1)
     defaults[name] = data[name]
 
+  limits = {}
+  manifest = json.loads(files['manifest.json'])
+  for key, limit in (('name', 45), ('description', 132), ('short_name', 12)):
+    match = re.search(r'__MSG_(\S+)__', manifest.get(key, ""))
+    if match:
+      limits[match.group(1)] = limit
+
   for filename in files:
     if not filename.startswith('_locales/') or not filename.endswith('/messages.json'):
       continue
@@ -303,7 +317,9 @@ def fixMissingTranslations(files):
     data = json.loads(files[filename])
     for name, info in defaults.iteritems():
       data.setdefault(name, info)
-
+    for name, limit in limits.iteritems():
+      if name in data:
+        data[name]['message'] = truncate(data[name]['message'], limit)
     files[filename] = toJson(data)
 
 def signBinary(zipdata, keyFile):
@@ -371,7 +387,8 @@ def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuil
     importGeckoLocales(params, files)
 
   files['manifest.json'] = createManifest(params, files)
-  fixMissingTranslations(files)
+  if type == 'chrome':
+    fixTranslationsForCWS(files)
 
   if devenv:
     import buildtools

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