phpScheduleIt
May 21, 2013, 12:27:26 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Subtle bug in language selection functions caused by regexps  (Read 1844 times)
Zanchey
Newbie
*

Karma: 0
Posts: 5


« on: December 27, 2007, 01:17:37 AM »

During deployment of phpScheduleIt here in Perth, Australia, I've noticed what I think is a subtle bug in the language selection functions in config/lang.php due to the ordering of regular expressions.

We need to have the en_GB locale set as default for all users as this affects the display of dates, so I set the defaultLanguage configuration option to 'en_GB'. However, the get_browser_lang() function consistently returns en_US as the language.  Our browsers are sending en-au as their HTTP_ACCEPT_LANGUAGE.

Preliminary investigation showed that this was due to the regular expressions used to match the various English locales. The regexp for en_US is
Code:
en([-_]us)?|english

This matches en-us, en_us, en... and en-au.

Because en-us sits higher in the $languages array, a HTTP_ACCEPT_LANGUAGE header of 'en-gb' will always match against en_US before being checked against en_GB.

My suggestion is to alter the regular expressions for en_GB and en_US (and probably the others, for consistency) to something like:
Code:
'en_US' => array('^(en([-_]us)?|english)$', 'en_US.lang.php', 'en', 'English US'),
'en_GB' => array('^en[-_]gb$', 'en_GB.lang.php', 'en', 'English GB'),


This means that the en_US regex matches on 'en' and 'en-us', but not 'en-gb' or 'en-au'. This also removes the overlap between en_US and en_GB for the 'english' and 'en' codes.
Logged
Zanchey
Newbie
*

Karma: 0
Posts: 5


« Reply #1 on: December 27, 2007, 02:18:39 AM »

Whoops - forgot a couple of details. The regex change was required in 1.2.8. I am using PHP 5.2.5 running in ISAPI mode on IIS 6.0, on Windows Server 2003.
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5419


WWW
« Reply #2 on: December 28, 2007, 02:26:30 PM »

Thanks, I'll make this change.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!