Пример #1
0
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)
Пример #2
0
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);