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

Unified Diff: update_locales.py

Issue 8560083: adblockplusopera: Port UI code from Chrome (Closed)
Patch Set: Created Oct. 19, 2012, 4:04 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 | « options/whitelist.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: update_locales.py
===================================================================
new file mode 100755
--- /dev/null
+++ b/update_locales.py
@@ -0,0 +1,74 @@
+#!/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/.
+
+"""Copies the locales from ABP for Chrome and prepares them for Opera"""
+
+import os, shutil, sys
+
+def remove(path):
+ if os.path.exists(path):
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+ else:
+ os.remove(path)
+
+def map_locale(locale):
+ locale = locale.replace("_", "-")
+
+ mapping = {
+ "en-US": "en",
+ "es": "es-ES",
+ "es-419": "es-LA",
+ "pt-PT": "pt"
+ }
+
+ if locale in mapping:
+ return mapping[locale]
+
+ return locale
+
+def copy_messages(source, destination):
+ messages_file_name = "messages.json"
+
+ source_path = os.path.join(source, messages_file_name)
+ source_file = open(source_path)
+ messages = source_file.read()
+ source_file.close()
+
+ messages = messages.replace("Chrome", "Opera")
+
+ dest_path = os.path.join(destination, messages_file_name)
+ dest_file = open(dest_path, "w+")
+ dest_file.write(messages)
+ dest_file.close()
+
+def copy_locales(source, destination):
+ for source_locale in os.listdir(source):
+ source_locale_path = os.path.join(source, source_locale)
+ if not os.path.isdir(source_locale_path):
+ continue
+
+ dest_locale = map_locale(source_locale)
+ dest_locale_path = os.path.join(destination, dest_locale)
+
+ os.mkdir(dest_locale_path)
+ copy_messages(source_locale_path, dest_locale_path)
+
+def update_locales():
+ locales_dir = "locales"
+ remove(locales_dir)
+ os.mkdir(locales_dir)
+
+ chrome_locales_dir = os.path.join("..", "adblockpluschrome", "_locales")
+ if not os.path.exists(chrome_locales_dir):
+ message = "Unable to find Chrome locales in %s" % chrome_locales_dir
+ print >>sys.stderr, message
+
+ copy_locales(chrome_locales_dir, locales_dir)
+
+if __name__ == "__main__":
+ update_locales()
« no previous file with comments | « options/whitelist.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld