Re: Multiple language support design question
| From: | Neil Freeman | Date: | Mon, 07 Apr 2003 13:15:38 +0000 |
| Subject: | Re: Multiple language support design question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-142692@lists.php.net to get a copy of this message | ||
That's great - thanks for the info Don.
Neil
Don Read wrote:
******************************************************************************* This Message Was Virus Checked With : SAVI 3.66 February 2003 Last Updated 7th April 2003 ******************************************************************************* On 07-Apr-2003 Neil Freeman wrote:-- ---------------------- www.curvedvision.com ----------------------Hi, Possibly slightly off-topic but I hope someone can help. I am trying to>implement a multi-lingual site using PHP and MySQL but am not sure ifthere is a recommended method of implementing this. I wish the user to be able to select their language and then have the rest of the site presented in their preferred language. Would you recommend storing the language specific strings in the database, xml, flat files? The content of the pages will be dynamic therefore any of these could be used I suppose.I use a database. mysql> desc nls; +--------+---------------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------+---------------------+------+-----+---------+-------+| catid | varchar(32) | | PRI | | | | lang | varchar(5) | | PRI | en | | | strid | varchar(127) binary | | PRI | | | | strval | tinyblob | YES | | NULL | |+--------+---------------------+------+-----+---------+-------+ The lang field is the ISO lang_dialect notation. So locale de_DE.DIS_8859-15 => 'de_DE', and de_CH.ISO_8859-2 => 'de_CH', etc.mysql> select * from nls where strid ='History'; +-------+------+---------+------------+ | catid | lang | strid | strval |+-------+------+---------+------------+| | de | History | Geschichte | | | en | History | History | | | sv | History | Historia | | | es | History | Historia | | | pl | History | Historia | | | it | History | Storia |+-------+------+---------+------------+ 6 rows in set (0.01 sec) mysql> select * from nls where strid ='Statistics for'; +-------+------+----------------+------------------------+| catid | lang | strid | strval |+-------+------+----------------+------------------------+| fp | de | Statistics for | Stand vom %s | | fp | en | Statistics for | Statistics for %s | | fp | sv | Statistics for | Statistik för %s | | fp | fr | Statistics for | Statistiques pour %s | | fp | es | Statistics for | Estadística para el %s | | fp | pl | Statistics for | statystyki dla %s | | fp | it | Statistics for | Statistiche per %s |+-------+------+----------------+------------------------+ 7 rows in set (0.01 sec) At the start of each page it populates an array with the strings: $_nlsary[$strid]=$strval; The select order is 'en', $lang, $lang_$dialect all in one select. This ensures the array is filled with English as default, then over writtenw ith the "base" language string, and then maybe with a differing dialect: mysql> SELECT lang,strid,strval, IF(lang='en', 0, IF(lang='de',1,2)) as sort-> from nls where lang in ('en','de','de_CH') AND strid='Fee' -> order by sort;+-------+-------+--------------+------+| lang | strid | strval | sort |+-------+-------+--------------+------+| en | Fee | Fee | 0 | | de | Fee | Gebühr | 1 | | de_CH | Fee | Betriebskost | 2 |+-------+-------+--------------+------+ function nls($skey) {global $_nlsary;if ( isset($_nlsary[$skey]) ) return($_nlsary[$skey]); return($skey);} Will get the (translated) strings back. Also you might want to do; setlocale(LC_TIME, $locale); then use strftime() for your date formatting. Regards,