michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import sys michael@0: import re michael@0: import codecs michael@0: try: michael@0: from Mozilla.Parser import getParser michael@0: except ImportError: michael@0: sys.exit('''extract-bookmarks needs compare-locales michael@0: michael@0: Find that on http://pypi.python.org/pypi/compare-locales. michael@0: This script has been tested with version 0.6, and might work with future michael@0: versions.''') michael@0: michael@0: ll=re.compile('\.(title|a|dd|h[0-9])$') michael@0: michael@0: p = getParser(sys.argv[1]) michael@0: p.readFile(sys.argv[1]) michael@0: michael@0: template = '''#filter emptyLines michael@0: michael@0: # LOCALIZATION NOTE: The 'en-US' strings in the URLs will be replaced with michael@0: # your locale code, and link to your translated pages as soon as they're michael@0: # live. michael@0: michael@0: #define bookmarks_title %s michael@0: #define bookmarks_heading %s michael@0: michael@0: #define bookmarks_toolbarfolder %s michael@0: #define bookmarks_toolbarfolder_description %s michael@0: michael@0: # LOCALIZATION NOTE (getting_started): michael@0: # link title for https://www.mozilla.org/en-US/firefox/central/ michael@0: #define getting_started %s michael@0: michael@0: # LOCALIZATION NOTE (firefox_heading): michael@0: # Firefox links folder name michael@0: #define firefox_heading %s michael@0: michael@0: # LOCALIZATION NOTE (firefox_help): michael@0: # link title for https://www.mozilla.org/en-US/firefox/help/ michael@0: #define firefox_help %s michael@0: michael@0: # LOCALIZATION NOTE (firefox_customize): michael@0: # link title for https://www.mozilla.org/en-US/firefox/customize/ michael@0: #define firefox_customize %s michael@0: michael@0: # LOCALIZATION NOTE (firefox_community): michael@0: # link title for https://www.mozilla.org/en-US/contribute/ michael@0: #define firefox_community %s michael@0: michael@0: # LOCALIZATION NOTE (firefox_about): michael@0: # link title for https://www.mozilla.org/en-US/about/ michael@0: #define firefox_about %s michael@0: michael@0: #unfilter emptyLines''' michael@0: michael@0: strings = tuple(e.val for e in p if ll.search(e.key)) michael@0: michael@0: print codecs.utf_8_encode(template % strings)[0]