#41157 [NEW]: nl_langinfo() implementation conflicts with setlocale()

From: Date: Sat, 21 Apr 2007 21:13:27 +0000
Subject: #41157 [NEW]: nl_langinfo() implementation conflicts with setlocale()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111771@lists.php.net to get a copy of this message
From: jo at feuersee dot de Operating system: Linux PHP version: 5.2.1 PHP Bug Type: I18N and L10N related Bug description: nl_langinfo() implementation conflicts with setlocale() Description: ------------ nl_langinfo() seems to expect that the locale has been set in the format ll_CC (ll being the ISO 639-1 language code and CC the ISO 3166-2 country code). All other locales (like only setting a language like 'de' or adding an encoding like 'ja_JP.UTF-8') do result in output which looks like locale 'C'. This leaves nl_langinfo() unuseable, since for languages with multiple possible encodings it is necessary to explicitly set the encoding in setlocale() (eg. to get the strftime() format strings in a useable defined encoding). I compared the PHP results with the plain C API results and the restrictions do not appear in the C version. Thus I say the PHP implementation of nl_langinfo() is buggy. To compare test4 with the C equivalent, here is the code: #include <stdio.h> #include <locale.h> #include <langinfo.h> // char buffer[1024]; char *buffer; int main (void) { buffer = setlocale(LC_ALL, "ja_JP.UTF-8"); printf("Locale: %s\n", buffer); printf("%s\n", nl_langinfo(D_T_FMT)); return(0); } Reproduce code: --------------- (All examples are supposed to be typed into the shell): test1 ~> php -r 'setlocale(LC_ALL, 'C'); printf("%d: %s\n", D_T_FMT, nl_langinfo('D_T_FMT'));' test2 ~> php -r 'setlocale(LC_ALL, 'ja'); printf("%d: %s\n", D_T_FMT, nl_langinfo('D_T_FMT'));' test3 ~> php -r 'setlocale(LC_ALL, 'ja_JP'); printf("%d: %s\n", D_T_FMT, nl_langinfo('D_T_FMT'));' test4> php -r 'setlocale(LC_ALL, 'ja_JP.UTF-8'); printf("%d: %s\n", D_T_FMT, nl_langinfo(D_T_FMT));' Expected result: ---------------- test1: 131112: %a %b %e %H:%M:%S %Y test2: 131112: %a %b %e %H:%M:%S %Y test3: (output of C code) 131112: %Y&#495;%m&#65533;d&#65533; %H%M&#684;%S&#65533; test4: (C code gives propert UTF-8 output) %Y&#24180;%m&#26376;%d&#26085; %H&#26178;%M&#20998;%S&#31186; Actual result: -------------- test1: passed test2: fallback to locale C (passed) test3: (output is in undefined encoding like C code, passed) 131112: %Y&#495;%m&#65533;d&#65533; %H%M&#684;%S&#65533; test4: (fallback to C locale, _not_ passed): 131112: %a %b %e %H:%M:%S %Y -- Edit bug report at http://bugs.php.net/?id=41157&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41157&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41157&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41157&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41157&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41157&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41157&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41157&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41157&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41157&r=support Expected behavior: http://bugs.php.net/fix.php?id=41157&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41157&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41157&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41157&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41157&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41157&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41157&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41157&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41157&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41157&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41157&r=mysqlcfg

« previous php.bugs (#111771) next »