how to change the lang=" " dynamically for multi-language sites

Permalink 1 user found helpful
I'm having number of multi-language sites, for that i need different languages which should be place in <html lang=' '>. It should be achieved without plugin. Through php hardcode i need. Can anyone please tell me how I could make this work?

 
CMSDeveloper replied on at Permalink Best Answer Reply
CMSDeveloper
Hi!

You can use something like this code example:

<?php
 if (strstr($_SERVER['REQUEST_URI'], '/nl/'))
 {
 echo ("<html lang=\"nl\">");
//  echo ("Hello NL");
 }
  if (strstr($_SERVER['REQUEST_URI'], '/en/'))
 {
 echo ("<html lang=\"en\">");
//  echo ("Hello EN");
 }
 ?>
raju replied on at Permalink Reply
Sorry, I'm not good at php. can u please be more specific?
raju replied on at Permalink Reply
I got the answer...
$current_domain = $_SERVER['SERVER_NAME'];
$Meta='{
  "example.com": "en_us",
  "example.es": "es",
  "example.com.br": "br",
  "example.nl":"nl"
}';
$domains = json_decode($Meta, true);
$lang = null;
foreach ($domains as $k => $v) {
  if ($k == $current_domain) {
     $lang = $v;
     break;
  }
}
wyso replied on at Permalink Reply
wyso
Here is my approach. It makes my root to be "pl" if it's not under "/en/":
<?php
 if (strstr($_SERVER['REQUEST_URI'], '/en/'))
 {
 echo ("<html lang=\"en\">");
 }
 elseif (strstr($_SERVER['REQUEST_URI'], '/'))
 {
 echo ("<html lang=\"pl\">");
 }
 ?>

Cheers.