Ejemplo n.º 1
0
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);
Ejemplo n.º 2
0
def getContrastReadingPageHtml(translationLocale, translator, action,
                               reqPath, userLocale):
  contrastReadingPageTemplateValue = {
      'reqPath': reqPath,
      'trInfo': getXmlLocaleTranslationInfo(action,
                                            translationLocale,
                                            translator) }

  oriBody = paliXslt(action).find('body')
  trBody = translationXslt(action, translationLocale, translator).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)

  footNotes = processTranslatedPElementsNotes(trPElms)

  contrastReadingPageTemplateValue['contrastReadings'] = \
    etree.tostring(table) + etree.tostring(footNotes)

  template = getJinja2Env(userLocale).get_template('contrastReadingPage.html')
  return template.render(contrastReadingPageTemplateValue)