note 111311 added to function.gettext

From: Date: Tue, 05 Feb 2013 11:59:33 +0000
Subject: note 111311 added to function.gettext
Groups: php.notes 
Request: Send a blank email to php-notes+get-193531@lists.php.net to get a copy of this message
Just a quick note on locale names, since I just spent 2 days wondering why gettext did not translate anything: I configured the interesting locales on a debian 6 system, where I basically enabled the utf8 variants like ca_ES.utf8, es_ES.utf8, ... with dpkg-reconfigure locales Then, I tried setting the locale from the browsers accepted languages by $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); which yields for example "es_ES". Well, I am not interested in ISO-8859-1 output, so es_ES was not installed since it apparently is based on ISO-8859-1 and the recommendation is to install UTF-8 based locales only for new systems. Therefore setLocale(LC_MESSAGES, $locale) did not set a valid system locale in this case and so gettext still used system default locale. It did not help in any way that I kept the spanish messages in a generic language folder $localedir/es/LC_MESSAGES for all spanish variants. A quick workaround was to do the following: $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); $lang = Locale::getPrimaryLanguage($locale); $region = Locale::getRegion($locale); $locale = $lang . '_' . $region . '.utf8'; Locale::setDefault($locale); setlocale(LC_ALL, $locale); setlocale(LC_MESSAGES, $locale); Of course, checks for empty values have to be added. ---- Server IP: 69.147.83.199 Probable Submitter: 62.57.67.2 ---- Manual Page -- http://php.net/manual/en/function.gettext.php Edit -- https://master.php.net/note/edit/111311 Del: integrated -- https://master.php.net/note/delete/111311/integrated Del: useless -- https://master.php.net/note/delete/111311/useless Del: bad code -- https://master.php.net/note/delete/111311/bad+code Del: spam -- https://master.php.net/note/delete/111311/spam Del: non-english -- https://master.php.net/note/delete/111311/non-english Del: in docs -- https://master.php.net/note/delete/111311/in+docs Del: other reasons-- https://master.php.net/note/delete/111311 Reject -- https://master.php.net/note/reject/111311 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193531) next »