def transliterate(text, lang1_code, lang2_code): """ convert the source language script (lang1) to target language script (lang2) text: text to transliterate lang1_code: language 1 code lang1_code: language 2 code """ if (lang1_code in langinfo.SCRIPT_RANGES) and (lang2_code in langinfo.SCRIPT_RANGES): # if Sinhala is source, do a mapping to Devanagari first if lang1_code == 'si': text = sdt.sinhala_to_devanagari(text) lang1_code = 'hi' # if Sinhala is target, make Devanagiri the intermediate target org_lang2_code = '' if lang2_code == 'si': lang2_code = 'hi' org_lang2_code = 'si' trans_lit_text = [] for c in text: newc = c offset = ord(c) - langinfo.SCRIPT_RANGES[lang1_code][0] if offset >= langinfo.COORDINATED_RANGE_START_INCLUSIVE and offset <= langinfo.COORDINATED_RANGE_END_INCLUSIVE: if lang2_code == 'ta': # tamil exceptions offset = UnicodeIndicTransliterator._correct_tamil_mapping( offset) newc = py23char(langinfo.SCRIPT_RANGES[lang2_code][0] + offset) trans_lit_text.append(newc) # if Sinhala is source, do a mapping to Devanagari first if org_lang2_code == 'si': return sdt.devanagari_to_sinhala(''.join(trans_lit_text)) return (''.join(trans_lit_text)) else: return text
def transliterate(text,lang1_code,lang2_code): """ convert the source language script (lang1) to target language script (lang2) text: text to transliterate lang1_code: language 1 code lang1_code: language 2 code """ if (lang1_code in langinfo.SCRIPT_RANGES) and (lang2_code in langinfo.SCRIPT_RANGES): # if Sinhala is source, do a mapping to Devanagari first if lang1_code=='si': text=sdt.sinhala_to_devanagari(text) lang1_code='hi' # if Sinhala is target, make Devanagiri the intermediate target org_lang2_code='' if lang2_code=='si': lang2_code='hi' org_lang2_code='si' trans_lit_text=[] for c in text: newc=c offset=ord(c)-langinfo.SCRIPT_RANGES[lang1_code][0] if offset >=langinfo.COORDINATED_RANGE_START_INCLUSIVE and offset <= langinfo.COORDINATED_RANGE_END_INCLUSIVE: if lang2_code=='ta': # tamil exceptions offset=UnicodeIndicTransliterator._correct_tamil_mapping(offset) newc=py23char(langinfo.SCRIPT_RANGES[lang2_code][0]+offset) trans_lit_text.append(newc) # if Sinhala is source, do a mapping to Devanagari first if org_lang2_code=='si': return sdt.devanagari_to_sinhala(''.join(trans_lit_text)) return (''.join(trans_lit_text)) else: return text
def test_SinhalaDevanagariTransliterator(self): sin = sdt.devanagari_to_sinhala('राजस्थान') self.assertEqual(sin, 'රාජස්ථාන') dev = sdt.sinhala_to_devanagari('රාජස්ථාන') self.assertEqual(dev, 'राजस्थान')
def test_SinhalaDevanagariTransliterator(self): sin = sdt.devanagari_to_sinhala('राजस्थान') self.assertEqual(sin, 'රාජස්ථාන') dev = sdt.sinhala_to_devanagari('රාජස්ථාන') self.assertEqual(dev, 'राजस्थान')
def test_SinhalaDevanagariTransliterator(self): sin = sdt.devanagari_to_sinhala("राजस्थान") self.assertEqual(sin, "රාජස්ථාන") dev = sdt.sinhala_to_devanagari("රාජස්ථාන") self.assertEqual(dev, "राजस्थान")