| 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() |