View difference between Paste ID: EuNGfP82 and mRFmUzQQ
SHOW: | | - or go back to the newest paste.
1
cyrLetters = [u"А", u"Б", u"В", u"Г", u"Д", u"Ђ", u"Е", u"Ж", u"З", u"И", u"Ј", u"К", u"Л", u"Љ", u"М", 
2
	            u"Н", u"Њ", u"О", u"П", u"Р", u"С", u"Т", u"Ћ", u"У", u"Ф", u"Х", u"Ц", u"Ч", u"Џ", u"Ш",
3
	            u"а", u"б", u"в", u"г", u"д", u"ђ", u"е", u"ж", u"з", u"и", u"ј", u"к", u"л", u"љ", u"м", 
4
	            u"н", u"њ", u"о", u"п", u"р", u"с", u"т", u"ћ", u"у", u"ф", u"х", u"ц", u"ч", u"џ", u"ш"]
5
	              
6
latLetters = [u"A", u"B", u"V", u"G", u"D", u"Đ", u"E", u"Ž", u"Z", u"I", u"J", u"K", u"L", u"LJ", u"M", 
7
	            u"N", u"NJ", u"O", u"P", u"R", u"S", u"T", u"Ć", u"U", u"F", u"H", u"C", u"Č", u"DŽ", u"Š",
8
	            u"a", u"b", u"v", u"g", u"d", u"đ", u"e", u"ž", u"z", u"i", u"j", u"k", u"l", u"lj", u"m", 
9
	            u"n", u"nj", u"o", u"p", u"r", u"s", u"t", u"ć", u"u", u"f", u"h", u"c", u"č", u"dž", u"š"]
10
11-
def fixMixedCyrLatWord(word):
11+
def fixMixedCyrLatWord(match):
12
13
	word = match.group()
14
15
	latToCyr = zip(latLetters, cyrLetters)
16
	cyrToLat = zip(cyrLetters, latLetters)
17
	
18
	originScript = 'l'
19
	if originScript == 'c':
20
		letterMap = dict(zip(cyrLetters, latLetters))
21
	elif originScript == 'l':
22
		letterMap = dict(zip(latLetters, cyrLetters))
23
	else:
24
	  raise Exception("Unexpected script: " + originScript)
25
  
26
	newWord = ""
27
	for c in word:
28
		newWord += letterMap.get(c, c)
29
	return newWord
30
31
fixes['mixedWords']= {
32
    'regex': True,
33
    'msg': {
34
           'sr':u'Порука...',
35
    },
36
    'replacements': [
37
        (u"[А-Ша-шЈјЊњЏџЂђ]+[A-Za-zĐđŽžĆćČ芚].*", fixMixedCyrLatWord),
38
        (u"[A-Za-zĐđŽžĆćČ芚]+[А-Ша-шЈјЊњЏџЂђ].*", fixMixedCyrLatWord),
39
    ],
40
    'exceptions': { #Your exceptions here
41
    }
42
}