Best Practices for Browser Language Detection

RussianRoot 13/07/2012 0
Best Practices for Browser Language Detection

Hello World!

I would like to share my experience how to detect browser language and include the right file that contents language variables.

I have created a simple echo of $server array with key “HTTP_ACCEPT_LANGUAGE”:

Test Link: http://tests.russianroot.net/language_detection/

And I have recieved this output:

OS: Windows 7

  • Firefox 13.0.1: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
  • Internet Explorer 9: de-DE
  • Opera 12: de-DE,de;q=0.9,en;q=0.8
  • Chrome 20.0.*: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
  • Safari 5.1.5: de-DE

OS: Win XP

  • Internet Explorer 7: de
  • Internet Explorer 8: de
  • Firefox 3.6.23:  de

OS: Debian Lenny

  • Epiphany: de-de, de;q=0.90

OS: Ubuntu

  • Chromium 18.0.*: en-US,en;q=0.8
OS: Android 4.0.3 (Samsung Galaxy S2):
  • Android Browser: de-DE, en-US
* “de” stands for Deutsch (German)

We see that at the beginnig of string we can cut first 2 letters and this is going to be our parameter for php switch.
So i created following script:

To add additional language just copy and paste “case” declaration and replace language snippet with desired one.

Have fun. Feel free to comment and give Feedback.

 

Best regards,
Konstantin Konobeyev.

Leave A Response »


8 × = 56


Warning: require_once(/www/htdocs/w00e1ca9/domainpool/russianroot.net): failed to open stream: No such file or directory in /www/htdocs/w00e1ca9/domainpool/russianroot.net/wp-content/themes/aven/footer.php on line 48

Fatal error: require_once(): Failed opening required '' (include_path='.:/usr/share/php:..') in /www/htdocs/w00e1ca9/domainpool/russianroot.net/wp-content/themes/aven/footer.php on line 48