OLD | NEW |
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-2014 Eyeo GmbH | 4 # Copyright (C) 2006-2014 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 Loading... |
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 | |
276 def postprocessChromeLocale(path, data): | 271 def postprocessChromeLocale(path, data): |
277 parsed = json.loads(data) | 272 parsed = json.loads(data) |
278 if isinstance(parsed, list): | 273 if isinstance(parsed, list): |
279 return | 274 return |
280 | 275 |
281 # Delete description from translations | 276 # Delete description from translations |
282 for key, value in parsed.iteritems(): | 277 for key, value in parsed.iteritems(): |
283 if "description" in value: | 278 if "description" in value: |
284 del value["description"] | 279 del value["description"] |
285 | 280 |
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 | |
291 file = codecs.open(path, 'wb', encoding='utf-8') | 281 file = codecs.open(path, 'wb', encoding='utf-8') |
292 json.dump(parsed, file, ensure_ascii=False, sort_keys=True, indent=2, separato
rs=(',', ': ')) | 282 json.dump(parsed, file, ensure_ascii=False, sort_keys=True, indent=2, separato
rs=(',', ': ')) |
293 file.close() | 283 file.close() |
294 | 284 |
295 def setupTranslations(type, locales, projectName, key): | 285 def setupTranslations(type, locales, projectName, key): |
296 # Copy locales list, we don't want to change the parameter | 286 # Copy locales list, we don't want to change the parameter |
297 locales = set(locales) | 287 locales = set(locales) |
298 | 288 |
299 # Fill up with locales that we don't have but the browser supports | 289 # Fill up with locales that we don't have but the browser supports |
300 if type == 'chrome': | 290 if type == 'chrome': |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 450 |
461 # Remove any extra files | 451 # Remove any extra files |
462 for dir, files in dirs.iteritems(): | 452 for dir, files in dirs.iteritems(): |
463 baseDir = os.path.join(localesDir, dir) | 453 baseDir = os.path.join(localesDir, dir) |
464 if not os.path.exists(baseDir): | 454 if not os.path.exists(baseDir): |
465 continue | 455 continue |
466 for file in os.listdir(baseDir): | 456 for file in os.listdir(baseDir): |
467 path = os.path.join(baseDir, file) | 457 path = os.path.join(baseDir, file) |
468 if os.path.isfile(path) and (file.endswith('.json') or file.endswith('.pro
perties') or file.endswith('.dtd')) and not file in files: | 458 if os.path.isfile(path) and (file.endswith('.json') or file.endswith('.pro
perties') or file.endswith('.dtd')) and not file in files: |
469 os.remove(path) | 459 os.remove(path) |
OLD | NEW |