[Phpsniff-devel] Browser HTTP_ACCEPT_LANGUAGE
Brought to you by:
epsilon7
From: Dave G. <php...@gu...> - 2003-01-22 19:33:01
|
Hi, This is my first email to this list (in fact it may be the first email _ever_ to this list!) so hello to Roger Raymond (epsilon7 @ SF) and hello to everyone else! I am aware of the forums at http://sourceforge.net/projects/phpsniff/ but I _much_ prefer email to the small textarea boxes on the forums :-) Firstly let me introduce myself. My name is Dave Guerin (daveguerin @ SF) and I am one of the developers of the web content management system called Pagetool http://www.pagetool.org/ http://sourceforge.net/projects/pagetool We currently use phpSniff in the generation of a browser specific style sheet for a Pagetool site. Thank you very much for all your work on the class Roger! We have attempted to make Pagetool multi lingual, include()ing specific language files depending on the HTTP_ACCEPT_LANGUAGE set by the browser. Currently we use the following function to return the name of the file to be included: function pt_accept_language() { global $ptconf, $HTTP_ACCEPT_LANGUAGE; /* $lang set to the default value of 'en'. If no other language is available this language file will be returned. */ $lang =3D 'en'; if (isset($HTTP_ACCEPT_LANGUAGE)) { if (file_exists("src/lang/pt_lang_".substr($HTTP_ACCEPT_LANGUAGE,0,2).".inc" )) { $lang =3D substr($HTTP_ACCEPT_LANGUAGE,0,2); } } return("src/lang/pt_lang_". $lang . ".inc"); } This works fine for the first preferred language the user has set. However if the HTTP_ACCEPT_LANGUAGE is nn-no,es-pr;q=3D0.8,sv;q=3D0.7,zh-hk;q=3D0.5,en;q=3D0.3,en-gb;q=3D0.2 for example (that's Norwegian (Nynorsk), Spanish (Puerto Rico), Swedish, Chinese (Hong Kong SAR), English, and English (United Kingdom) and no I don't speak all of those) then English is included as the default language, and then Norwegian will be included if it exists. If it doesn't exists, that's it. Even if Spanish is available the user will only get English :-( Also, another problem is the various values returned by different browsers: IE6 SP1 Norwegian (Nynorsk) nn-no Norwegian (Bokm=E5l) no Norwegian (Bokm=E5l) nb-no Opera 6.01 Norwegian (Nynorsk) no-nyn Norwegian (Nynorsk) nn Norwegian (Bokm=E5l) nb Norwegian (Bokm=E5l) no-bok Norwegian no Mozilla 1.0 Norwegian (Nynorsk) nn Norwegian no Norwegian (Bokm=E5l) nb And no I don't speak any form of Norwegian, a Pagetool user contributed a language file in Norwegian (Nynorsk) and I was at a loss as to how to deal with it. It's not as easy as a plain old English language include(). I know phpSniff has a $client->language_is(language) function but this doesn't deal with the variation in browser values for the same language, or with the addition of dialects to a basic language like en-gb or en-us. I was wondering if phpSniff was to be extended in any way to assist in dealing with these problems. I more than willing to help in any way I can with coding but I'm not sure currently quite which way is the best way forward. I look forward to any comments and ideas people on this list may have. --=20 Cheers, d a v e |