Translate EN To CN Fast (Batch and Python)

Hey there so i am playing with batch and python for fun again and i made this lol :neutral_face:
This script translates English to Chinese on google translator. I know its useless but its fun lol
https://video-amt2-1.xx.fbcdn.net/v/l/t42.3356-2/13426539_1793550174224389_1274282525_n.mp4/video-1465401961.mp4?vabr=240223&oh=4688446ff2099d15f3c2f754718ae5da&oe=5759EABF

Code Batch

@echo off
title Translate EN To CN
:START
cd C:\Program Files (x86)\Google\Chrome\Application
SET /P TRANSLATE= 
IF /I "%TRANSLATE%" NEQ "%TRANSLATE%" GOTO TRANSLATED
:TRANSLATED
chrome.exe https://translate.google.com/#en/zh-CN/"%TRANSLATE%"
cls
GOTO START

Code Python Download Ready EXE

import os 
import webbrowser 
os.system('title Translate EN To CN')
gt="https://translate.google.com/#en/zh-CN/"
while True:
  translate= raw_input("")
  webbrowser.open_new(gt+translate)
  os.system('cls')

M8, Python is way better suited as a scripting language. You could even launch Google with the default browser instead of Chrome.

I know @anon68632391 just for some reason i have way more fun when i do stuff in batch

You should learn some Python. It’s really easy to learn it. Here is how you would open your URL in Python:

url = 'http://www.python.org/'

# Open URL in a new tab, if a browser window is already open.
webbrowser.open_new_tab(url + 'doc/')

# Open URL in new window, raising the window if possible.
webbrowser.open_new(url)
2 Likes

what if you could take the value that the translator puts out and put that in the batch so you don’t have to go on the internet O:
probably hard to make

I am not sure if this is possible with batch :confused:

It’s probably impossible with batch. But there is a Python-API for that:
https://developers.google.com/api-client-library/python/apis/translate/v2

Here is some example code:

1 Like

@anon68632391 I ported it to python tell me if the code is ok

Nice, can’t test it right now, but it should work.
Implementing the Google API is a bit more complicated than this because you have to create a dev account etc.