How to correctly (without violating the basic replacement algorithm) screw the following 2 conversions to the existing Ukrainian transliterator code in the Latin alphabet?
- Convert the letters "Є", "Ї", "Y", "Yu", "I" to "Ye", "Yi", "Y", "Yu", "Ya", respectively (but only in the case if these letters are in the first position in the word).
- Convert the combination of the letters "zg" to "zgh" in any position in the word.
In all cases, the register of the next letter must be taken into account so that something like “ZGUROVSKAYA - ZghUROVSKAIA” does not work out.
About the replacement algorithm:
The Ukrainian letters stand out in a separate dictionary, which are represented as several Latin characters, after which a dictionary (transliteration table) is created from pairs of characters, where for each of these letters (, F, X, C, H, W, U, I and I) there are variants with each of the lowercase letters of the Russian alphabet. Accordingly, it remains to first make a replacement for such pairs of characters, and then for all other characters that are not translated. Each of the letters corresponding to several Latin letters, followed by a lowercase character ([az]) is replaced by the Latin representation of this letter, followed by the same lowercase character (without transliteration). After that, respectively, the remaining lowercase letters are replaced separately, as, by the way, and capital. When replacing capital letters corresponding to several Latin characters, the upper () method is used for the Latin representation of the letter. In two cycles, where regular expressions are not used for the replacement, the replacement operation is performed using the string replace method.
translated = text.translate(dict(zip(map(ord, "ЄЖ"), ('Ye', 'Zh')))). By the way, if the solution in the above answer worked for you, then tick the answer . - jfs