Python gettext i18n — Explain Like I'm 5
Your App Learns New Languages
Imagine you build a toy vending machine. It has buttons that say “Press here” and “Thank you!” in English. Now your friend in Japan wants one too — but the buttons should say the same things in Japanese.
You don’t want to build a whole new machine. You just want to swap out the labels.
That’s what gettext does for your Python programs. Every piece of text your user sees — buttons, error messages, instructions — gets wrapped in a special marker. Then translators write label sheets (called translation files) for each language. When someone in France runs your app, Python grabs the French label sheet and swaps every marker for the French version.
Your actual code stays exactly the same. The logic doesn’t change. Only the words on the screen change.
The marker looks like this: _("Hello"). That underscore function is the signal to Python: “This text might need translating.”
Professional apps like Firefox, GIMP, and Blender all use this exact system. It was invented decades ago for Unix programs and Python adopted it because it works so well.
The best part? If a translation is missing, the original English text shows up instead. Nobody sees a blank screen or a crash.
The one thing to remember: gettext is a label-swapping system — wrap your text in _(), provide translation files, and your app speaks any language without code changes.
See Also
- Python Babel Localization Babel teaches your Python app how dates, numbers, and currencies look in every country — not just yours.
- Python Locale Module Python's locale module reads your computer's regional settings so numbers, dates, and sorting feel right for where you live.
- Ci Cd Why big apps can ship updates every day without turning your phone into a glitchy mess — CI/CD is the behind-the-scenes quality gate and delivery truck.
- Containerization Why does software that works on your computer break on everyone else's? Containers fix that — and they're why Netflix can deploy 100 updates a day without the site going down.
- Python 310 New Features Python 3.10 gave programmers a shape-sorting machine, friendlier error messages, and cleaner ways to say 'this or that' in type hints.