setlocale() throws CI_Controller class not found error
When setlocale(LC_ALL, 'tr_TR.UTF-8') is used "Fatal error: Class ‘CI_Controller’ not found in /var/www/xxx/htdocs/ci_system/core/CodeIgniter.php on line xxx" error is thrown. It is not tried for other languages than turkish.
This happened to me too when implementing Turkish gettext. The issue is actually in LC_CTYPE, and we went around it like this:
if (get_setting('fs_gen_lang'))
{
$locale = get_setting('fs_gen_lang');
putenv("LANG=$locale");
if ($locale != "tr_TR.utf8")
{
setlocale(LC_ALL, $locale);
}
else // workaround to make turkish work with FoOlSlide
{
setlocale(LC_COLLATE, $locale);
setlocale(LC_MONETARY, $locale);
setlocale(LC_NUMERIC, $locale);
setlocale(LC_TIME, $locale);
setlocale(LC_MESSAGES, $locale);
setlocale(LC_CTYPE, "sk_SK.utf8");
}
bindtextdomain("default", FCPATH . "assets/locale");
textdomain("default");
}
I couldn't track down the cause of the issue further than this. The above solution makes my gettext work fine though.
LC_CTYPE for character classification and conversion, for example strtoupper() http://www.php.net/manual/en/function.setlocale.php
It may be a cause of the error, but where?
I track down the error and found this "if (strtolower($direction) == 'random')" on the first line of order_by method in DB_active_rec.php. But the issue happens on server, not local. PHP versions are the same(5.2.17). And also I found this: ' It is important to note that setlocale() will silently fail if it can't find the specified locale on your system, so always check its return value' on http://php.net/manual/en/function.strtoupper.php. It looks like it is not a codeigniter issue. Thanks all for help.