python google translate csv

Solutions on MaxInterview for python google translate csv by the best coders in the world

showing results for - "python google translate csv"
Emilie
13 Sep 2016
1import pandas as pd 
2from google_trans_new import google_translator  
3translator = google_translator()  
4translate_text = translator.translate('Hola mundo!', lang_src='es', lang_tgt='en')  
5
6df = pd.read_csv('./my_file.csv')
7translations = []
8unique_elements = df['text'].unique()
9countr = 0
10for element in unique_elements:
11    countr += 1
12    translations.append(f'{str(countr)}|{translator.translate(element, lang_src="es", lang_tgt="en")}')  
13
14ostream = open ('./my_file_en.csv', 'w', encoding='utf-8')
15ostream.write('\n'.join(translations))
16ostream.close()