Skip to content

Commit 4714165

Browse files
Merge pull request #1594 from Archit-Kohli/multi-language-translation
Add Multi Language Translation
2 parents b6321bc + f13ccee commit 4714165

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

Multi-Language Translation/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Multi-Language Translation
2+
This is an amazing python script that lets you translate a single phrase into multiple languages using google translate's API.
3+
4+
## Get Started
5+
Here you will learn how to run the python script, just follow these steps in order and you will be a polyglot in no time!
6+
7+
1. Go to [RapidAPI's Google Translate API](https://rapidapi.com/googlecloud/api/google-translate1).
8+
2. Get your free rapidAPI key by clicking on the subscribe button and choosing the free plan.
9+
3. Copy your API key under `X-RapidAPI-Key`.
10+
4. Just paste this key under the `'X-RapidAPI-Key'` in the *main.py* file.
11+
5. Here are the function parameters you need: `languages:list`&`phrase:str`. Refer below for a list of supported languages.
12+
6. Just enter the parameters in the function call
13+
7. run `pip install-r requirements.txt`.
14+
8. Run the `main.py` file.
15+
16+
## Sample Request
17+
```
18+
print(multi_translate(["ru","fr"],"hello"))
19+
```
20+
21+
### Output
22+
```
23+
hello
24+
{'ru': 'привет', 'fr': 'Salut'}
25+
```
26+
27+
## Supported Languages
28+
|Language |Code |
29+
| --- | --- |
30+
|Afrikaans|` af `|
31+
|Albanian|` sq `|
32+
|Amharic|` am `|
33+
|Arabic|` ar `|
34+
|Armenian|` hy `|
35+
|Azerbaijani|` az `|
36+
|Basque|` eu `|
37+
|Belarusian|` be `|
38+
|Bengali|` bn `|
39+
|Bosnian|` bs `|
40+
|Bulgarian|` bg `|
41+
|Catalan|` ca `|
42+
|Cebuano|` ceb `|
43+
|Chinese (Simplified)|` zh-CN `|
44+
|Chinese (Traditional)|` zh-TW `|
45+
|Corsican|` co `|
46+
|Croatian|` hr `|
47+
|Czech|` cs `|
48+
|Danish|` da `|
49+
|Dutch|` nl `|
50+
|English|` en `|
51+
|Esperanto|` eo `|
52+
|Estonian|` et `|
53+
|Finnish|` fi `|
54+
|French|` fr `|
55+
|Frisian|` fy `|
56+
|Galician|` gl `|
57+
|Georgian|` ka `|
58+
|German|` de `|
59+
|Greek|` el `|
60+
|Gujarati|` gu `|
61+
|Haitian Creole|` ht `|
62+
|Hausa|` ha `|
63+
|Hawaiian|` haw `|
64+
|Hebrew|` he** `|
65+
|Hindi|` hi `|
66+
|Hmong|` hmn `|
67+
|Hungarian|` hu `|
68+
|Icelandic|` is `|
69+
|Igbo|` ig `|
70+
|Indonesian|` id `|
71+
|Irish|` ga `|
72+
|Italian|` it `|
73+
|Japanese|` ja `|
74+
|Javanese|` jw `|
75+
|Kannada|` kn `|
76+
|Kazakh|` kk `|
77+
|Khmer|` km `|
78+
|Korean|` ko `|
79+
|Kurdish|` ku `|
80+
|Kyrgyz|` ky `|
81+
|Lao|` lo `|
82+
|Latin|` la `|
83+
|Latvian|` lv `|
84+
|Lithuanian|` lt `|
85+
|Luxembourgish|` lb `|
86+
|Macedonian|` mk `|
87+
|Malagasy|` mg `|
88+
|Malay|` ms `|
89+
|Malayalam|` ml `|
90+
|Maltese|` mt `|
91+
|Maori|` mi `|
92+
|Marathi|` mr `|
93+
|Mongolian|` mn `|
94+
|Myanmar (Burmese)|` my `|
95+
|Nepali|` ne `|
96+
|Norwegian|` no `|
97+
|Nyanja (Chichewa)|` ny `|
98+
|Pashto|` ps `|
99+
|Persian|` fa `|
100+
|Polish|` pl `|
101+
|Portuguese (Portugal, Brazil)|` pt `|
102+
|Punjabi|` pa `|
103+
|Romanian|` ro `|
104+
|Russian|` ru `|
105+
|Samoan|` sm `|
106+
|Scots Gaelic|` gd `|
107+
|Serbian|` sr `|
108+
|Sesotho|` st `|
109+
|Shona|` sn `|
110+
|Sindhi|` sd `|
111+
|Sinhala (Sinhalese)|` si `|
112+
|Slovak|` sk `|
113+
|Slovenian|` sl `|
114+
|Somali|` so `|
115+
|Spanish|` es `|
116+
|Sundanese|` su `|
117+
|Swahili|` sw `|
118+
|Swedish|` sv `|
119+
|Tagalog (Filipino)|` tl `|
120+
|Tajik|` tg `|
121+
|Tamil|` ta `|
122+
|Telugu|` te `|
123+
|Thai|` th `|
124+
|Turkish|` tr `|
125+
|Ukrainian|` uk `|
126+
|Urdu|` ur `|
127+
|Uzbek|` uz `|
128+
|Vietnamese|` vi `|
129+
|Welsh|` cy `|
130+
|Xhosa|` xh `|
131+
|Yiddish|` yi `|
132+
|Yoruba|` yo `|
133+
|Zulu|` zu `|
134+
135+
## Author
136+
[Archit Kohli](https://github.com/Archit-Kohli)

Multi-Language Translation/main.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import requests
2+
3+
url = "https://google-translate1.p.rapidapi.com/language/translate/v2"
4+
5+
headers = {
6+
"content-type": "application/x-www-form-urlencoded",
7+
"Accept-Encoding": "application/gzip",
8+
"X-RapidAPI-Key": "ENTER RAPID API KEY HERE",
9+
"X-RapidAPI-Host": "google-translate1.p.rapidapi.com"
10+
}
11+
12+
# function to send a request
13+
def multi_translate(languages:list,phrase:str):
14+
print(phrase)
15+
res = {}
16+
for i in languages:
17+
payload = {
18+
"q": phrase,
19+
"target": i
20+
}
21+
22+
response = requests.post(url, data=payload, headers=headers)
23+
24+
res[i] = response.json()['data']['translations'][0]['translatedText']
25+
return res
26+
27+
28+
print(multi_translate(["ru","fr"],"hi"))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

0 commit comments

Comments
 (0)