ZF-2300: System locale "de_DE@euro is not deceted


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


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:

  • OS
  • php version
  • zf revision
  • testcode for reproduction
  • output from testcode
  • called from where
  • output of setlocale()

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

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...

echo setlocale(LC_ALL, 0);

Please provide information about from where you are calling the script...

Browser, Commandline, ....

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.

I reported this issue because it worked on ZF 1.0.2, and I do not see why it should stop working now.

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

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:

// Bootstrap
try {
    $locale = new Zend_Locale();
} catch (Zend_Locale_Exception $e) {
    $locale = new Zend_Locale('de'); // or whatever your standard locale is if no one can be detected...

// Code
$date = new Zend_Date($locale);

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 ?

// for example
setlocale(LC_CTYPE, 'de_DE@euro');
echo "'" . setlocale(LC_ALL, 0) . "'";

I will add an patched locale file for tests on your systems.

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.

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'

That does not work for me. I get results like "e_DE" instead of "de_DE", because you substr() from 1 instead from 0

"I get results" = locale name is detected as that

Sorry... typo See SVN-7202

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); }}

Any why am I getting this information now and not before as I requested it ???

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

No response since 9 days. Seems to work now.