I create a multilingual website and I am wondering how to get the language data. Well, my code gets information about the user's language from the browser, then include the locale file.
get user language:
<?php
$hl = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
?>
include locale:
<?php
if (file_exists('locales/".$hl.".php')){
include "locales/".$hl.".php";
}else{
include "locales/en.php";
}
/* VS */
switch ($hl){
case 'de': include "locales/de.php"; break;
case 'fr': include "locales/fr.php"; break;
/* ...*/
default: include "locales/en.php";
}
?>
Which way is the best?