Last active
July 6, 2025 09:59
-
-
Save Blayung/4864b20abc4b46760dfd4eff861798fe to your computer and use it in GitHub Desktop.
Polish to cyrillic text converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
mainMap = { | |
"a": "а", | |
"ą": "ѧ", | |
"b": "б", | |
"c": "ц", | |
"ć": "ть", | |
"d": "д", | |
"e": "э", | |
"ę": "ѫ", | |
"f": "ф", | |
"g": "ґ", | |
"h": "г", | |
"i": "и", | |
"j": "й", | |
"k": "к", | |
"l": "л", | |
"ł": "ў", | |
"m": "м", | |
"n": "н", | |
"ń": "нь", | |
"o": "о", | |
"ó": "у", | |
"p": "п", | |
"r": "р", | |
"s": "с", | |
"ś": "сь", | |
"t": "т", | |
"u": "у", | |
"w": "в", | |
"y": "ы", | |
"ź": "зь", | |
"ż": "ж" | |
} | |
iotatedVowels = {"a": "я", "e": "е", "o": "ё", "u": "ю", "ą": "ѩ", "ę": "ѭ"} | |
def toCyrillic(text): | |
text = text.lower().replace("ti", "tъi").replace("ci", "ti") | |
outputText = [] | |
for index, letter in enumerate(text): | |
previousLetter = text[index - 1] if index > 0 else " " | |
if letter in iotatedVowels.keys() and (previousLetter == "j" or previousLetter == "i"): | |
if index > 1 and previousLetter == "j" and text[index - 2] in ["n", "s", "z", "t"]: | |
outputText[-1] = "ъ" | |
outputText += iotatedVowels[letter] | |
else: | |
outputText[-1] = iotatedVowels[letter] | |
elif letter == "z": | |
if previousLetter == "c": | |
if index > 2 and text[index - 2] == "z" and text[index - 3] == "s": | |
outputText[-1] = "щ" | |
else: | |
outputText[-1] = "ч" | |
elif previousLetter == "s": | |
outputText[-1] = "ш" | |
elif previousLetter == "r": | |
outputText[-1] = "ж" | |
else: | |
outputText += "з" | |
elif letter == "h" and previousLetter == "c": | |
outputText[-1] = "х" | |
elif letter in mainMap.keys(): | |
outputText += mainMap[letter] | |
else: | |
outputText += letter | |
return "".join(outputText) | |
if __name__ == "__main__": | |
open("output.txt", "w").write(toCyrillic(open("input.txt", "r").read())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment