I am stuck in a rut here. When browsing through a translated version of my localized site, the translation randomly stops, and I have no idea why; I'm not sure if it has to do with the way I'm setting the Locale or what, but it randomly stops translating and reverts back to english. Once it does that, the only way to get it back is to go to the home page, highlight the URL in the address bar and press enter.
I'm hoping someone could have a look at the way I'm setting the locale in PHP and seeing if there's something I'm missing or screwing up.
<?php
explode(";", setlocale(LC_ALL, 0));
$pageURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
if (strpos($pageURL,'es.') !== false) {
$language = 'es_ES.utf8';
}
elseif (strpos($pageURL,'it.') == true) {
explode(";", setlocale(LC_ALL, 0));
$language = 'it_IT.utf8';
}
elseif (strpos($pageURL,'de.') == true) {
explode(";", setlocale(LC_ALL, 0));
$language = 'de_DE.utf8';
}
elseif (strpos($pageURL,'pt.') == true) {
explode(";", setlocale(LC_ALL, 0));
$language = 'pt_PT.utf8';
}
elseif (strpos($pageURL,'fr.') == true) {
explode(";", setlocale(LC_ALL, 0));
$language = 'fr_FR.utf8';
}
else {
explode(";", setlocale(LC_ALL, 0));
$language = 'en_US.utf8';
}
putenv("LANG=" . $language);
explode(";", setlocale(LC_ALL, 0));
setlocale(LC_ALL, $language);
// Set the text domain as "messages"
$domain = "messages";
bindtextdomain($domain, "Locale");
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
?>
If any of you have any ideas as to why gettext randomly stops working, please let me know. Also please let me know if there's a snippet of code elsewhere that you'd need to see in order to address the issue. I really appreciate it!