Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Function that changes the language of my site based on http_accept_language

Posted on 2008-11-18
3
Medium Priority
?
198 Views
Last Modified: 2012-05-05
Hi

My website is displayable in 2 languages, English and dutch, and I want to show the dutch language if the http_accept_language is present and set to dutch [nl-NL?], the attached code is my first attempt to do so, can someone improve this pls, it should display English in every other case if the http_accept_language is not set to dutch, or, do you know a better way to do this in php?
function ChangeLang(){
 
$Dutch = 'nl';
$Nl = 'lang/dutch.lang';
$En = 'lang/english.lang';
  if (strstr($_SERVER['HTTP_ACCEPT_LANGUAGE'],$Dutch)){
  	  include($Nl);
  }
     else {
 
    include($En);
 }
}

Open in new window

0
Comment
Question by:PeterdeB
  • 2
3 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 22985822
That code looks fine to me.  This is what my server presents:

_ENV["HTTP_ACCEPT_LANGUAGE"] = en-us,en;q=0.5

Be aware of variable scope since you are including these lang modules inside a function.

Best regards, ~Ray
0
 

Author Comment

by:PeterdeB
ID: 22985910
Ok thank you very much, I already had taken notice of the variable scope but thanks again
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22985953
Thanks for the points, and good luck with your project! ~Ray
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question