def _init_pages(projectroot, languagecode): """Initialize localizable pages Does not do any merging. Reads in the en-US templates and makes .po files from it.""" logger = logging.getLogger('scripts.amo') # we need TidyLib to import pages if not tidy: logger.debug( "Cannot import pages without utidylib (http://utidylib.berlios.de/)." ) return enus_dir = os.path.join(projectroot, 'en_US', 'pages') this_dir = os.path.join(projectroot, languagecode, 'pages') # find all pages pages = os.listdir(enus_dir) thtml = re.compile("\.thtml$", re.IGNORECASE) pages = [f for f in pages if thtml.search(f)] for page in pages: # grab English template logger.debug('importing page %s', page) template = _tidy_page(os.path.join(enus_dir, page)) converter = html2po.html2po() output = open(os.path.join(this_dir, page[:-6]) + '.po', 'w') print >> output, converter.convertfile(template, page, False) template.close() output.close()
def _init_pages(projectroot, languagecode): """Initialize localizable pages Does not do any merging. Reads in the en-US templates and makes .po files from it.""" logger = logging.getLogger('scripts.amo') # we need TidyLib to import pages if not tidy: logger.debug("Cannot import pages without utidylib " "(http://utidylib.berlios.de/).") return enus_dir = os.path.join(projectroot, 'en_US', 'pages') this_dir = os.path.join(projectroot, languagecode, 'pages') # find all pages pages = os.listdir(enus_dir) thtml = re.compile("\.thtml$", re.IGNORECASE) pages = [f for f in pages if thtml.search(f)] for page in pages: # grab English template logger.debug('importing page %s', page) template = _tidy_page(os.path.join(enus_dir, page)) converter = html2po.html2po() output = open(os.path.join(this_dir, page[:-6])+'.po', 'w') print >> output, converter.convertfile(template, page, False) template.close() output.close()
def html2po( self, markup, duplicatestyle="msgctxt", keepcomments=False, ): """Helper to convert html to po without a file.""" inputfile = BytesIO(markup.encode() if isinstance(markup, str) else markup) convertor = html2po.html2po() return convertor.convertfile(inputfile, "test", duplicatestyle, keepcomments)
def html2po(self, markup, includeuntagged=False, duplicatestyle="msgctxt", keepcomments=False): """Helper to convert html to po without a file.""" inputfile = wStringIO.StringIO(markup) convertor = html2po.html2po() outputpo = convertor.convertfile(inputfile, "test", includeuntagged, duplicatestyle, keepcomments) return outputpo
def convertfile(storefile): return html2po().convertfile(storefile, os.path.basename(storefile.name))