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

Delta Between Two Patch Sets: update_locales.py

Issue 8560083: adblockplusopera: Port UI code from Chrome (Closed)
Left Patch Set: Created Oct. 12, 2012, 1:11 p.m.
Right Patch Set: Created Oct. 19, 2012, 4:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « options/whitelist.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 #!/usr/bin/env python
2 # coding: utf-8
3 #
4 # This Source Code is subject to the terms of the Mozilla Public License
5 # version 2.0 (the "License"). You can obtain a copy of the License at
6 # http://mozilla.org/MPL/2.0/.
7
8 """Copies the locales from ABP for Chrome and prepares them for Opera"""
9
10 import os, shutil, sys
11
12 def remove(path):
13 if os.path.exists(path):
14 if os.path.isdir(path):
15 shutil.rmtree(path)
16 else:
17 os.remove(path)
18
19 def map_locale(locale):
20 locale = locale.replace("_", "-")
21
22 mapping = {
23 "en-US": "en",
24 "es": "es-ES",
25 "es-419": "es-LA",
26 "pt-PT": "pt"
27 }
28
29 if locale in mapping:
30 return mapping[locale]
31
32 return locale
33
34 def copy_messages(source, destination):
35 messages_file_name = "messages.json"
36
37 source_path = os.path.join(source, messages_file_name)
38 source_file = open(source_path)
39 messages = source_file.read()
40 source_file.close()
41
42 messages = messages.replace("Chrome", "Opera")
43
44 dest_path = os.path.join(destination, messages_file_name)
45 dest_file = open(dest_path, "w+")
46 dest_file.write(messages)
47 dest_file.close()
48
49 def copy_locales(source, destination):
50 for source_locale in os.listdir(source):
51 source_locale_path = os.path.join(source, source_locale)
52 if not os.path.isdir(source_locale_path):
53 continue
54
55 dest_locale = map_locale(source_locale)
56 dest_locale_path = os.path.join(destination, dest_locale)
57
58 os.mkdir(dest_locale_path)
59 copy_messages(source_locale_path, dest_locale_path)
60
61 def update_locales():
62 locales_dir = "locales"
63 remove(locales_dir)
64 os.mkdir(locales_dir)
65
66 chrome_locales_dir = os.path.join("..", "adblockpluschrome", "_locales")
67 if not os.path.exists(chrome_locales_dir):
68 message = "Unable to find Chrome locales in %s" % chrome_locales_dir
69 print >>sys.stderr, message
70
71 copy_locales(chrome_locales_dir, locales_dir)
72
73 if __name__ == "__main__":
74 update_locales()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld