File size: 2,242 Bytes
6f68287
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
special_combs = {
    'đ' : 'ъ', 'Đ' : 'Ъ',
    'ђ' : 'ъ', 'Ђ' : 'Ъ',
    'dž': 'ъ', 'Dž' : 'Ъ',
    'dz': 'ъ', 'Dz' : 'Ъ',
    'џ' : 'ъ', 'Џ' : 'Ъ',
    'c' : 'ts', 'C' : 'Ts',
}

serbian_dict = {
    'а': 'a', 'А' : 'A',
    'б': 'b', 'Б' : 'B',
    'в': 'v', 'В' : 'V',
    'г': 'g', 'Г' : 'G',
    'д': 'd', 'Д' : 'D',
    'е': 'e', 'Е' : 'E',
    'ж': 'zh', 'Ж' : 'Zh',
    'ž': 'zh', 'Ž' : 'Zh',
    'з': 'z', 'З' : 'Z',
    'и': 'i', 'И' : 'I',
    'ј': 'y', 'Ј' : 'Y',
    'j': 'y', 'J' : 'Y',
    'к': 'k', 'К' : 'K',
    'л': 'l', 'Л' : 'L',
    'љ': 'ly', 'Љ' : 'Ly',
    'lj': 'ly', 'Lj' : 'Ly',
    'м': 'm', 'М' : 'M',
    'н': 'n', 'Н' : 'N',
    'њ': 'ny', 'Њ' : 'Ny',
    'nj': 'ny', 'Nj' : 'Ny',
    'о': 'o', 'О' : 'O',
    'п': 'p', 'П' : 'P',
    'р': 'r', 'Р' : 'R',
    'с': 's', 'С' : 'S',
    'т': 't', 'Т' : 'T',
    'ћ': 'ch', 'Ћ' : 'Ch',
    'ć': 'ch', 'Ć' : 'Ch',
    'č': 'ch', 'Č' : 'Ch',
    'у': 'u', 'У' : 'U',
    'ф': 'f', 'Ф' : 'F',
    'х': 'h', 'Х' : 'H',
    
    'ч': 'ch', 'Ч' : 'Ch',
    # 'џ': 'dz', 'Џ' : 'Dz',
    'ш': 'sh', 'Ш' : 'Sh',
    'š': 'sh', 'Š' : 'Sh',
}

cyrillic_equiv_dict = {
    'ъ' : 'j', 'Ъ' : 'J',
    'ц': 'ts', 'Ц' : 'Ts',
}

def check_special_comb(word):
    for comb in special_combs:
        if comb in word:
            word = word.replace(comb,special_combs[comb])
    return word

def serbian_letter_to_eng(letter):
    if letter in serbian_dict:
        return serbian_dict[letter]
    else:
        return letter
    
def cyrillic_to_eng(word):
    for cyrillic in cyrillic_equiv_dict:
        if cyrillic in word:
            word = word.replace(cyrillic,cyrillic_equiv_dict[cyrillic])
    return word

def serbian_sentence_to_latin(sentence):
    sentence = str(sentence)
    # print("Original word: ", sentence)
    sentence = check_special_comb(sentence)
    # print("Just after special combination replacement: -", sentence)
    sentence = ''.join([serbian_letter_to_eng(letter) for letter in sentence])
    # print("After regular word replacement: -", sentence)
    sentence = cyrillic_to_eng(sentence)
    # print("Simplified pronunciation: -", sentence)
    return sentence