Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added nkechi ijeoma -WT-21-168/.DS_Store
Binary file not shown.
168 changes: 168 additions & 0 deletions nkechi ijeoma -WT-21-168/translator.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"def register ():\n",
" user_name= input( \"create a user name!\" )\n",
" user_password= input (\"enter a password! \")\n",
" if user_name :\n",
" print (f'welcome { user_name } hope you enjoy using the system')\n",
" else:\n",
" print(\"please enter a user name\")\n",
"\n",
"def greet():\n",
" print(\"hi, welcome this is nkechi's translator\")\n",
" pass;"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
"def translator(sentense):\n",
" url = \"https://google-translate1.p.rapidapi.com/language/translate/v2\"\n",
"\n",
" payload = \"q=\"+sentense+\" &target=es&source=en\"\n",
"\n",
" headers = {\n",
" 'content-type': \"application/x-www-form-urlencoded\",\n",
" 'accept-encoding': \"application/gzip\",\n",
" 'x-rapidapi-key': \"3a6325ca5amsh1deed8e94b50cd7p1d0302jsn0f984cb4c696\",\n",
" 'x-rapidapi-host': \"google-translate1.p.rapidapi.com\"\n",
" }\n",
"\n",
" response = requests.request(\"POST\", url, data=payload, headers=headers)\n",
"\n",
"# print(response.text)\n",
" return response.json()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
"def transalator_app(sentenses):\n",
" translated_sentenses = []\n",
" for sentense in sentenses:\n",
" \n",
" translated_sentenses.append(translator(sentense))\n",
"# print(sentense)\n",
" \n",
" print(translated_sentenses)"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[{'data': {'translations': [{'translatedText': 'Qué está mal'}]}}, {'data': {'translations': [{'translatedText': 'estoy yendo a casa'}]}}, {'data': {'translations': [{'translatedText': 'Estoy enojado'}]}}]\n"
]
}
],
"source": [
"sentenses = ['What is Wrong','I am coming home','I am angry']\n",
"\n",
"transalator_app(sentenses)"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
"def askForQuestionToBeTranslated():\n",
" isFinished = 0\n",
" question = \"\"\n",
" question = input(\"Enter Your Question To Be Transalated\")\n",
" questionList = []\n",
" questionList.append(question)\n",
" \n",
" while isFinished == 0:\n",
" response = input(\"Do you want to add another Question\")\n",
" if response == \"No\":\n",
" isFinished = 1\n",
" else:\n",
" question = input(\"Enter Your Question To Be Transalated\")\n",
" questionList.append(question) \n",
" \n",
" return questionList"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hi, welcome this is nkechi's translator\n",
"create a user name!MIchael\n",
"enter a password! Ji\n",
"welcome MIchael hope you enjoy using the system\n",
"Enter Your Question To Be TransalatedI am here\n",
"Do you want to add another QuestionNo\n",
"[{'data': {'translations': [{'translatedText': 'Estoy aquí'}]}}]\n"
]
}
],
"source": [
"greet()\n",
"register ()\n",
"transalator_app(askForQuestionToBeTranslated())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}