I'm working in a python library that is going to be used by Brazilians, the official speak language here is Portuguese! Basically, I want to get the Exception messages in portuguese, for example:
Instead of get...
>>> float('A')
ValueError: could not convert string to float: A
I wanna get this...
>>> float('A')
ValueError: não é possível converter a string para um float: A
Is there any way to do it?
The CPython implementation does not provide any automatic mean of localizing error messages. Hence you should rewrite all python's error messages in portuguese and either add a lot of try...except
blocks or replace sys.excepthook
to handle the exceptions.
If you plan to do this I'd consider using the gettext
module for the localization.
Other python implementations do have localized error messages(like IronPython).
In my opinion what you want to do is not a good practice. These brazilian developer must know a bit of English anyway if they want to look at some documentation of python/libraries(which aren't probably all translated in portuguese).
Also if you localize the error messages searching for them on the web becomes much harder.
The default language for python is English and one is always encouraged to use it (as per PEP 8).
So, as far as I know, they do not support/encourage using different languages like this, so you'll likely have to change everything yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With