Unicode & multi language support strategy in PHP5

I have heard that PHP6 will support Unicode, which I hope will simplify multilingual support. However, PHP5 has pretty weak support for unicode and multilingualism (i.e. just a set of specialized string functions).

I was wondering what are your strategies for supporting unicode and multi-languaage in your PHP5 applications?

Also, how do you save translations since PHP5 does not have a WebResource file like ASP.NET?

+4
php unicode
Jul 06 '09 at 1:45
source share
4 answers

It is not so difficult, but you can ask your question a little more specifically.

If you are talking to a database, make sure that your database stores data in UTF-8 and that the connection to your database is in UTF-8 (common error). Remember to run this when establishing the connection:

mysql_set_charset('utf8'); 

For user input, set the accept-charset attribute on your forms.

 <form accept-charset="utf-8"> 

Submit your sites with the appropriate HTTP header:

 header('Content-Type: text/html; charset=utf-8'); 

or at least set the appropriate meta tags for your site:

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

Save the source code files encoded in UTF-8.

If you keep everything in UTF-8, you usually don't need to worry about anything. This becomes problematic only after you start mixing encodings throughout the application.

If you start talking about string manipulation, of course, you have to take care a bit. Basically you want to use the mb_ set of string functions, as you indicated yourself.

+9
Jul 06 '09 at 2:29
source share

Good for developing applications in PHP, I use CodeIgniter, which handles the processing of several language files. It is very powerful and easy to use.

Here is a link to their Language Class

+1
Jul 06 '09 at 1:59
source share

For translations, you can use the framework or just collapse your own library. You can store translations in csv files and use PHP fgetcsv () to parse it. CSV files can be edited using any spreadsheet application.

For example, you can see the Zend_Translate code (part of the Zend Framework). Easy to follow.

+1
Jul 06 '09 at 7:27
source share

Associated with the use of the mb_ * feature set, while maintaining compatibility, see the mb_string.overload php.ini directive,

This will allow you to use regular string functions that have been overloaded with multibyte included.

+1
Jul 6 '09 at 8:35
source share



All Articles