]> git.phdru.name Git - m_lib.git/blob - m_lib/rus/rus2lat.py
Version 3.1.1: Python 3.13
[m_lib.git] / m_lib / rus / rus2lat.py
1 #! /usr/bin/env python
2 # -*- coding: koi8-r -*-
3
4 from __future__ import print_function
5 from ..lazy.dict import LazyDictInitFunc
6
7 #
8 # Rus -> Lat transliteration (koi2lat and win2lat)
9 #
10
11 koi2lat_d = {
12    "�": "A",
13    "�": "B",
14    "�": "V",
15    "�": "G",
16    "�": "D",
17    "�": "E",
18    "�": "Yo",
19    "�": "Zh",
20    "�": "Z",
21    "�": "I",
22    "�": "Y",
23    "�": "K",
24    "�": "L",
25    "�": "M",
26    "�": "N",
27    "�": "O",
28    "�": "P",
29    "�": "R",
30    "�": "S",
31    "�": "T",
32    "�": "U",
33    "�": "F",
34    "�": "H",
35    "�": "Ts",
36    "�": "Ch",
37    "�": "Sh",
38    "�": "Sh",
39    "�": "'",
40    "�": "'",
41    "�": "Y",
42    "�": "E",
43    "�": "Yu",
44    "�": "Ya",
45    "�": "a",
46    "�": "b",
47    "�": "v",
48    "�": "g",
49    "�": "d",
50    "�": "e",
51    "�": "yo",
52    "�": "zh",
53    "�": "z",
54    "�": "i",
55    "�": "y",
56    "�": "k",
57    "�": "l",
58    "�": "m",
59    "�": "n",
60    "�": "o",
61    "�": "p",
62    "�": "r",
63    "�": "s",
64    "�": "t",
65    "�": "u",
66    "�": "f",
67    "�": "h",
68    "�": "ts",
69    "�": "ch",
70    "�": "sh",
71    "�": "sh",
72    "�": "'",
73    "�": "'",
74    "�": "y",
75    "�": "e",
76    "�": "yu",
77    "�": "ya",
78 }
79
80 def make_xxx2lat(encoding="cp1251"):
81    d = {}
82    for k, v in koi2lat_d.items():
83       d[k] = v
84    return d
85
86
87 win2lat_d = LazyDictInitFunc(make_xxx2lat, encoding="cp1251")
88
89
90 def rus2lat(instr, rus2lat_d = koi2lat_d):
91    out = []
92    for c in instr:
93       c = rus2lat_d.get(c, c)
94       if isinstance(c, int):
95          c = chr(c)
96       out.append(c)
97    return ''.join(out)
98
99
100 koi2lat = rus2lat
101
102 def win2lat(instr):
103    return rus2lat(instr, win2lat_d)
104
105
106 if __name__ == "__main__":
107    Test = "�������� ����� �����������. ��� xyz ��� ����� �����"
108    print("Test:", Test)
109    print("����:", koi2lat(Test))
110    print("����:", win2lat(Test))