OsCommerce installation and Multilanguage support

Install OsCommerce in cPanel is a piece of cake. However, only several western languages are shipped with the release package. Once install some eastern language package, such as Chinese, one my encounter character display problem. The source pack uses iso-8859-1 (latin1) charset while connecting to the database, which is compatible with all the western languages. The Chinese language pack on the official site is in GB2321 encoding, and it is quite old, developed in 2006. In addition, the database itself also uses some encoding method, which is utf8 in my case. Therefore, three charsets are used by the source, the language pack and the database. God! You must be extremely lucky if you have no trouble with these.

In fact this problem is not unique only for oscommerce, but also for many other scripts developed by western people. I have to appreciate their hard work on the nice scripts, but I must say sometimes they ignore a huge amount of people living in a place called Asia.

To solve this problem is quite simple in concept. The only thing we have to do is to unify all those encoding methods. The best choice nowadays seems to be utf8. So for my database, there is nothing to do. Then I tried to hack a little the oscommerce source. Specifically, I had to modify two places after the installation in cPanel. One is the database.php under “install_dir/includes/functions/”, the other is the database.php under “/install_dir/admin/includes/functions/”. For both files I found the line “if ($$link) mysql_select_db($database);”, and added a new line “mysql_query(“SET NAMES ‘utf8′”,$$link);” above it. This is to tell the script to use “utf8 language” to communicate the database. The final step is the language pack, which is a real trouble. Because it’s not just a problem with the encoding, but also the missing files. Since oscommerce was kept developing, but not the language packs. If you check the official repository, you will find many lang-packs are really old. I have to wonder if there are may people using osc in some countries. Worse, the old lang-packs miss some php files, which were added after the translation. These files are really important, such as the payment scripts, and they are used when you submit an order. To be frank I think this is a design flaw of oscommerce. The authors really should separate the theme or language from the work-horse code. I then make a copy of the English lang-pack from the source into the Chinese language folder, this will remedy the missing files in the Chinese pack. Then open the Chinese.php and modify the line “define(‘CHARSET’, ‘GB2321′);” to define(‘CHARSET’, ‘utf8′);. This step is also critical, because it force the script to set the correct charset for the viewers. This has to be done at two places: the root/includes/languages and the /admin/inlcudes/laguages/. So far we fix all the encoding problems, with a missing translation as payback. This could be done easily, simply translation the strings in the english lang-pack and save all files using “utf8″ encoding with a text editor!!!!

Test the site, listing, searching, backoffice should all work fine for Chinese. And when you view the frontend, the browser will switch to utf8 automatically. Hard work being accomplished! Cheers!

Share this:
Facebook Linkedin Twitter Digg Email

One Comment

  1. 9rivers says:

    Note: some operation is needed for the database also. Using PhpMyAdmin, export the database as a sql file(adding drop table commands). Then use text editor such as notepad++ to replace all “latin1″ to “utf8″. Import this modifile sql file to your database by PhpMyAdmin. This will change all the text field to use utf8 collation and encoding method.

    ps: Zen cart is a fork of Oscommerce, you can do the similar things:
    You can also make your existing cart UTF-8 compatible by:
    1) Making the above changes in the 2 files (english.php [In /includes/languages/ and /admin/includes/languages]and query_factory.php[In /includes/classes/db/mysql/query_factory.php])
    2) Converting your whole table, field by field and table by table to UTF-8 collation

Leave a Reply