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

Side by Side Diff: localeTools.py

Issue 5163766501081088: Crop Chrome descriptions (Closed)
Patch Set: Created Dec. 17, 2013, 11:52 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus build tools, 3 # This file is part of the Adblock Plus build tools,
4 # Copyright (C) 2006-2013 Eyeo GmbH 4 # Copyright (C) 2006-2013 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 value["description"] = "%s: %s" % (key, value["description"]) 261 value["description"] = "%s: %s" % (key, value["description"])
262 else: 262 else:
263 value["description"] = key 263 value["description"] = key
264 else: 264 else:
265 # Delete description from translations 265 # Delete description from translations
266 if "description" in value: 266 if "description" in value:
267 del value["description"] 267 del value["description"]
268 268
269 return json.dumps(data, ensure_ascii=False, sort_keys=True, indent=2) 269 return json.dumps(data, ensure_ascii=False, sort_keys=True, indent=2)
270 270
271 def truncate(text, length_limit):
272 if len(text) <= length_limit:
273 return text
274 return text[:length_limit - 1].rstrip() + u"\u2026"
275
271 def postprocessChromeLocale(path, data): 276 def postprocessChromeLocale(path, data):
272 parsed = json.loads(data) 277 parsed = json.loads(data)
273 if isinstance(parsed, list): 278 if isinstance(parsed, list):
274 return 279 return
275 280
276 # Delete description from translations 281 # Delete description from translations
277 for key, value in parsed.iteritems(): 282 for key, value in parsed.iteritems():
278 if "description" in value: 283 if "description" in value:
279 del value["description"] 284 del value["description"]
280 285
286 # Crop Chrome description, we need to enforce the length limit
287 if "description_chrome" in parsed:
288 description_chrome = parsed["description_chrome"]
289 description_chrome["message"] = truncate(description_chrome["message"], 132)
290
281 file = codecs.open(path, 'wb', encoding='utf-8') 291 file = codecs.open(path, 'wb', encoding='utf-8')
282 json.dump(parsed, file, ensure_ascii=False, sort_keys=True, indent=2, separato rs=(',', ': ')) 292 json.dump(parsed, file, ensure_ascii=False, sort_keys=True, indent=2, separato rs=(',', ': '))
283 file.close() 293 file.close()
284 294
285 def setupTranslations(type, locales, projectName, key): 295 def setupTranslations(type, locales, projectName, key):
286 # Copy locales list, we don't want to change the parameter 296 # Copy locales list, we don't want to change the parameter
287 locales = set(locales) 297 locales = set(locales)
288 298
289 # Fill up with locales that we don't have but the browser supports 299 # Fill up with locales that we don't have but the browser supports
290 if type == 'chrome': 300 if type == 'chrome':
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 460
451 # Remove any extra files 461 # Remove any extra files
452 for dir, files in dirs.iteritems(): 462 for dir, files in dirs.iteritems():
453 baseDir = os.path.join(localesDir, dir) 463 baseDir = os.path.join(localesDir, dir)
454 if not os.path.exists(baseDir): 464 if not os.path.exists(baseDir):
455 continue 465 continue
456 for file in os.listdir(baseDir): 466 for file in os.listdir(baseDir):
457 path = os.path.join(baseDir, file) 467 path = os.path.join(baseDir, file)
458 if os.path.isfile(path) and (file.endswith('.json') or file.endswith('.pro perties') or file.endswith('.dtd')) and not file in files: 468 if os.path.isfile(path) and (file.endswith('.json') or file.endswith('.pro perties') or file.endswith('.dtd')) and not file in files:
459 os.remove(path) 469 os.remove(path)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld