Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.11.4

Bug #3494 I18Nv2's modifies the global locale
Submitted: 2005-02-16 16:30 UTC
From: ojai at nerim dot net Assigned:
Status: No Feedback Package: I18Nv2
PHP Version: 4.3.10 OS: Linux Debian
Roadmaps: (Not assigned)    
Subscription  


 [2005-02-16 16:30 UTC] ojai at nerim dot net
Description: ------------ Hi, I'm using I18Nv2-0.11.0 to format some dates. The problem is that it calls setlocale() so that all of my output is affected. This behaviour breaks my app, and is very intrusive to me. OO is about encapsulating, not changing global settings like this. What I need is I18Nv2 to format my date, and nothing more, nothing less. Please let the locale as it is. I guess you'll have to restore it after changing it everytime, but that's a necessary overhead to me. Reproduce code: --------------- function makeDate ($timestamp,$lang) { $localeStr = $lang . '_' . strtoupper ($lang); $locale = &I18Nv2::createLocale($localeStr); $date_str = $locale->formatDate($timestamp, I18Nv2_DATETIME_FULL); return $date_str; } printf('%2.f',10); // prints 10.00 (dot) echo makeDate(time(),'de'); // shows the date correctly printf('%2.f',10); // prints 10,00 (comma)

Comments

 [2005-02-21 10:59 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2005-02-21 12:18 UTC] ojai at nerim dot net
I'm aware of the %F directive, but it is very recent : since php 4.3.10. That is a problem for me. The real problem is that most of the code out there that use sprintf() to format numbers rely on %f. For example by altering the locale, I18Nv2 breaks the FPDF library (http://www.fpdf.org). I couldn't enumerate all libraries and applications that would break because of this issue, but, for portability, these are likely not to require php 4.3.10 before a while. Additionally, changing the locale may modify the behaviour of such methods as preg_match() and uasort().
 [2005-02-21 13:45 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2005-02-21 15:43 UTC] ojai at nerim dot net
Yep, it works :-) Two small typos, though : - in I18Nv2::createLocale() your forget to pass the $paranoid parameter to the Locale constructor - in I18Nv2_Locale, on line 734, you typed "paramoid" instead of "paranoid" ;-) So, I don't know if I'm paranoid or paramoid, but I do have a patch, that tries to improve your idea. The problem with resetting to the C locale is that it is still intrusive : it ends up altering the locale. Instead of resetting the locale, I try to restore it. I can't test that on Windows, but it works fine on my Linux system : http://samalyse.com/ln/0014.php
 [2005-03-22 15:30 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2005-06-17 11:21 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!