Reputation: 11
I'm trying to set the pt_BR locale in my application.
But, for some reason, my number format configuration is still in the wrong format.
I tried to set the correct locale in so many ways:
setlocale(LC_ALL, 'pt_BR');
setlocale(LC_ALL, 'pt_BR.utf-8', 'pt_BR', 'portuguese', 'pt-br');
setlocale(LC_ALL, 'pt_BR.utf-8');
setlocale(LC_ALL, 'portuguese');
But, for all of them, I have the decimal_point with a dot. The correct value for this, in portuguese, is a comma. It's all the same result:
array (size=18)
'decimal_point' => string '.' (length=1)
'thousands_sep' => string '' (length=0)
'int_curr_symbol' => string '' (length=0)
'currency_symbol' => string '' (length=0)
'mon_decimal_point' => string '' (length=0)
'mon_thousands_sep' => string '' (length=0)
'positive_sign' => string '' (length=0)
'negative_sign' => string '' (length=0)
'int_frac_digits' => int 127
'frac_digits' => int 127
'p_cs_precedes' => int 127
'p_sep_by_space' => int 127
'n_cs_precedes' => int 127
'n_sep_by_space' => int 127
'p_sign_posn' => int 127
'n_sign_posn' => int 127
'grouping' =>
array (size=0)
empty
'mon_grouping' =>
array (size=0)
empty
This happens in my local environment and some other Windows computers that I tested. But in some another Windows it works. All computers running Windows 7. I also tested in a UNIX environment and works well. The problem is just for some Windows installations.
The locale exist but is wrong for some reason.
Someone has an idea to help me? I'd like to understand why this is happening.
Thanks
Upvotes: 1
Views: 788
Reputation: 4661
Windows and unixes use different locale codes. Also some locales may not be installed on a system. This makes setlocale
function not easily portable.
Manual for setlocale warns about possible failure reasons:
Returns the new current locale, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.
You should check the return value and try a workaround in case the locale is not available.
Update
Regarding your issue, when setlocale
call succeeds but has no effect on regional settings, I found this bug report with won't-fix
status. In the bug comments the function is generally described as unpredictable. One of the possible reasons of failure is that it is not thread safe. There is also another similar bug report marked as duplicate. Interesting that both reporters list Windows 7
as their platform.
Upvotes: 1