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

Side by Side Diff: update_locales.py

Issue 8560083: adblockplusopera: Port UI code from Chrome (Closed)
Patch Set: Created Oct. 16, 2012, 2:16 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« background.js ('K') | « options/whitelist.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 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.
21
22 def copy_messages(source, destination):
23 messages_file_name = "messages.json"
24
25 source_path = os.path.join(source, messages_file_name)
26 source_file = open(source_path)
27 messages = source_file.read()
28 source_file.close()
29
30 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
31
32 dest_path = os.path.join(destination, messages_file_name)
33 dest_file = open(dest_path, "w+")
34 dest_file.write(messages)
35 dest_file.close()
36
37 def write_locale(target_dir, locale):
38 # We have to write the actual locale to a localised file because Opera doesn't
39 # 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
40 locale_file = open(os.path.join(target_dir, "locale.js"), "w+");
41 locale_file.write('window.locale = "%s";\n' % locale);
42 locale_file.close();
43
44 def copy_locales(source, destination):
45 for source_locale in os.listdir(source):
46 source_locale_path = os.path.join(source, source_locale)
47 if not os.path.isdir(source_locale_path):
48 continue
49
50 dest_locale = map_locale(source_locale)
51 dest_locale_path = os.path.join(destination, dest_locale)
52
53 os.mkdir(dest_locale_path)
54 copy_messages(source_locale_path, dest_locale_path)
55 write_locale(dest_locale_path, dest_locale)
56
57 def update_locales():
58 locales_dir = "locales"
59 remove(locales_dir)
60 os.mkdir(locales_dir)
61
62 chrome_locales_dir = os.path.join("..", "adblockpluschrome", "_locales")
63 if not os.path.exists(chrome_locales_dir):
64 message = "Unable to find Chrome locales in %s" % chrome_locales_dir
65 print >>sys.stderr, message
66
67 copy_locales(chrome_locales_dir, locales_dir)
68
69 if __name__ == "__main__":
70 update_locales()
OLDNEW
« background.js ('K') | « options/whitelist.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld