How I Built A Fast Translator using Pons and Anki

EQVq...nucG
8 May 2022
115

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

If you would like to integrate a dictionary into your website or application, PONS has an ideal solution: PONS provides…
en.pons.com

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


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

Write & Read to Earn with BULB

Learn More

Enjoy this blog? Subscribe to Timothy102

3 Comments

B
No comments yet.
Most relevant comments are displayed, so some may have been filtered out.