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

Side by Side Diff: localeSyncChrome.py

Issue 9257092: More build tools improvements (Closed)
Patch Set: Added some more changes required to build Firefox and Chrome extensions from the same repository (s… Created Jan. 25, 2013, 1:47 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
« no previous file with comments | « chainedconfigparser.py ('k') | localeTools.py » ('j') | 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 file is part of the Adblock Plus build tools,
5 # Copyright (C) 2006-2012 Eyeo GmbH
6 #
7 # Adblock Plus is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 3 as
9 # published by the Free Software Foundation.
10 #
11 # Adblock Plus is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
18
19 import sys, os, json, re, codecs
20 import buildtools.localeTools as localeTools
21
22 firefoxToChrome = {
23 'ar': 'ar',
24 'bg': 'bg',
25 'ca': 'ca',
26 'cs': 'cs',
27 'da': 'da',
28 'de': 'de',
29 'el': 'el',
30 'en-US': 'en_US',
31 'en-GB': 'en_GB',
32 'es-ES': 'es',
33 'es-AR': 'es_419',
34 'et': 'et',
35 'fi': 'fi',
36 # '': 'fil', ???
37 'fr': 'fr',
38 'he': 'he',
39 'hi-IN': 'hi',
40 'hr': 'hr',
41 'hu': 'hu',
42 'id': 'id',
43 'it': 'it',
44 'ja': 'ja',
45 'ko': 'ko',
46 'lt': 'lt',
47 'lv': 'lv',
48 'nl': 'nl',
49 # 'nb-NO': 'no', ???
50 'pl': 'pl',
51 'pt-BR': 'pt_BR',
52 'pt-PT': 'pt_PT',
53 'ro': 'ro',
54 'ru': 'ru',
55 'sk': 'sk',
56 'sl': 'sl',
57 'sr': 'sr',
58 'sv-SE': 'sv',
59 'th': 'th',
60 'tr': 'tr',
61 'uk': 'uk',
62 'vi': 'vi',
63 'zh-CN': 'zh_CN',
64 'zh-TW': 'zh_TW',
65 }
66
67 def syncLocales(sourceLocales, targetLocales, removed, imported):
68 for source, target in firefoxToChrome.iteritems():
69 targetFile = os.path.join(targetLocales, target, 'messages.json')
70 hasSource = os.path.exists(os.path.join(sourceLocales, source))
71 if hasSource and os.path.exists(os.path.join(sourceLocales, source, '.incomp lete')):
72 hasSource = False
73 if not hasSource and not os.path.exists(targetFile):
74 continue
75
76 data = {}
77 if os.path.exists(targetFile):
78 file = codecs.open(targetFile, 'rb', encoding='utf-8')
79 data = json.load(file)
80 file.close()
81
82 for entry in removed:
83 if entry in data:
84 del data[entry]
85
86 if hasSource:
87 for fileName, stringIDs in imported:
88 sourceFile = os.path.join(sourceLocales, source, fileName)
89 try:
90 sourceData = localeTools.readFile(sourceFile)
91 for stringID in stringIDs:
92 if stringID in sourceData:
93 key = re.sub(r'\..*', '', fileName) + '_' + re.sub(r'\W', '_', str ingID)
94 data[key] = {'message': sourceData[stringID]}
95 except:
96 pass
97
98 sourceFile = os.path.join(sourceLocales, source, 'meta.properties')
99 try:
100 sourceData = localeTools.readFile(sourceFile)
101 if 'name' in sourceData:
102 data['name'] = {'message': sourceData['name']}
103 except:
104 pass
105
106 try:
107 os.makedirs(os.path.dirname(targetFile))
108 except:
109 pass
110 file = codecs.open(targetFile, 'wb', encoding='utf-8')
111 json.dump(data, file, ensure_ascii=False, sort_keys=True, indent=2, separato rs=(',', ': '))
112 print >>file
113 file.close()
114
115 def run(baseDir, sourceDir):
116 import buildtools.packagerGecko as packagerGecko
117 import buildtools.packagerChrome as packagerChrome
118
119 sourceLocales = packagerGecko.getLocalesDir(sourceDir)
120 if not os.path.isdir(sourceLocales):
121 raise IOError('Directory %s not found' % sourceLocales)
122 targetLocales = os.path.join(baseDir, '_locales')
123
124 metadata = packagerChrome.readMetadata(baseDir)
125 removed = []
126 if metadata.has_option('locale_sync', 'remove'):
127 for key in re.split(r'\s+', metadata.get('locale_sync', 'remove')):
128 removed.append(key)
129
130 imported = []
131 for file, keys in metadata.items('locale_sync'):
132 if file == 'remove':
133 continue
134 imported.append((file, re.split(r'\s+', keys)))
135 syncLocales(sourceLocales, targetLocales, removed, imported)
OLDNEW
« no previous file with comments | « chainedconfigparser.py ('k') | localeTools.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld