Reputation: 1128
What would be a scalable and low resource solution to apply multi-language in my PHP website? Also how would you guys integrate it with javascript, some javascript also requires translations.
My current solution is just:
define('DEFAULT_LANGUAGE', 'en');
if(!isset($_SESSION['language'])){
$_SESSION['language'] = DEFAULT_LANGUAGE;
}
function lang($key, $set = null){
static $lang;
if($set !== null){
$lang = $set;
return true;
}
return $lang[$key];
}
include('language/' . $_SESSION['language'] . '.php');
lang(null, $lang);
My doubts to this solution: if the array in the file, is pretty big, 1000+ elements, and we pass it in the function, set the language array, it's doubled in memory right, because we are not passing by reference?
Thanks for reading.
Upvotes: 0
Views: 308
Reputation: 132051
unset($lang)
Upvotes: 1