ZF-2300: System locale "de_DE@euro is not deceted
Description
Our system has the locale "de_DE@euro". This is not recognized by Zend_Locale, causing most classes using it to error out. Worked with 1.0.2
Our system has the locale "de_DE@euro". This is not recognized by Zend_Locale, causing most classes using it to error out. Worked with 1.0.2
Comments
Posted by Thomas Weidner (thomas) on 2007-12-12T13:01:03.000+0000
This is much too less information for reproduction...
Also to mention: "de_DE@euro" is no supported locale... locale can eighter have language or language and region. But it should defer to "de" and if no locale can be found an exception should be raised. There is no way to "just error out" !!
Please add the following informations for reproduction:
Posted by Christian Weiske (cweiske) on 2007-12-12T13:34:08.000+0000
I am using CentOS (Redhat Linux) with PHP 5.2.5 and Zend Framework 1.0.3. de_DE@euro is a valid locale that many linux distributions ship.
The code: <?php require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); echo ':' . setlocale(LC_ALL, 'de_DE@euro') . ':'; $loc = new Zend_Locale(); ?>
Output: cweiske:~/Dev/cvs> LANG=de_DE@euro php zend-locale.php :: Fatal error: Uncaught exception 'Zend_Locale_Exception' with message 'Autodetection of Locale has been failed!' in /home/cweiske/Dev/cvs/pear/instpear/share/pear/Zend/Locale.php:122 Stack trace:
0 /home/cweiske/Dev/cvs/zend-locale.php(5): Zend_Locale->__construct()
1 {main}
thrown in /home/cweiske/Dev/cvs/pear/instpear/share/pear/Zend/Locale.php on line 122
Posted by Thomas Weidner (thomas) on 2007-12-12T14:52:34.000+0000
So it does not "just error out"... it returns that the locale can not be detected... this seems to be a normal behaviour, and you are not handling this exception properly.
Please provide output of "setlocale()"... don't set a own locale per hand...
Please provide information about from where you are calling the script...
Browser, Commandline, ....
Posted by Christian Weiske (cweiske) on 2007-12-12T15:24:41.000+0000
The call of "LANG=de_DE@euro php ..." was an example because on my laptop I do not use it as default locale. On our server, we get "de_DE@euro" as output of setlocale() when using from cmdline. I'll check out what we get with a browser tomorrow.
Posted by Christian Weiske (cweiske) on 2007-12-12T15:27:36.000+0000
I reported this issue because it worked on ZF 1.0.2, and I do not see why it should stop working now.
Posted by Marc Bennewitz (GIATA mbH) (mben) on 2007-12-13T04:00:43.000+0000
Hi I have the same problem. If I start my script with an cronjob, ZF can't detact the environment locale: setlocale(LC_ALL, 0) -> return "C" on SuSE10.3
Than I would like to set the locale manuelly to de_DE@euro or de_DE.UTF-8 but ZF can't detact the locale setlocale(LC_ALL, 'de_DE@euro') new Zend_Locale(Zend_Locale::ENVIRONMENT); -> Autodetection of Locale has been failed!
setlocale(LC_ALL, 'de_DE.UTF-8') new Zend_Locale(Zend_Locale::ENVIRONMENT); -> Autodetection of Locale has been failed!
setlocale(LC_CTYPE, 'de_DE@euro') new Zend_Locale(Zend_Locale::ENVIRONMENT); -> Autodetection of Locale has been failed!
setlocale(LC_CTYPE, 'de_DE.UTF-8') new Zend_Locale(Zend_Locale::ENVIRONMENT); -> THIS WORK
Posted by Thomas Weidner (thomas) on 2007-12-14T02:42:20.000+0000
Beside the problem itself, you can handle this situation with the following code instead of just throwing an exception which is displayed to the user:
Because when the browser does not send an language and the servers language can also not detected you will always get an exception.
And related to "C"... this means that the locale is set somewhere else in your OS and php is not able to detect it. In this case you will always have to set a locale per hand.
Mark: Can you get me the output after you set the locale for all your tests ?
I will add an patched locale file for tests on your systems.
Posted by Thomas Weidner (thomas) on 2007-12-15T16:12:09.000+0000
Please verify SVN-7144. I added support for properitary unix locales adding charsets.
Still this one 'setlocale(LC_ALL, 'de_DE.UTF-8');' should have been worked before. If there is really a problem I still need the output as written before and not the output of a set locale.
Without this I will not be able to fix the problem.
Posted by Thomas Weidner (thomas) on 2007-12-17T15:20:18.000+0000
If I get no response until 23.December I will close this issue as fixed. For undetectable locales use setDefault() (ZF-2310). 'de_DE@UTF-8' should not be detectable and degrade to 'de_DE'
Posted by Christian Weiske (cweiske) on 2007-12-19T06:08:59.000+0000
That does not work for me. I get results like "e_DE" instead of "de_DE", because you substr() from 1 instead from 0
Posted by Christian Weiske (cweiske) on 2007-12-19T06:09:48.000+0000
"I get results" = locale name is detected as that
Posted by Thomas Weidner (thomas) on 2007-12-19T07:39:32.000+0000
Sorry... typo See SVN-7202
Posted by Christian Weiske (cweiske) on 2007-12-20T04:13:38.000+0000
Ok. Getting to the source of the problem. There are two types of arrays that setlocale() returns: {{array(12) { [0]=> string(20) "LC_CTYPE=de_DE@euro" [1]=> string(12) "LC_NUMERIC=C" [2]=> string(9) "LC_TIME=C" [3]=> string(12) "LC_COLLATE=C" [4]=> string(13) "LC_MONETARY=C" [5]=> string(13) "LC_MESSAGES=C" [6]=> string(10) "LC_PAPER=C" [7]=> string(9) "LC_NAME=C" [8]=> string(12) "LC_ADDRESS=C" [9]=> string(14) "LC_TELEPHONE=C" [10]=> string(16) "LC_MEASUREMENT=C" [11]=> string(19) "LC_IDENTIFICATION=C" } }}
the other one is: {{array(1) { [0]=> string(10) "de_DE@euro" } }}
this means that sometimes an '=' is prefixed, and sometimes not - the confusion about the substr problem has its source here.
I suggest the following that works on all of my systems:
{{ if ($language != '=C') { if ($language[0] == '=') { $language = substr($language, 1); } if (strpos($language, '.') !== false) { $language = substr($language, 0, strpos($language, '.')); } else if (strpos($language, '@') !== false) { $language = substr($language, 0, strpos($language, '@')); } $splitted = explode('_', $language); }}
Posted by Thomas Weidner (thomas) on 2007-12-20T06:09:37.000+0000
Any why am I getting this information now and not before as I requested it ???
Posted by Thomas Weidner (thomas) on 2007-12-20T06:19:51.000+0000
Your code has problems when LC_ALL returns "C" alone like your de_DE@xxx comes alone which is not possible in *nix systems.
LC_ALL should always return a collection of all LC_x avaiable... even if they are set to the same.
Try SVN-7213
Posted by Thomas Weidner (thomas) on 2007-12-29T04:03:22.000+0000
No response since 9 days. Seems to work now.