|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 import sys |
|
6 import re |
|
7 import codecs |
|
8 try: |
|
9 from Mozilla.Parser import getParser |
|
10 except ImportError: |
|
11 sys.exit('''extract-bookmarks needs compare-locales |
|
12 |
|
13 Find that on http://pypi.python.org/pypi/compare-locales. |
|
14 This script has been tested with version 0.6, and might work with future |
|
15 versions.''') |
|
16 |
|
17 ll=re.compile('\.(title|a|dd|h[0-9])$') |
|
18 |
|
19 p = getParser(sys.argv[1]) |
|
20 p.readFile(sys.argv[1]) |
|
21 |
|
22 template = '''#filter emptyLines |
|
23 |
|
24 # LOCALIZATION NOTE: The 'en-US' strings in the URLs will be replaced with |
|
25 # your locale code, and link to your translated pages as soon as they're |
|
26 # live. |
|
27 |
|
28 #define bookmarks_title %s |
|
29 #define bookmarks_heading %s |
|
30 |
|
31 #define bookmarks_toolbarfolder %s |
|
32 #define bookmarks_toolbarfolder_description %s |
|
33 |
|
34 # LOCALIZATION NOTE (getting_started): |
|
35 # link title for https://www.mozilla.org/en-US/firefox/central/ |
|
36 #define getting_started %s |
|
37 |
|
38 # LOCALIZATION NOTE (firefox_heading): |
|
39 # Firefox links folder name |
|
40 #define firefox_heading %s |
|
41 |
|
42 # LOCALIZATION NOTE (firefox_help): |
|
43 # link title for https://www.mozilla.org/en-US/firefox/help/ |
|
44 #define firefox_help %s |
|
45 |
|
46 # LOCALIZATION NOTE (firefox_customize): |
|
47 # link title for https://www.mozilla.org/en-US/firefox/customize/ |
|
48 #define firefox_customize %s |
|
49 |
|
50 # LOCALIZATION NOTE (firefox_community): |
|
51 # link title for https://www.mozilla.org/en-US/contribute/ |
|
52 #define firefox_community %s |
|
53 |
|
54 # LOCALIZATION NOTE (firefox_about): |
|
55 # link title for https://www.mozilla.org/en-US/about/ |
|
56 #define firefox_about %s |
|
57 |
|
58 #unfilter emptyLines''' |
|
59 |
|
60 strings = tuple(e.val for e in p if ll.search(e.key)) |
|
61 |
|
62 print codecs.utf_8_encode(template % strings)[0] |