All articles

Python: a small translation exercise at work

Two language files, 3000 lines each, untranslated strings. A Python script (tuples, sets, dictionaries) to find what's missing.

Python: a small translation exercise at work

Not long ago, I started programming in Python. I really wondered where developers' obsession with this language came from 🐍 probably a venom you're born with 😁. In reality, what Python offers is a unique developer experience (DX), which I got a taste of.

At work, we had a problem: strings not translated into French. There are two language files holding all of an app's strings, structured as PHP associative arrays at least 3000 lines each.

I wrote a script that reads each file's content and restructures it into tuples, sets and dictionaries in Python. Then I diff the two tuples (English and French) to get the list of keys present on the English side but missing on the French side. I store that list in a new file, php”, ready to be translated via an API 381 remaining lines.

This exercise taught me to read from files and manipulate sequences (strings, sets, tuples, lists) and dictionaries in Python. A rather fun little exercise. 🙌🏾

[object Object] — 2
Share