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

Delta Between Two Patch Sets: import_locales.py

Issue 5748296123416576: Issue 1166 - Import strings from ABP for Firefox (Closed)
Left Patch Set: Comments addressed Created Aug. 6, 2014, 10:31 a.m.
Right Patch Set: Use localeTools.langMappingGecko, don't hard code IE locales Created Aug. 6, 2014, 12:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « .hgsubstate ('k') | locales/ar.ini » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import codecs 3 import codecs
4 from ConfigParser import SafeConfigParser 4 from ConfigParser import SafeConfigParser
5 import os 5 import os
6 import re 6 import re
7 7
8 from buildtools import localeTools 8 from buildtools import localeTools
9 9
10 ie_locales = [ 10 ie_locale_base_path = "locales"
11 "ar", 11 gecko_locale_base_path = "libadblockplus/adblockplus/chrome/locale"
12 "bg",
13 "ca",
14 "cs",
15 "da",
16 "de",
17 "el",
18 "en",
19 "es-ES",
20 "et",
21 "fi",
22 "fil",
23 "fr",
24 "he",
25 "hi",
26 "hr",
27 "hu",
28 "it",
29 "ja",
30 "kn",
31 "mr",
32 "ms",
33 "nb",
34 "nl",
35 "nn-NO",
36 "pl",
37 "pt-BR",
38 "pt-PT",
39 "ro",
40 "ru",
41 "sk",
42 "sv-SE",
43 "th",
44 "tr",
45 "uk",
46 "ur-PK",
47 "zh-CN",
48 "zh-TW"
49 ]
50 12
51 gecko_locale_mapping = { 13 gecko_locale_mapping = dict(zip(localeTools.langMappingGecko.values(),
52 "en": "en-US", 14 localeTools.langMappingGecko.keys()))
53 "hi": "hi-IN",
54 "nb": "nb-NO"
55 }
56 15
57 gecko_locale_base_path = "libadblockplus/adblockplus/chrome/locale" 16 # We should be using en-US instead of en in IE, see
17 # https://issues.adblockplus.org/ticket/1177
18 gecko_locale_mapping["en"] = "en-US"
58 19
59 strings_to_import = { 20 strings_to_import = {
60 "firstRun.properties/firstRun_acceptableAdsHeadline": "first-run/first-run-aa- title", 21 "firstRun.properties/firstRun_acceptableAdsHeadline": "first-run/first-run-aa- title",
61 "firstRun.properties/firstRun_acceptableAdsExplanation": "first-run/first-run- aa-text", 22 "firstRun.properties/firstRun_acceptableAdsExplanation": "first-run/first-run- aa-text",
62 "filters.dtd/acceptableAds2.label": "settings/settings-acceptable-ads" 23 "filters.dtd/acceptableAds2.label": "settings/settings-acceptable-ads"
63 } 24 }
64 25
65 def read_gecko_locale_strings(locale): 26 def read_gecko_locale_strings(locale):
66 locale_strings = {} 27 locale_strings = {}
67 locale_files = set([key.split("/")[0] for key in strings_to_import.keys()]) 28 locale_files = set([key.split("/")[0] for key in strings_to_import.keys()])
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 target_section, target_key = target.split("/") 60 target_section, target_key = target.split("/")
100 if source_key in gecko_locale_strings[source_section]: 61 if source_key in gecko_locale_strings[source_section]:
101 value = gecko_locale_strings[source_section][source_key] 62 value = gecko_locale_strings[source_section][source_key]
102 value = re.sub(r"\s*\(&.\)$", "", value).replace("&", "") 63 value = re.sub(r"\s*\(&.\)$", "", value).replace("&", "")
103 config.set(target_section, target_key, value) 64 config.set(target_section, target_key, value)
104 65
105 with codecs.open(ie_locale_path, "w", "utf-8") as ie_locale_file: 66 with codecs.open(ie_locale_path, "w", "utf-8") as ie_locale_file:
106 write_ini(config, ie_locale_file) 67 write_ini(config, ie_locale_file)
107 68
108 def import_locales(): 69 def import_locales():
70 ie_locales = [os.path.splitext(file)[0]
71 for file in os.listdir(ie_locale_base_path)
72 if os.path.isfile(os.path.join(ie_locale_base_path, file))]
109 for ie_locale in ie_locales: 73 for ie_locale in ie_locales:
110 import_locale(ie_locale) 74 import_locale(ie_locale)
111 75
112 if __name__ == "__main__": 76 if __name__ == "__main__":
113 import_locales() 77 import_locales()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld