X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_lib%2Frus%2Frus2lat.py;h=ae786167518100fb406eb64234dbf13c2bc404fc;hb=ad79073f55777a802e6a7bdc7c3a119d6bfe7155;hp=7fbbf06b5948d6d4268a02a4fdc03d69cc8e5f59;hpb=fb3af94919a9ee18ba1c35f927f19837f057fa1f;p=m_lib.git diff --git a/m_lib/rus/rus2lat.py b/m_lib/rus/rus2lat.py index 7fbbf06..ae78616 100755 --- a/m_lib/rus/rus2lat.py +++ b/m_lib/rus/rus2lat.py @@ -2,6 +2,7 @@ # -*- coding: koi8-r -*- from __future__ import print_function +from ..lazy.dict import LazyDictInitFunc # # Rus -> Lat transliteration (koi2lat and win2lat) @@ -71,25 +72,26 @@ koi2lat_d = { "Ù": "y", "Ü": "e", "À": "yu", - "Ñ": "ya" + "Ñ": "ya", } def make_xxx2lat(encoding="cp1251"): d = {} for k, v in koi2lat_d.items(): - k = unicode(k, "koi8-r").encode(encoding) d[k] = v return d -from m_lib.lazy.dict import LazyDictInitFunc win2lat_d = LazyDictInitFunc(make_xxx2lat, encoding="cp1251") def rus2lat(instr, rus2lat_d = koi2lat_d): out = [] for c in instr: - out.append(rus2lat_d.get(c, c)) + c = rus2lat_d.get(c, c) + if isinstance(c, int): + c = chr(c) + out.append(c) return ''.join(out) @@ -103,4 +105,4 @@ if __name__ == "__main__": Test = "ýÅÒÂÁËÏ× éÇÏÒØ çÒÉÇÏÒØÅ×ÉÞ. áâ÷ xyz ÁÂ× øøüàñ ßØÜÀÑ" print("Test:", Test) print("ôÅÓÔ:", koi2lat(Test)) - print("ôÅÓÔ:", win2lat(unicode(Test, "koi8-r").encode("cp1251"))) + print("ôÅÓÔ:", win2lat(Test))