-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (57 loc) · 2.16 KB
/
main.py
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
# -*- coding: utf-8 -*-
"""
Ceci script permet de traduire du LiemrOm au francais.
Le langage LiemrOm est tiré du livre de Ghislain Taschereau - Etoiles Tombantes.
L'auteur en question m'a lancé le défi de trouver l'erreur
qui s'était glissée dans sa langue inventée.
Le programme ne corrige pas les fautes de francais. Cette verification
doit se faire manuellement.
TL;DR Challenge accepted!
"""
import Repository
def is_vowel(l):
for vowel in _vowels:
if l == vowel:
return True
return False
def is_translatable(l):
for character in _specialCharacters:
if l == character:
return False
return True
def translate_sentence(s):
s = s.lower()
translation = ""
for char in s:
if is_translatable(char):
if is_vowel(char):
translation += _vowels[_vowels.index(char) + 1] if _vowels.index(char) < len(_vowels) - 1 else _vowels[0]
else:
translation += _consonants[_consonants.index(char) + 1] if _consonants.index(char) < len(_consonants) - 1 else _consonants[0]
else:
translation += char
return translation
def pretty_print_and_export(dictionary, filename):
output = open(filename, "w")
for translatedPage in sorted(dictionary):
header = "\nTraduction de la page %s" % translatedPage
print header
output.write(header + "\n")
for translatedSentence in dictionary[translatedPage]:
print translatedSentence
output.write(translatedSentence + "\n")
output.close()
# Main Program
_vowels = Repository.vowels
_consonants = Repository.consonants
_specialCharacters = Repository.specialChars
_liemrOmDictionary = Repository.liemrOmDictionary
# Etape 1 - Traduction du dialecte de Lothaire Fillion
translatedDictionary = {}
for page in _liemrOmDictionary.keys():
translatedPageSentences = []
for sentence in _liemrOmDictionary[page]:
translatedPageSentences.append(translate_sentence(sentence))
translatedDictionary[page] = translatedPageSentences
# Etape 2 - Export de la traduction
pretty_print_and_export(translatedDictionary, "translation.txt")