def handleMatch(self, match):
     attrib = {'lang': 'sa', 'class': 'sa2'}
     el = etree.Element('span', **attrib)
     text = match.group(2)
     devanagari = sanscript.transliterate(text, 'hk', 'iast')
     el.text = devanagari
     return el
示例#2
0
def sa2(text, _from=sanscript.SLP1, _to=sanscript.IAST, tag="span", safe=False):
    """Return a secondary Sanskrit string in the given tag."""
    sans = sanscript.transliterate(text or "", _from, _to)
    if safe:
        sans = Markup(sans)
    if tag:
        return Markup('<%s lang="sa" class="sa2">%s</%s>') % (tag, sans, tag)
    else:
        return sans
示例#3
0
def sa1(text, _from=sanscript.SLP1, _to=sanscript.DEVANAGARI, tag="span", safe=False):
    """Return a primary Sanskrit string in the given tag."""
    sans = sanscript.transliterate(text or "", _from, _to)
    if safe:
        sans = Markup(sans)
    if tag:
        return Markup('<%s class="sa1">%s</%s>') % (tag, sans, tag)
    else:
        return sans
示例#4
0
def mw_transform(data, to_script):
    clean_data = re.sub('[~_]', ' ', data)

    xml = ET.fromstring(clean_data)
    for gk in xml.findall('.//gk'):
        gk.text = B.transliterate(gk.text)
    translate(xml, mw)

    result = ET.tostring(xml, 'utf-8').decode('utf-8')
    result = re.sub(' ([,;])', '\\1', result)
    if to_script:
        return S.transliterate('##' + result, S.SLP1, to_script)
    else:
        return result
示例#5
0
def mw_pretty(from_script, q):
    form = QueryForm(csrf_enabled=False)
    to_script = S.DEVANAGARI

    if from_script not in S.SCHEMES:
        return redirect(url_for('.mw'))

    slp_query = S.transliterate(q, from_script, S.SLP1)
    results = mw_results(slp_query)
    for key in results:
        results[key] = [mw_transform(x, to_script) for x in results[key]]

    return render_template('dicts/mw/index.html', form=form,
                           to_script=to_script,
                           results=results)
示例#6
0
def mw():
    form = QueryForm(request.args, csrf_enabled=False)

    if form.validate():
        q = form.data['q']
        from_script = form.data['from_script']
        to_script = form.data['to_script']

        slp_query = S.transliterate(q, from_script, S.SLP1)
        results = mw_results(slp_query)
        for key in results:
            results[key] = [mw_transform(x, to_script) for x in results[key]]

        return render_template('dicts/mw/index.html',
                               form=form,
                               to_script=to_script,
                               results=results)
    else:
        return render_template('dicts/mw/index.html', form=form)
示例#7
0
def to_slp1(q, from_script):
    """Helper function. Transliterate to SLP1."""
    return sanscript.transliterate(q, from_script, sanscript.SLP1)