We’re teaching a class in chinese (Mandarin). For our students, it would be easier (and make more sense to them) if the error output running php (on the commandline) was localizable to Mandarin. Is there a way to configure our php setup to support this (i.e. edit a php.ini file)?
We’re teaching a class in chinese (Mandarin). For our students, it would be easier
Share
I have downloaded the PHP source code and searched how the source handles it’s errors. After going through a couple of (randomly picked) files and found these kinds of lines all over the place:
This goes on and on forever which makes me conclude that errors are hardcoded and thus not available in any other language…
Too bad 🙁
After hours of searching (5 hours and 45 minutes to be exact) – I have found a couple of solutions that probably aren’t worthwhile but who am I to judge.
Translations are often saved in files with the .po extension. These files contain a bunch of original strings and the translated strings. This means that you have to translate every string each, manually. You can create files with PoEdit.
Then you need to parse these files. You can build a PHP version that has the Gettext module installed. Alternatively, the Zend Framework is able to parse these files as well.
Clearly, you don’t want to translate every possible string manually. Last option is using a translator service such as Google Translate or Microsoft Translate.
In all cases, you have to replace the existing error string with the new error string. There’s a native PHP function called
set_error_handler(). This allows you to set a custom error handling function. If you want to translate the existing error string you should do it there. Here’s a set up that you could use (I haven’t tested this thoroughly):All that remains is including this code to your script and you should be all good!