def getHtmlTitle(urlLocale, texts, userLocale, translator=None, contrastReading=None): tmpValue = {'urlLocale': urlLocale, 'texts': texts } if translator: tmpValue['translator'] = translator.decode('utf-8') tmpValue['contrastReading'] = contrastReading titleTemplate = getJinja2Env(userLocale).get_template('title.html') return titleTemplate.render(tmpValue)
def getHtmlTitle(urlLocale, texts, userLocale, translator=None, contrastReading=None): tmpValue = {'urlLocale': urlLocale, 'texts': texts} if translator: tmpValue['translator'] = translator.decode('utf-8') tmpValue['contrastReading'] = contrastReading titleTemplate = getJinja2Env(userLocale).get_template('title.html') return titleTemplate.render(tmpValue)
def getAllLocalesTranslationsHtml(urlLocale, userLocale): # check cache first key = '%s#%s' % (urlLocale, userLocale) if key in AllTransCache: return AllTransCache[key] # cache miss template = getJinja2Env(userLocale).get_template('info.html') AllTransCache[key] = template.render({'urlLocale': urlLocale, 'userLocale': userLocale, 'localeTranslations': getAllLocalesTranslationsTemplateValues()}) return AllTransCache[key]
def getContrastReadingPageHtml(translationLocale, translator, action, reqPath, userLocale): contrastReadingPageTemplateValue = { 'reqPath': reqPath } oriBody = paliXslt(action).find('body') # extract translation information and then do xslt transformedHtml, contrastReadingPageTemplateValue['trInfo'] = \ translationXslt2(action, translationLocale, translator) trBody = transformedHtml.find('body') if (len(oriBody) != len(trBody)): raise Exception('two XML document body childs # not match') table = etree.fromstring('<table class="ctReading"></table>') trPElms = [] # create contrast (parallet) reading table for i in range(len(oriBody)): if oriBody[0].tag != 'p' or trBody[0].tag != 'p': raise Exception('not in p tag') tr = etree.fromstring('<tr></tr>') if etree.tostring(oriBody[0]) == etree.tostring(trBody[0]): # not translated tdOri = etree.fromstring('<td></td>') tdOri.append(oriBody[0]) tdTr = etree.fromstring('<td></td>') trBody.remove(trBody[0]) tr.append(tdOri) tr.append(tdTr) else: tdOri = etree.fromstring('<td></td>') tdOri.append(oriBody[0]) tdTr = etree.fromstring('<td></td>') trPElms.append(trBody[0]) tdTr.append(trBody[0]) tr.append(tdOri) tr.append(tdTr) table.append(tr) # move notes to the bottom of the page footNotes = processTranslatedPElementsNotes(trPElms) contrastReadingPageTemplateValue['contrastReadings'] = \ etree.tostring(table) + etree.tostring(footNotes) template = getJinja2Env(userLocale).get_template('contrastReadingPage.html') return template.render(contrastReadingPageTemplateValue)
def getTranslationPageHtml(translationLocale, translator, action, reqPath, userLocale): translationPageTemplateValue = { 'reqPath': reqPath, 'trInfo': getXmlLocaleTranslationInfo(action, translationLocale, translator) } # xslt transformedHtml = translationXslt(action, translationLocale, translator) processNotes(transformedHtml) # get innerHTML of body translationPageTemplateValue['body'] = etree.tostring( transformedHtml.find('body'))[6:-7] template = getJinja2Env(userLocale).get_template('translationPage.html') return template.render(translationPageTemplateValue);
def getTranslationPageHtml(translationLocale, translator, action, reqPath, userLocale): translationPageTemplateValue = { 'reqPath': reqPath } # extract translation information and then do xslt transformedHtml, translationPageTemplateValue['trInfo'] = \ translationXslt2(action, translationLocale, translator) # move notes to the bottom of the page processNotes(transformedHtml) # get innerHTML of body translationPageTemplateValue['body'] = etree.tostring( transformedHtml.find('body'))[6:-7] template = getJinja2Env(userLocale).get_template('translationPage.html') return template.render(translationPageTemplateValue);
def getCanonPageHtml(node, reqPath, userLocale): canonPageTemplateValue = { 'reqPath': reqPath } if 'action' in node: canonPageTemplateValue['isPaliText'] = True # set links of translation and contrast reading if any canonPageTemplateValue['i18nLinks'] = \ getI18nLinksTemplateValues(os.path.basename(node['action'])) # xslt transformedHtml = paliXslt(node['action']) # get innerHTML of body canonPageTemplateValue['body'] = etree.tostring( transformedHtml.find('body'))[6:-7] else: canonPageTemplateValue['childs'] = node['child'] template = getJinja2Env(userLocale).get_template('canonPage.html') return template.render(canonPageTemplateValue);
# cache miss, go find translated names trText = {} for locale in canonTextTranslation: trText[locale] = translateNodeText(text, locale) if trText[locale] == text: trText[locale] = '' # store translated canon names in cache translatedCanonNameCache[text] = trText return trText # FIXME: ugly coding style from template import getJinja2Env jj2env = getJinja2Env('en_US') jj2env.filters['nodeTextStrip2'] = nodeTextStrip2 jj2env.filters['translateNodeText4'] = translateNodeText4 def getHtmlTitle(urlLocale, texts, userLocale, translator=None, contrastReading=None): tmpValue = {'urlLocale': urlLocale, 'texts': texts } if translator: tmpValue['translator'] = translator.decode('utf-8') tmpValue['contrastReading'] = contrastReading titleTemplate = getJinja2Env(userLocale).get_template('title.html') return titleTemplate.render(tmpValue)
# cache miss, go find translated names trText = {} for locale in canonTextTranslation: trText[locale] = translateNodeText(text, locale) if trText[locale] == text: trText[locale] = '' # store translated canon names in cache translatedCanonNameCache[text] = trText return trText # FIXME: ugly coding style from template import getJinja2Env jj2env = getJinja2Env('en_US') jj2env.filters['nodeTextStrip2'] = nodeTextStrip2 jj2env.filters['translateNodeText4'] = translateNodeText4 def getHtmlTitle(urlLocale, texts, userLocale, translator=None, contrastReading=None): tmpValue = {'urlLocale': urlLocale, 'texts': texts} if translator: tmpValue['translator'] = translator.decode('utf-8') tmpValue['contrastReading'] = contrastReading titleTemplate = getJinja2Env(userLocale).get_template('title.html')