How I Built A Fast Translator using Pons and Anki

Make the translation work for youThis is the story of my battle with easing the translation process. Oh, and by the way, everything you are about to read falls under the assumption that you give a damn about learning languages and/or improving your gra…


This content originally appeared on Level Up Coding - Medium and was authored by Tim Cvetko

Make the translation work for you

This is the story of my battle with easing the translation process. Oh, and by the way, everything you are about to read falls under the assumption that you give a damn about learning languages and/or improving your grammar.

Photo by Justin Lim on Unsplash

The problem

I have found myself wasting a whole bunch of time during the translation process. This is how I previously dealt with adding new words.

  • I used to find a new word and I translated it using my favorite application.
Mine is Pons. Mainly I use it for English and German, but it comes in handy for translating Spanish song lyrics :)
  • I wrote down the new word in a very special notebook. Later on, I kept the new words in a file on my computer.
  • the words were then input to Anki-the mobile flashcards app

Hey, if it ain’t broke, don’t fix it. But it is. Here’s why my astonishingly-devised plan was counter-productive:

  • I had done the calculations. For every new word I wanted to add to my vocabulary, I spent approximately 20 seconds of time. Since the plan was to learn a significantly higher number of words per day, something had to be done.
  • All records I had kept were inconsistent and hard to look at.
  • I had a double-entry design. First, the words were written in a notebook or a file, then those same words would be put into Anki.

I wanted a clever system where I could spare the time for both the input and the search for new words.

The Solution

Luckily, after some research, I found that I could simplify the task. Pons has come up with their own Python API that you can use to translate any word, between any two languages.

PONS Online Dictionary API

That’s cool. At this stage, I can automate the code so any single word I want to translate, I can. That solves the issue of having to manually input the words.

All code can be found on Github.

The next problem I wanted to address was the double-entry problem. How do you write a script in which you have the program run through a bunch of words and return their translated meaning as output?

Having stored all new words in a text file before, the obvious alternative was to have different files, one containing the new words prepared for translation, and another one, containing their translations. All you have to do is intertwine the two files in the code in a way that the new words are automatically stored. We can do that :)

Cool. So far, the workflow is as follows. Once you find a word, you simply write it to the words file. Once you feel you’d like to translate, the list of words will automatically be stored for you in the corresponding file.

Image by Author

I know — I run (both English!) and German in a folder called English.

Handling the Anki Interface

That’s a biggy. Since Anki was originally built using Python, I thought they would enable a simple interface for interacting with the flashcards remotely. They didn’t.

Python requests had to have been used. You heard that right!

The script works by invoking the request to the Anki-connected server. A predefined JSON message containing the flashcard is left for you to send.

There you go. We have reached our destination. The automation of the translation process has been completed. Once selecting the word, the code translates it, stores it for future references, and uploaded it to Anki flashcards.

Briefly: a question may have arisen while reading: do you actually see the translated meaning? The correct answer is, yes, two times:

  • firstly, once you run the script, the terminal displays all words and their corresponding meaning
  • secondly, on the newly minted Anki Flashcards.

Conclusion

This is how incorporated my coding skills to solve a mundane issue I had with the task of translation. I hope this article intrigues you to find even neater solutions to automating tasks, such as translation.

Create beyond the imaginable!

Connect and read more

Hey, before you go. If you liked this article and would love to read some more content, I encourage you to subscribe to Medium for only $5 and earn yourself a membership. Follow for moreeee!

Thank you for reading this article.

Feel free to contact me via any social media. I’d be happy to get your feedback, acknowledgment, or criticism. Let me know what you create !!!

LinkedIn, Medium, GitHubGmail

Why Private Blockchains Matter


How I Built A Fast Translator using Pons and Anki was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Tim Cvetko


Print Share Comment Cite Upload Translate Updates
APA

Tim Cvetko | Sciencx (2022-04-10T16:29:32+00:00) How I Built A Fast Translator using Pons and Anki. Retrieved from https://www.scien.cx/2022/04/10/how-i-built-a-fast-translator-using-pons-and-anki/

MLA
" » How I Built A Fast Translator using Pons and Anki." Tim Cvetko | Sciencx - Sunday April 10, 2022, https://www.scien.cx/2022/04/10/how-i-built-a-fast-translator-using-pons-and-anki/
HARVARD
Tim Cvetko | Sciencx Sunday April 10, 2022 » How I Built A Fast Translator using Pons and Anki., viewed ,<https://www.scien.cx/2022/04/10/how-i-built-a-fast-translator-using-pons-and-anki/>
VANCOUVER
Tim Cvetko | Sciencx - » How I Built A Fast Translator using Pons and Anki. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/10/how-i-built-a-fast-translator-using-pons-and-anki/
CHICAGO
" » How I Built A Fast Translator using Pons and Anki." Tim Cvetko | Sciencx - Accessed . https://www.scien.cx/2022/04/10/how-i-built-a-fast-translator-using-pons-and-anki/
IEEE
" » How I Built A Fast Translator using Pons and Anki." Tim Cvetko | Sciencx [Online]. Available: https://www.scien.cx/2022/04/10/how-i-built-a-fast-translator-using-pons-and-anki/. [Accessed: ]
rf:citation
» How I Built A Fast Translator using Pons and Anki | Tim Cvetko | Sciencx | https://www.scien.cx/2022/04/10/how-i-built-a-fast-translator-using-pons-and-anki/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.