def extract(packages, output_dir, output_package, domain, products): """Extract i18n strings """ parser = OptionParser() parser.add_option( "-o", "--output", dest="output_dir", help="alternate output directory for the extracted file") parser.add_option( "-p", "--package", action="store_true", dest="output_package", help="extract to the output package") (options, args) = parser.parse_args() if products: load_products(products) output_file = domain + '.pot' if options.output_dir: if not os.path.exists(options.output_dir): print "Selected directory doesn't exists: %s" % options.output_dir return output_file = os.path.join(options.output_dir, output_file) elif options.output_package: if not output_package: print "No output package selected." return python_package = resolve(output_package) path = os.path.join(os.path.dirname(python_package.__file__), 'i18n') if not os.path.exists(path): print "Selected package doesn't have translations: %s" % path return output_file = os.path.join(path, output_file) elif output_dir: if not os.path.exists(output_dir): os.mkdir(output_dir) output_file = os.path.join(output_dir, output_file) print "Domain: %s" % domain print "Output file: %r" % output_file maker = MultiplePOTMaker(output_file, '') for package in packages: print "Processing package %s..." % package python_package = resolve(package) path = os.path.dirname(python_package.__file__) maker.add(py_strings(path, domain, verify_domain=True), path, package) maker.add(tal_strings(path, domain), path, package) # For Chameleon templates maker.add(tal_strings(path, domain, filePattern='*.cpt'), path, package) maker.add(formulator_strings(path, domain), path, package) maker.add(metadata_strings(path, domain), path, package) maker.write() return output_file
def tal_strings_xml(path, domain, include_default_domain, exclude_dirs, **kw): from zope.app.locales.extract import tal_strings return tal_strings(path, domain, include_default_domain, exclude=exclude_dirs, filePattern='*.xml')
for mName in moduleNames: mIdx = path.rfind(mName) basePath = basePath[:mIdx] pkgPath = path[len(basePath):] print "package: %r\n" \ "base: %r\n" \ "path: %r\n" \ % (pkgPath, basePath, path) maker.add(py_strings(path, domain, exclude=exclude_dirs, verify_domain=verify_domain), basePath) if not python_only: maker.add(zcml_strings(path, domain, site_zcml), basePath) maker.add(tal_strings(path, domain, include_default_domain, exclude=exclude_dirs), basePath) for maker_func in makers: try: maker.add( maker_func( path=path, base_path=basePath, exclude_dirs=exclude_dirs, domain=domain, include_default_domain=include_default_domain, site_zcml=site_zcml, ), basePath) except TypeError: # BBB: old arguments maker.add(maker_func(path, basePath, exclude_dirs), basePath)
def main(argv=sys.argv): try: opts, args = getopt.getopt( argv[1:], "hed:s:i:m:p:o:x:t:", [ "help", "domain=", "site_zcml=", "path=", "python-only", "verify-domain", "exclude-default-domain", ], ) except getopt.error as msg: usage(1, msg) domain = "z3c" include_default_domain = True output_dir = None exclude_dirs = [] python_only = False verify_domain = False site_zcml = None makers = [] eggPaths = [] header_template = None for opt, arg in opts: if opt in ("-h", "--help"): usage(0) elif opt in ("-d", "--domain"): domain = arg elif opt in ("-s", "--site_zcml"): site_zcml = arg elif opt in ("-e", "--exclude-default-domain"): include_default_domain = False elif opt in ("-m",): makers.append(resolve(arg)) elif opt in ("-o",): output_dir = arg elif opt in ("-x",): exclude_dirs.append(arg) elif opt in ("--python-only",): python_only = True elif opt in ("--verify-domain"): verify_domain = True elif opt in ("-p", "--package"): package = resolve(arg) path = os.path.dirname(package.__file__) if not os.path.exists(path): usage(1, "The specified path does not exist.") eggPaths.append((arg, path)) elif opt in ("-t",): if not os.path.exists(arg): usage(1, "The specified header template does not exist.") header_template = arg # setup output file output_file = domain + ".pot" if output_dir: if not os.path.exists(output_dir): os.mkdir(output_dir) output_file = os.path.join(output_dir, output_file) print( "domain: %r\n" "configuration: %s\n" "exclude dirs: %r\n" "include default domain: %r\n" "python only: %r\n" "verify domain: %r\n" "header template: %r\n" % ( domain, site_zcml, exclude_dirs, include_default_domain, python_only, verify_domain, header_template, ) ) # setup pot maker maker = POTMaker(output_file, "", header_template) # add maker for each given path for pkgName, path in eggPaths: basePath = path moduleNames = pkgName.split(".") moduleNames.reverse() for mName in moduleNames: mIdx = path.rfind(mName) basePath = basePath[:mIdx] pkgPath = path[len(basePath):] print( "package: %r\n" "base: %r\n" "path: %r\n" % (pkgPath, basePath, path) ) maker.add( py_strings( path, domain, exclude=exclude_dirs, verify_domain=verify_domain ), basePath, ) if not python_only: maker.add(zcml_strings(path, domain, site_zcml), basePath) maker.add( tal_strings( path, domain, include_default_domain, exclude=exclude_dirs ), basePath, ) for maker_func in makers: try: maker.add( maker_func( path=path, base_path=basePath, exclude_dirs=exclude_dirs, domain=domain, include_default_domain=include_default_domain, site_zcml=site_zcml, ), basePath, ) except TypeError: # BBB: old arguments maker.add(maker_func(path, basePath, exclude_dirs), basePath) maker.write() print("output: %r\n" % output_file)
if (isinstance(self.msgid, Message) and self.msgid.default is not None): # Write msgstr file.write('msgstr %s\n' % normalize(default)) else: file.write('msgstr ""\n') file.write('\n') class CCPOTMaker(POTMaker): def add(self, strings, base_dir=None): for msgid, locations in strings.items(): if msgid == '': continue if msgid not in self.catalog: self.catalog[msgid] = CCPOTEntry(msgid) for filename, lineno in locations: if base_dir is not None: filename = filename.replace(base_dir, '') self.catalog[msgid].addLocationComment(filename, lineno) maker = CCPOTMaker('extracted.pot', '') maker.add(py_strings('cc/engine/', 'cc_org'), 'cc/engine/') maker.add( tal_strings('cc/engine/templates/', 'cc_org', include_default_domain=True), 'cc/engine/templates/') maker.write()
mIdx = path.rfind(mName) basePath = basePath[:mIdx] pkgPath = path[len(basePath):] else: # this is a package linked in as externals basePath = path[:srcIdx] pkgPath = path[len(basePath):] print "package: %r\n" \ "base: %r\n" \ "path: %r\n" \ % (pkgPath, basePath, path) maker.add(py_strings(path, domain, exclude=exclude_dirs), basePath) if not python_only: maker.add(zcml_strings(path, domain, site_zcml), basePath) maker.add(tal_strings(path, domain, include_default_domain, exclude=exclude_dirs), basePath) maker.add(tal_strings(path, domain, include_default_domain, exclude=exclude_dirs, filePattern='*.ptm'), basePath) for m in makers: poMaker = resolve(m) maker.add(poMaker(path, basePath, exclude_dirs)) maker.write() print "output: %r\n" % output_file if __name__ == '__main__': main()
def main(argv=sys.argv): try: opts, args = getopt.getopt( argv[1:], 'hed:s:i:m:p:o:x:t:', ['help', 'domain=', 'site_zcml=', 'path=', 'python-only', 'verify-domain', 'exclude-default-domain']) except getopt.error as msg: usage(1, msg) domain = 'z3c' include_default_domain = True output_dir = None exclude_dirs = [] python_only = False verify_domain = False site_zcml = None makers = [] eggPaths = [] header_template = None for opt, arg in opts: if opt in ('-h', '--help'): usage(0) elif opt in ('-d', '--domain'): domain = arg elif opt in ('-s', '--site_zcml'): site_zcml = arg elif opt in ('-e', '--exclude-default-domain'): include_default_domain = False elif opt in ('-m', ): makers.append(resolve(arg)) elif opt in ('-o', ): output_dir = arg elif opt in ('-x', ): exclude_dirs.append(arg) elif opt in ('--python-only',): python_only = True elif opt in ('--verify-domain'): verify_domain = True elif opt in ('-p', '--package'): package = resolve(arg) path = os.path.dirname(package.__file__) if not os.path.exists(path): usage(1, 'The specified path does not exist.') eggPaths.append((arg, path)) elif opt in ('-t', ): if not os.path.exists(arg): usage(1, 'The specified header template does not exist.') header_template = arg # setup output file output_file = domain+'.pot' if output_dir: if not os.path.exists(output_dir): os.mkdir(output_dir) output_file = os.path.join(output_dir, output_file) print("domain: %r\n" \ "configuration: %s\n" \ "exclude dirs: %r\n" \ "include default domain: %r\n" \ "python only: %r\n" \ "verify domain: %r\n" \ "header template: %r\n" \ % (domain, site_zcml, exclude_dirs, include_default_domain, python_only, verify_domain, header_template)) # setup pot maker maker = POTMaker(output_file, '', header_template) # add maker for each given path for pkgName, path in eggPaths: basePath = path moduleNames = pkgName.split('.') moduleNames.reverse() for mName in moduleNames: mIdx = path.rfind(mName) basePath = basePath[:mIdx] pkgPath = path[len(basePath):] print("package: %r\n" \ "base: %r\n" \ "path: %r\n" \ % (pkgPath, basePath, path)) maker.add(py_strings(path, domain, exclude=exclude_dirs, verify_domain=verify_domain), basePath) if not python_only: maker.add(zcml_strings(path, domain, site_zcml), basePath) maker.add(tal_strings(path, domain, include_default_domain, exclude=exclude_dirs), basePath) for maker_func in makers: try: maker.add( maker_func( path=path, base_path=basePath, exclude_dirs=exclude_dirs, domain=domain, include_default_domain=include_default_domain, site_zcml=site_zcml, ), basePath) except TypeError: # BBB: old arguments maker.add(maker_func(path, basePath, exclude_dirs), basePath) maker.write() print("output: %r\n" % output_file)
"'site.zcml' location: %s\n" \ "exclude dirs: %r\n" \ "domain: %r\n" \ "include default domain: %r\n" \ "output file: %r\n" \ "Python only: %r" \ "parse html files: %r" \ % (base_dir, path, site_zcml, exclude_dirs, domain, include_default_domain, output_file, python_only, extract_html) from zope.app.locales.extract import POTMaker, \ py_strings, tal_strings, zcml_strings maker = POTMaker(output_file, path) maker.add(py_strings(path, domain, exclude=exclude_dirs), base_dir) if not python_only: maker.add(zcml_strings(path, domain, site_zcml), base_dir) maker.add(tal_strings(path, domain, include_default_domain, exclude=exclude_dirs), base_dir) if extract_html: maker.add(tal_strings(path, domain, include_default_domain, exclude=exclude_dirs, filePattern='*.html'), base_dir) for m in makers: poMaker = resolve(m) maker.add(poMaker(path, base_dir, exclude_dirs)) maker.write() if __name__ == '__main__': main()
if (isinstance(self.msgid, Message) and self.msgid.default is not None): # Write msgstr file.write('msgstr %s\n' % normalize(default)) else: file.write('msgstr ""\n') file.write('\n') class CCPOTMaker(POTMaker): def add(self, strings, base_dir=None): for msgid, locations in strings.items(): if msgid == '': continue if msgid not in self.catalog: self.catalog[msgid] = CCPOTEntry(msgid) for filename, lineno in locations: if base_dir is not None: filename = filename.replace(base_dir, '') self.catalog[msgid].addLocationComment(filename, lineno) maker = CCPOTMaker('extracted.pot', '') maker.add(py_strings('cc/engine/', 'cc_org'), 'cc/engine/') maker.add(tal_strings('cc/engine/templates/', 'cc_org', include_default_domain=True), 'cc/engine/templates/') maker.write()