Created
July 19, 2018 04:24
-
-
Save KatiGithub/bdef02aeb71f1d8493da4153334050ed to your computer and use it in GitHub Desktop.
To work with this you need to do pip install googletrans and if using VSCode make sure to go into the directory at C:\Python\Python36\Lib\site-packages and take the folders correlated with googletrans API and copy and paste into your python workspace folder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from googletrans import Translator | |
import sys | |
import codecs | |
import os.path | |
translator = Translator() | |
language = str(input("Language code: ")) | |
file_Exist = str(input("Filename: ")) | |
file_Exist2 = file_Exist | |
file_Exist = os.path.exists(file_Exist) | |
if file_Exist == True: | |
translations = codecs.open(file_Exist2, "r", "UTF-8").read() | |
result = translator.translate(translations, dest = language) | |
print(result.origin + " -> " + result.text) | |
print("Done translating!") | |
sys.exit() | |
while file_Exist == False: | |
quit_or_not = str(input("File to translate non existent, ('x' to exit): ")) | |
file_Exist2 = quit_or_not | |
if quit_or_not == "x": | |
print("Done!") | |
sys.exit() | |
file_Exist = quit_or_not | |
file_Exist = os.path.exists(file_Exist) | |
if file_Exist == True: | |
translations = codecs.open(file_Exist2, "r", "UTF-8").read() | |
result = translator.translate(translations, dest = language) | |
print(result.origin + " -> " + result.text) | |
print("done translating!") | |
sys.exit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment