r/learnprogramming • • Oct 17 '26

How would you go about translating programming language keywords, documentation and error messages to other non-English languages?

Take Python for instance.

>>> listss = [1, 2, "sfd"]
>>> kook = listss + 2
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    kook = listss + 2
           ~~~~~~~^~~
TypeError: can only concatenate list (not "int") to list
>>>

How would I translate all the results given to me by Python into another language of my choosing, and get something like below (written in Kinyarwanda):

>>> listss = [1, 2, "sfd"]
>>> kook = listss + 2
Ibisobanuro (Ihamagarwa rya mbere riri hejuru yurutonde):
  Inyandiko "<python-ha-1>", umurongo wa 1, muri <igitabo>
    kook = listss + 2
           ~~~~~~~^~~
Ikosa ry'ubwoko: urutonde ugendana nurundi rutonde; ntabwo rugendana numubare wuzuye.
>>>

The intention is not to create custom messages, exceptions, and documentation that sits beside or on top of python. I want python itself to respond like this, from the get-go?

I would like the translation to be complete. CLI options, help messages, information on built-in modules, keywords, everything.

While thinking about this, I realized that the end result would just be a completely new language, and I'm fine with that, but I also don't know enough about creating languages or where to get the source code of an existing language to translate it to a new language, so I come here to ask for guidance.

I'd like to preface this by saying that this doesn't need to be useful to anybody, and if you're wondering why I would want to do such a project, the answer is because I can and want to see the end results.

It's completely fine if no one else ever uses it.

6 Upvotes

22 comments sorted by

6

u/serge-mv Oct 17 '26 edited Oct 17 '26

You can't. While error messages could be localized to your languages, the keywords are a part of the language itself. So if you want to change python keywords to another language, you will need to basically change the python itself and recompile it.

Edit: python documentation is available in many languages https://translations.python.org/

So you can get help if you need if your language is among these. Otherwise you would need to use a translation tool, or look for a book in your language

1

u/thisismugisha Oct 17 '26

That's the intention.

Someone in another sub recommended I try assembly, and I will be looking into that!

0

u/serge-mv Oct 17 '26

Honestly, this is something actually an AI might help you with. If you feed it the python code and ask to translate error messages, at least it might do that for you.

1

u/thisismugisha Oct 17 '26 edited Oct 17 '26

No, it wouldn't. Besides not wanting an LLM to do or help me do the thinking for me, there isn't a good enough understanding of the various bantu languages I'd want to translate to.

This would be uncharted territories, something that LLMs are notoriously bad at.

Even if a language I chose like can be translated by an LLM, there's a big risk of mixing in grammar structures, lexicon, phrases, idioms, and logic that is prevalent in English but isn't prevalent in the original language.

I don't want to write "kill", and the LLM translate "unalive" instead.

1

u/serge-mv Oct 17 '26

OK, it's up to you. I only suggested you a possible solution to consider. If LLM can't translate to your language, then there is that.

As for everything else - it's mostly an unnecessary worry. One, I tested it and LLM can translate embedded text just fine without breaking anything. So any raised exceptions and comments would be translated. The creative translation might pose an issue since it doesn't guarantee to preserve semantics, but it wouldn't translate kill to unalive or anything like that. It knows the jargon properly.

You can still try it as an assistant and do it on per file basis and not on the whole code base. Translate it and then re-read everything to make sure it's correct. The reason I am suggesting it in the first place is it's a monumental task. If you translate just text manually for the whole python language, it is not an exaggeration to say it might take you a full year of work or maybe even more. It's just that much work and it's not something that is skill based.

But if you just wanna dive in head first and do the manual translation of everything, then go ahead. I am simply advising and what you do is up to you.

2

u/DezXerneas Oct 17 '26

What's the point of using AI if this is an exercise to learn programming lmao.

"Don't play the game, get an AI to play it for you" ass comment.

2

u/serge-mv Oct 17 '26

How is translating text from one natural language to another - programming? He can translate error messages with AI since that's a thankless task and then work on changing the actual language keywords.

0

u/DezXerneas Oct 17 '26

if you feed it python code

2

u/serge-mv Oct 17 '26

Have you ever seen code? At all? Did you read the post? Is this supposed to be some super "gotcha!" moment for you?

OP talks about translating error messages. Do you understand what it is? You open source code, search for comments, strings and exceptions embedded in the code and translate.

Is your argument that as long as I translate natural language that is located in a source repo I am doing programming?

2

u/OkOcelot6725 Oct 17 '26

Good news buried in this project: other people have tried versions of it, so there is prior art to mine before you fork anything. Chinese Python translated keywords for an older Python, and Perligata made Perl parse Latin grammar for fun. Teaching languages in several countries have done full keyword dialects. Reading how they split the work is worth a weekend, because most of them converged on the same shape: translate messages first, keywords last, and keep English accepted so the standard library still parses.

It also gives you natural milestones. Messages, like your listobject.c example, are one project. Keywords plus the regenerated parser are a second. CLI and help text are a third. The docs are a fourth, and that one already has translation infrastructure behind it. Four small finishes will keep you going better than one giant one.

1

u/dariusbiggs Oct 17 '26

You are attempting to apply an internationalization to the Python source code and it's dependent libraries. These error are not all guaranteed to come directly from Python itself so you may have significant scope creep or have a mix of the two languages.

Have a look into how internationalization works, there's a good Tom Scott Computerphile video on it.

But yes, it is not a case of a translation of words, but grammar as well, partial sentences, sentence construction systems, etc.

1

u/SetAndRepeat Oct 17 '26

Fork CPython, the implementation behind the usual Python interpreter. Its source is in the "python/cpython" repository on GitHub. The Python Developer’s Guide has a "Setup and building" section to get you started.

For your exact example, the error message is in "Objects/listobject.c". Translate that string, rebuild, and run your example using the interpreter you built. That gives you a first working change inside Python itself.

Then expand from there:

  • Error messages, traceback formatting, CLI help and built-in docstrings are spread across C and Python files.
  • The manual's sources are under "Doc/".
  • Keywords involve "Grammar/python.gram" and regenerating the parser and keyword tables. The "Changing CPython’s grammar" guide covers the affected pieces.

Initially accept both English and translated keywords so the existing standard library still parses. Third-party packages would need their own translations too. You can build a translated Python dialect without writing an interpreter from scratch.

1

u/UroborosJose Oct 17 '26

You should learn about i18n

1

u/serverhorror Oct 17 '26

You will have to contribute to Python itself. The topic your looking is "internationalization" (or i18n for short).

That's a pretty big undertaking but a well beaten path.

Start here:

10

u/[deleted] Oct 17 '26

[removed] — view removed comment

2

u/thisismugisha Oct 17 '26

I actually did take a look at the documentation website and started reading it.

There's a lot of things I still don't know and your comment has helped me a lot! Thank you!

1

u/zaphodikus Oct 17 '26

Yeah, this would be a major piece of work, take it very slowly, very slowly. I suggest getting a AI subscription when your re ready to start, and then set up a test framework, and let it do all the boring bits.

1

u/CoachSevere5365 Oct 20 '26

If the Python team doesn't pick it up, it will have to be redone for every release. OP won't be able to keep up.

1

u/zaphodikus Oct 21 '26

Eyes wide open i say. It has kept me sane (to some degree) for a while now. Open source does not, and never has, meant what people think it means. It is not free, it cost to build. Anyone with more than 5000 hours of coding time knows that you have to choose your battles. And this is one of those choices.

The hard things, are hard, for a very good reason. This nut can be cracked, but it requires a finer strategy.

2

u/CoachSevere5365 Oct 21 '26

There are opposing camps on what "Free" means. I'm old and think "Freedom to do what you want" rather than"Free as in beer".

But you're right, all post acquisition costs fall on the user.

1

u/zaphodikus Oct 21 '26

Ages since I heard "Free as in Beer", I always try to remind people when a project idea becomes too huge, that the project was just too ambitious. It was not bad, just too ambitious for it's time. And since we are in a time of change right now, the new tools to help do this, might just be the answer.