-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslator0.2.py
More file actions
204 lines (191 loc) · 6.72 KB
/
Translator0.2.py
File metadata and controls
204 lines (191 loc) · 6.72 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import time
import random
from Conjugation import conjugate
from googletrans import Translator
translator = Translator(service_urls=['translate.google.com'])
###imports###
#Initializing variables#
##Creating an array of all the words
file = open("./Dictionary.txt", "r", encoding="utf8")
english = {}
i = 0
while True:
temp = file.readline().replace('\n', '').split(',')
if temp == ['']:
break
print(temp)
english[i] = temp
i += 1
print()
file.close()
i = 0
##Creating parts of sentences
nouns = {}
verbs = {}
for i in english:
if "noun" in english[i]:
nouns[len(nouns)] = english[i]
elif "verb" in english[i]:
verbs[len(verbs)] = english[i]
subjects = {
0 : ("I", "yo"),
1 : ("you", "tú"),
2 : ("he", "él"),
3 : ("she", "ella"),
4 : ("you (formal)", "usted"),
5 : ("we (m)", "nosotros"),
6 : ("we (f)", "nosotras"),
7 : ("they (formal)", "ustedes"),
8 : ("they (m)", "ellos"),
9 : ("they (f)", "ellas"),
}
tenses = ("present")
words = len(english)
translation = ""
print(f"""Welcome to Translator 0.1
This is still in Beta so please be patient, as some functions may not work or will work incorrectly
The number of available words: {words}""")
def langmodeselect():
return input("\nWhat mode do you want?\n1. English to Spanish\n2. Spanish to English\n3. Both\n")
def flashcards():
#initialize variables
temp = ''
answer = ''
langmode = langmodeselect()
repeats = 0
#Start loop
while answer not in ("stop", "exit", "quit"):
if repeats > 0:
input()
else:
repeats = 1
rng = random.randrange(0,words)
##Lang 1 is English->Spanish, Lang 2 is vice versa##
if langmode == '1':
lang = 1
elif langmode == '2':
lang = 2
else:
lang = random.randrange(1,2)
if lang == 1:
answer = input(f"{english[rng][0]}\n")
answer = answer.lower()
#Sometimes an English word can translate to 2 or more spanish words
#So as long as answer is one of them it's correct
if answer in english[rng] and answer != english[rng][0]:
print('Congratulations! You got it right\n')
elif answer not in ("stop", "exit", "quit"):
x = english[rng][1]
## print(f'You guessed: {answer}')
print(f'Correct word: {x}\n')
elif lang == 2:
answer = input(f"{english[rng][1]}\n")
answer = answer.lower()
if answer == english[rng][0]:
print('Congratulations! You got it right\n')
elif answer not in ("stop", "exit", "quit"):
x = english[rng][0]
## print(f'You guessed: {answer}')
print(f'Correct word: {x}\n')
def createsentence():
##Initializes variables##
langmode = langmodeselect()
answer = ''
repeats = 0
while answer not in ("stop", "exit", "quit"):
if langmode == '1':
lang = 1
elif langmode == '2':
lang = 2
else:
lang = random.randrange(1,3)
if repeats > 0:
input()
else:
repeats = 1
noun = nouns[random.randrange(0,len(nouns))]
verb = verbs[random.randrange(0,len(verbs))]
subject = subjects[random.randrange(0,len(subjects))]
print(f'''
Verb is: {verb}
noun is: {noun}
subject is: {subject}
language: {lang}
''')
sentences = { ##The pre-made sentences that are used, similar to Mad-Libs##
0 : (f'{subject[0]} {conjugate ("to want", "present", subject[0])} {verb[0]} with the {noun[0]}',
f'{subject[1]} {conjugate ("querer", "present", subject[1])} {verb[1]} con {noun[1]}'),
1 : (f'the {noun[0]} {conjugate(verb[0], "present", "it")} the tree',
f'{noun[1]} {conjugate(verb[1], "present", "it")} el árbol'),
2 : (f'{subject[0]} {conjugate(verb[0], "present", subject[0])} the {noun[0]}',
f'{subject[1]} {conjugate(verb[1], "present", subject[1])} {noun[1]}')
}
rng = random.randrange(0, len(sentences))
print(f'Number was: {rng}')
##Lang 1 is English->Spanish, Lang 2 is vice versa##
if lang == 1:
answer = input(f'\nSentence:\n{sentences[rng][0].capitalize()}.\n')
answer = answer.lower()
if answer == f'{sentences[rng][1]}':
print('Congratualations!')
elif answer in ("stop", "exit", "quit"):
main()
else:
print(f'Correct sentence:\n{sentences[rng][1].capitalize()}.')
elif lang == 2:
answer = input(f'\nSentence:\n{sentences[rng][1].capitalize()}.\n')
answer = answer.lower()
if answer == f'{sentences[rng][0]}':
print('Congratualations!')
elif answer in ("stop", "exit", "quit"):
main()
else:
print(f'Correct sentence: \n{sentences[rng][0].capitalize()}.')
def changelog():
print()
file1 = open("./changelog.txt", "r")
print(file1.read())
file1.close()
def main ():
repeats = 0
while True:
if repeats > 0:
time.sleep(1)
else:
repeats = 1
mode = input("\nWhat would you like to do?\n1. Start Flashcards \n2. Work with sentences\n3. See all words\n4. See all English words\n5. View Changelog\n")
if mode == "1" or mode.lower() == "start":
flashcards()
elif mode == "2":
createsentence()
elif mode == "3":
print('\nCurrent words are:')
for k,v in english.items():
print(f'{k}. {v}')
print('Enter any input to continue')
while input() == '3':
None
elif mode == "4":
print("\nEnglish words are:")
for k, v in english.items():
print(f"{k}. {v[0].capitalize()}")
print('Enter any input to continue')
while input() == '4':
None
elif mode == '5':
changelog()
print('\nEnter any input to continue')
while input() == '5':
None
#Solely for testing out googletrans; not an actual mode
elif mode == '6':
translation = translator.translate('He to walk to the store', src='en', dest='es')
print(translation.text)
else:
break
mode = input('Are you sure you want to quit? Y/N\n')
if mode.lower() == 'n' or mode.lower() == 'no':
main()
else:
print('Thanks for playing!')
main()