Multi-language support with PHP

If you aim to create a multi-language website using PHP + Mysql , remember the following tips.
- You can use mysql database for this purpose rather than using separate language files as usual content management system does.
- You can create a table with following structure for this purpose.Table: muli-lang
string_id:
page_id:
en:
arb:
fr: - Here string_id is the code for getting content eg: welcome_message
page_id is for saving in which page the content belongs to. eg: home_page, login_page etc
In field en, you have to enter the message in english,eg: Welcome to my website
In arb field you can enter the corresponding translation in arab. eg: مرحبا بكم في موقعي - If you need to add more languages, it is just adding one more column to this table and put all translated values.
- Write a class or functions in PHP to retrieve all the informations.
eg: function get(language_id, page_id) returns corresponding message - Use session to save lang value. For example if you switch to french, set a variable lang= fr and use this variable to decide which column is to access from multi-lang table.eg: the sql will be , SELECT $lang FROM multi-lang WHERE string_id = ‘welcome_message’
- For some string fragment like about_us, contact_us etc, it has global scope; then leave page_id as blank
- To avoid multiple calling of functions to get translation, write a common function to get all translation for a particular page_id as array, and use this array all through the page. Thus you can avoid mysql query multiple times.
eg: function get_all($page_id) returns array, say $Translate of all strings replacement. $Translate['login_message'], $Translate['login_error'] - Additional things to remember:
- Use this meta tab in html header
<meta http-equiv=”Content-Type” content=”text /html; charset=UTF-8” />
to show all languages - Create my_sql table in UTF-8 format
- Execute the following query before executing any retrieval queries. Otherwise you may get ????? for language like Arabic, Hindi, Chinese etc.
mysql_query(“SET CHARACTER SET ‘utf8′”, $link);
I hope these information may help you when you develop a multi-langauge support website
Thank you
Sajith


I am learning the PHP right now,and it is useful to me,thank you very much.
is there any pluggins in fire fox for language conversion
Yes, there is a plugin for this:
https://addons.mozilla.org/en-US/firefox/addon/918/
Actually this is not multi language support in PHP. Because it is depends on browsers and mysql. This will mislead people who searching for PHP will support multi language or not? Actually core PHP won’t. You can’t do string manipulations over other languages easily. PHP 6 is going to support it.
ΑÎΑΣΤΑΣΙΟΣ type of output comes, Do u ve ne suggestion fr this?
Hi Sajith..I am looking for a programmer to do some customization work on a Groupon Clone script, if you interested, please email me at the above address. Thanks!
The following link has an excellent explanation of how to enable Arabic, Urdu and other foreign language support in PHP/MySQL.
addr.pk/a44d
OR
phphelp.co/2012/03/30/how-to-make-php-and-mysql-support-arabic-urdu-and-charactersets-or-other-foreign-languages/
Sajith, Thanks for such a detailed explanation. I was just wondering if you can provide an example in a zipped form to play with the code. I am not so good in PHP and I find this a little difficult to put into a real life application.
Thanks for giving directions.