Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: packagerChrome.py

Issue 5709087064981504: Issue 1321 - Truncate extension name and description at build time instead of only truncating descr… (Closed)
Patch Set: Created Sept. 3, 2014, 6:42 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « localeTools.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packagerChrome.py
===================================================================
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -283,32 +283,48 @@ def importGeckoLocales(params, files):
for chromeLocale, operaLocale in operaMapping.iteritems():
chromeFile = '_locales/%s/messages.json' % chromeLocale
operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != None else None
if chromeFile in files:
if operaFile != None:
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"
Sebastian Noack 2014/09/03 18:53:37 I think we should at least generate a warning when
Wladimir Palant 2014/09/03 19:05:22 I considered doing that. However, the main effect
Sebastian Noack 2014/09/03 19:13:03 Perfect. Even better would be to have proper monit
Wladimir Palant 2014/09/03 21:21:31 Not at all. It should spam you because you are the
Sebastian Noack 2014/09/04 10:40:02 So I feel this is the wrong place to address that
Wladimir Palant 2014/09/04 13:27:03 That's what you did originally. But that means tha
Sebastian Noack 2014/09/04 13:29:55 I agree, but that isn't what I meant to suggest. g
Wladimir Palant 2014/09/04 13:47:43 Take care how exactly? Do you speak Telugu? I don'
Sebastian Noack 2014/09/04 14:00:58 In the worst case one can still decide to truncate
+
+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
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):
import M2Crypto
if not os.path.exists(keyFile):
M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None)
key = M2Crypto.EVP.load_key(keyFile)
key.sign_init()
@@ -366,17 +382,18 @@ def createBuild(baseDir, type='chrome',
[f for f, _ in metadata.items('preprocess')],
{'needsExt': True}
)
if metadata.has_section('import_locales'):
importGeckoLocales(params, files)
files['manifest.json'] = createManifest(params, files)
- fixMissingTranslations(files)
+ if type == 'chrome':
+ fixTranslationsForCWS(files)
if devenv:
import buildtools
import random
files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js'), relpath='devenvPoller__.js')
files['devenvVersion__'] = str(random.random())
if (metadata.has_option('general', 'backgroundScripts') and
« no previous file with comments | « localeTools.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld