I built polyglot-python: write Python with localized keywords - 9 locales, no AI, byte-identical output

Wait 5 sec.

The annoying thing about "program in your own language" demos is that they are usually either a transliteration of identifiers, or a natural-language toy that never produces runnable code. I wanted the boring version: real Python semantics, real CPython, your words. So most of the work went into the parts that make it un-cute. polyglot-python 0.2.1 (MIT, zero runtime dependencies, on PyPI and npm) leaves Python's grammar alone and swaps only the 35 hard keywords before the file reaches the interpreter: tr eğer -> if fonksiyon -> def döndür -> return ru если -> if определить -> def вернуть -> return hi अगर -> if फलन -> def लौटाओ -> return zh 如果 -> if 函数 -> def 返回 -> return Nine locales ship today - tr, es, pt, de, fr, zh, hi, ar, ru - each one a table of exactly the 35 entries in keyword.kwlist, all nine living in a single locales.json. What I actually spent the time on: - The rewrite is tokenizer-driven. It runs the stdlib tokenize module and replaces only exact NAME tokens that match a locale keyword, so strings, comments, f-strings, numbers, identifiers and attribute names are untouched, and a localized keyword after a dot stays an attribute. - Line numbers carry over one-to-one and a per-line column map pulls reported positions back onto your localized file. A slip therefore comes out as Sözdizimi hatası: prog.tr:2:1: 'return' outside function - Turkish header, your line and column, CPython's English detail. - Tables are validated at load: every key must be in keyword.kwlist and every replacement must tokenize as a single identifier on the running interpreter, so a bad table raises instead of half-translating. - Determinism is tested rather than claimed: a CI job translates every example twice on Linux, Windows and macOS and compares the bytes. Four commands: run, translate (with -o to export plain .py), check (translates and compiles without executing, which is the one you put in CI) and locales. For run, options go before the file and everything after it becomes sys.argv[1:]. Numbers measured rather than copied from the README: I checked out the v0.2.1 tag this morning and ran the suite myself on CPython 3.12 - 120 tests collected, 120 passed, 314 of 314 statements covered. CI enforces the 100% gate on Ubuntu 3.12, runs 3.12/3.13/3.14 there plus 3.12 on Windows and macOS, and installs the built wheel into a clean environment to check a Russian example and run the Turkish one with it. Two limits up front, because the name oversells it. It localizes keywords only: print, range, the standard library and CPython's exception detail text stay English (the error headers themselves are localized). And run does not put the script's own directory on sys.path the way python file.py does, so a two-file program needs PYTHONPATH - I tried it with a sibling import and got a plain ModuleNotFoundError. GitHub: https://github.com/Furox-Art/polyglot-python PyPI: https://pypi.org/project/polyglot-python/ npm: https://www.npmjs.com/package/polyglot-python   submitted by   /u/Emergency-Tutor-7 [link]   [comments]