1
0
mirror of https://github.com/serega404/VodokanalBot.git synced 2026-07-01 17:39:17 +03:00

feat: добавил поддержку транслитерации и разбиения сообщений для MeshCore

This commit is contained in:
2026-06-02 00:23:45 +03:00
parent 03a4ad5d8e
commit 56c6d4406d
5 changed files with 422 additions and 2 deletions
+92
View File
@@ -0,0 +1,92 @@
FULL_CYR2LAT = {
'а': 'a',
'б': 'b',
'в': 'v',
'г': 'g',
'д': 'd',
'е': 'e',
'ё': 'yo',
'ж': 'zh',
'з': 'z',
'и': 'i',
'й': 'y',
'к': 'k',
'л': 'l',
'м': 'm',
'н': 'n',
'о': 'o',
'п': 'p',
'р': 'r',
'с': 's',
'т': 't',
'у': 'u',
'ф': 'f',
'х': 'h',
'ц': 'ts',
'ч': 'ch',
'ш': 'sh',
'щ': 'sch',
'ъ': '',
'ы': 'y',
'ь': '',
'э': 'e',
'ю': 'yu',
'я': 'ya',
}
SOFT_CYR2LAT = {
'а': 'a',
'е': 'e',
'о': 'o',
'р': 'p',
'с': 'c',
'у': 'y',
'х': 'x',
'А': 'A',
'В': 'B',
'Е': 'E',
'К': 'K',
'М': 'M',
'Н': 'H',
'О': 'O',
'Р': 'P',
'С': 'C',
'Т': 'T',
'Х': 'X',
}
CYR2LAT_MODES = {
'full': FULL_CYR2LAT,
'off': None,
'soft': SOFT_CYR2LAT,
}
def apply_case(replacement, char):
if char.isupper():
return replacement.capitalize()
return replacement
def cyr2lat(message, mode='full'):
if mode not in CYR2LAT_MODES:
raise ValueError("Unknown cyr2lat mode: " + mode)
if mode == 'off':
return message
mapping = CYR2LAT_MODES[mode]
result = []
for char in message:
if mode == 'soft':
result.append(mapping.get(char, char))
continue
replacement = mapping.get(char.lower())
if replacement is None:
result.append(char)
else:
result.append(apply_case(replacement, char))
return ''.join(result)