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. 16, 2012, 2:16 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
« background.js ('K') | « 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,70 @@
+#!/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):
+ return locale.lower().replace("_", "-")
Wladimir Palant 2012/10/18 12:30:40 Actually, the correct mapping is a bit more compli
Felix Dahlke 2012/10/18 13:09:11 Done.
+
+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")
Wladimir Palant 2012/10/18 12:30:40 LOL Let's hope this doesn't have any unintended si
Felix Dahlke 2012/10/18 13:09:11 Right now it doesn't :) Maybe r"\bChrome\b" to be
+
+ dest_path = os.path.join(destination, messages_file_name)
+ dest_file = open(dest_path, "w+")
+ dest_file.write(messages)
+ dest_file.close()
+
+def write_locale(target_dir, locale):
+ # We have to write the actual locale to a localised file because Opera doesn't
+ # show the country part in navigator.language (only "de", not "de-de").
Wladimir Palant 2012/10/18 12:30:40 That isn't really the case. navigator.lenguage ret
Felix Dahlke 2012/10/18 13:09:11 I'm definitely using en-GB and navigator.language
+ locale_file = open(os.path.join(target_dir, "locale.js"), "w+");
+ locale_file.write('window.locale = "%s";\n' % locale);
+ locale_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)
+ write_locale(dest_locale_path, dest_locale)
+
+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()
« background.js ('K') | « options/whitelist.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld