public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin
@ 2023-03-13  0:40 Yeo Kai Wei
  2023-03-13  5:40 ` Brian Inglis
  2023-03-13 10:49 ` Corinna Vinschen
  0 siblings, 2 replies; 7+ messages in thread
From: Yeo Kai Wei @ 2023-03-13  0:40 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1511 bytes --]

Hi All,

May I ask if there's a bug with Cygwin and Windows currency?

This is the output from the code below.

Region: en_AU.utf-8 Currency symbol: $ International currency symbol: AUD
Region: en_CA.utf-8 Currency symbol: $ International currency symbol: CAD
Region: en_GB.utf-8 Currency symbol: £ International currency symbol: GBP
Region: en_US.utf-8 Currency symbol: $ International currency symbol: USD
Region: en_NZ.utf-8 Currency symbol: $ International currency symbol: NZD
Region: en_ZM.utf-8 Currency symbol: $ International currency symbol: 
NZD <---- ERROR

The correct answer should be "Region: en_ZM.utf-8 Currency symbol: K 
International currency symbol: ZMK"

Supposedly, the code works on Linux.

Is this an issue with Windows?

How can one solve this issue?


Thank you very much.


Kind Regards,

YEO Kai Wei


*CODE*

#include <locale.h>

#include <stdio.h>

#include <stdlib.h>

void main()
{
     setlocale(LC_ALL, "");

     char* regions[] = {"en_AU.utf-8",
         "en_CA.utf-8",
         "en_GB.utf-8",
         "en_US.utf-8",
         "en_NZ.utf-8",
         "en_ZM.utf-8",
         NULL};

     int i = 0;

     while (regions[i])
     {
         setlocale(LC_MONETARY, regions[i]);

         const struct lconv* loc = localeconv();

         printf("Region: %s Currency symbol: %s International currency 
symbol: %s\n", regions[i], loc->currency_symbol, loc->int_curr_symbol);

         i++;
     }
}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin
  2023-03-13  0:40 [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin Yeo Kai Wei
@ 2023-03-13  5:40 ` Brian Inglis
  2023-03-13 10:49 ` Corinna Vinschen
  1 sibling, 0 replies; 7+ messages in thread
From: Brian Inglis @ 2023-03-13  5:40 UTC (permalink / raw)
  To: cygwin

On 2023-03-12 18:40, Yeo Kai Wei via Cygwin wrote:
> May I ask if there's a bug with Cygwin and Windows currency?

Windows Language Locale culture codes and currencies

> This is the output from the code below.
> Region: en_AU.utf-8 Currency symbol: $ International currency symbol: AUD
> Region: en_CA.utf-8 Currency symbol: $ International currency symbol: CAD
> Region: en_GB.utf-8 Currency symbol: £ International currency symbol: GBP
> Region: en_US.utf-8 Currency symbol: $ International currency symbol: USD
> Region: en_NZ.utf-8 Currency symbol: $ International currency symbol: NZD
> Region: en_ZM.utf-8 Currency symbol: $ International currency symbol: NZD <---- 
> ERROR
> The correct answer should be "Region: en_ZM.utf-8 Currency symbol: K 
> International currency symbol: ZMK"
                                  ZMW Zambia kwacha

Install Cygwin package units and see /usr/share/units/currencies.units:

$ units_cur
$ grep zambia /usr/share/units/currency.units
ZMW                    zambiakwacha
zambiakwacha              0.049970632087833 USD

> Supposedly, the code works on Linux.
> Is this an issue with Windows?
> How can one solve this issue?
If you look at the Windows Locale culture id ref:

https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f?source=recommendations

https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-LCID/%5bMS-LCID%5d.pdf

only two official languages are supported for Zambia and only since Windows 10:

"...
Language	Location	Language	Language	Supported
		(or type)	ID		tag		version
...
Bemba		Zambia		0x1000		bem-ZM		Release 10
...
English		Zambia		0x1000		en-ZM		Release 10
...
Language	Language
ID		tag
0x1000		Locale without assigned LCID if the current user default locale.
		See section 2.2.1.
...
2.2.1 Locale Names without LCIDs
Every locale name without an assigned LCID MAY be temporarily given one of the 
LCIDs in the following table, if the application requests an LCID.<14> These 
locale names include any valid [RFC5646] language tag.
Note: LCID assignments for Locale Names without LCIDs are temporary and are not 
suitable for use across a protocol, or for interchange between processes or 
machines.
These temporary LCID assignments are also unsuitable for tagging persisted data 
as the meaning of the LCID assignment will change over time.
...
Name				Value	Conditions
LOCALE_CUSTOM_UNSPECIFIED<17>	0x1000	When an LCID is requested for a locale 
without a permanent LCID assignment, nor a temporary assignment as above, the 
protocol will respond with LOCALE_CUSTOM_UNSPECIFIED for all such locales. 
Because this single value is used for numerous possible locale names, it is 
impossible to round trip this locale, even temporarily.
Applications should discard this value as soon as possible and never persist it. 
If the system is forced to respond to a request for LCID_CUSTOM_UNSPECIFIED, it 
will fall back to the current user locale. This is often incorrect but may 
prevent an application or component from failing.
As the meaning of this temporary LCID is unstable, it should never be used for 
interchange or persisted data.
This is a 1-to-many relationship that is very unstable.
..."

So it looks like you can only use this if you set this to the current user 
default locale, or set that up under your own custom locale using one of the 
other termporary assignment ids available, and set the current user default 
locale to that.

Instructions for doing so are available out there on the web if you search hard!

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin
  2023-03-13  0:40 [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin Yeo Kai Wei
  2023-03-13  5:40 ` Brian Inglis
@ 2023-03-13 10:49 ` Corinna Vinschen
  2023-03-14  1:30   ` Yeo Kai Wei
  1 sibling, 1 reply; 7+ messages in thread
From: Corinna Vinschen @ 2023-03-13 10:49 UTC (permalink / raw)
  To: cygwin; +Cc: Yeo Kai Wei

On Mar 13 08:40, Yeo Kai Wei via Cygwin wrote:
> Hi All,
> 
> May I ask if there's a bug with Cygwin and Windows currency?

The en_ZM locale isn't yet supported by Cygwin.  This will change with
Cygwin 3.5.0.  You can install the latest Cygwin test release
3.5.0-0.231.g93f70d7849b8 and retry.  You'll get the correct output:

Region: en_AU.utf-8 Currency symbol: $ International currency symbol: AUD
Region: en_CA.utf-8 Currency symbol: $ International currency symbol: CAD
Region: en_GB.utf-8 Currency symbol: £ International currency symbol: GBP
Region: en_US.utf-8 Currency symbol: $ International currency symbol: USD
Region: en_NZ.utf-8 Currency symbol: $ International currency symbol: NZD
Region: en_ZM.utf-8 Currency symbol: K International currency symbol: ZMW

Btw., you don't even need a test application, just call

  $ LC_MONETARY="en_ZM.utf-8" locale -ck LC_MONETARY

> The correct answer should be "Region: en_ZM.utf-8 Currency symbol: K
> International currency symbol: ZMK"
> 
> Supposedly, the code works on Linux.
> 
> Is this an issue with Windows?

We're fetching most locale information from Windows, this includes the
LC_MONETARY information.  However, the locale support up to Cygwin 3.4.x
is restricted by an issue in Windows:

Originally, locales were handled in Windows by using so called locale
identifiers, LCID, 2 byte numbers.  These LCIDs are used by Cygwin
internally.

In the meantime, Windows switched from LCIDs to locale string
identifiers following RFC 4646 resp. RFC 5646. Now, the problem is this:

Cygwin didn't yet follow suite, still using LCIDs internally, but
Windows introduced locales for which no LCID has ever been assigned.
Asking for the LCID for "en-ZW" returns 0.

For Cygwin 3.5.0, I converted Cygwin to use RFC 5646 locale strings
internally, too, so the next major version of Cygwin will be able to
support all locales Windows supports.

>     while (regions[i])
>     {
>         setlocale(LC_MONETARY, regions[i]);

You're not checking for errors here.  If the locale isn't supported,
setlocale should return NULL...

>         const struct lconv* loc = localeconv();

...and the locale information stays unchanged.  As such, if en_ZM isn't
supported, this call will still fetch the information of the en_NZ.utf-8
locale.


HTH,
Corinna

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin
  2023-03-13 10:49 ` Corinna Vinschen
@ 2023-03-14  1:30   ` Yeo Kai Wei
  2023-03-14  3:44     ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2023-03-14 10:17     ` Corinna Vinschen
  0 siblings, 2 replies; 7+ messages in thread
From: Yeo Kai Wei @ 2023-03-14  1:30 UTC (permalink / raw)
  To: cygwin

Hi Corinna,

I can't update to 3.5+, I tried reinstalling using the Cygwin setup

Using "uname -a", my current version is 3.4.6-1.x86_64.

I assume 3.5 hasn't been released officially.

May I know where to get the test release?


In the terminal, when I use $LC_MONETARY = "en_ZM.utf-8" locale -ck 
LC_MONETARY

Cygwin replies "-bash: LC_MONETARY: command not found"


Thank you very much.


Kind Regards,

YEO Kai Wei

On 13/3/2023 6:49 pm, Corinna Vinschen wrote:
> On Mar 13 08:40, Yeo Kai Wei via Cygwin wrote:
>> Hi All,
>>
>> May I ask if there's a bug with Cygwin and Windows currency?
> The en_ZM locale isn't yet supported by Cygwin.  This will change with
> Cygwin 3.5.0.  You can install the latest Cygwin test release
> 3.5.0-0.231.g93f70d7849b8 and retry.  You'll get the correct output:
>
> Region: en_AU.utf-8 Currency symbol: $ International currency symbol: AUD
> Region: en_CA.utf-8 Currency symbol: $ International currency symbol: CAD
> Region: en_GB.utf-8 Currency symbol: £ International currency symbol: GBP
> Region: en_US.utf-8 Currency symbol: $ International currency symbol: USD
> Region: en_NZ.utf-8 Currency symbol: $ International currency symbol: NZD
> Region: en_ZM.utf-8 Currency symbol: K International currency symbol: ZMW
>
> Btw., you don't even need a test application, just call
>
>    $ LC_MONETARY="en_ZM.utf-8" locale -ck LC_MONETARY
>
>> The correct answer should be "Region: en_ZM.utf-8 Currency symbol: K
>> International currency symbol: ZMK"
>>
>> Supposedly, the code works on Linux.
>>
>> Is this an issue with Windows?
> We're fetching most locale information from Windows, this includes the
> LC_MONETARY information.  However, the locale support up to Cygwin 3.4.x
> is restricted by an issue in Windows:
>
> Originally, locales were handled in Windows by using so called locale
> identifiers, LCID, 2 byte numbers.  These LCIDs are used by Cygwin
> internally.
>
> In the meantime, Windows switched from LCIDs to locale string
> identifiers following RFC 4646 resp. RFC 5646. Now, the problem is this:
>
> Cygwin didn't yet follow suite, still using LCIDs internally, but
> Windows introduced locales for which no LCID has ever been assigned.
> Asking for the LCID for "en-ZW" returns 0.
>
> For Cygwin 3.5.0, I converted Cygwin to use RFC 5646 locale strings
> internally, too, so the next major version of Cygwin will be able to
> support all locales Windows supports.
>
>>      while (regions[i])
>>      {
>>          setlocale(LC_MONETARY, regions[i]);
> You're not checking for errors here.  If the locale isn't supported,
> setlocale should return NULL...
>
>>          const struct lconv* loc = localeconv();
> ...and the locale information stays unchanged.  As such, if en_ZM isn't
> supported, this call will still fetch the information of the en_NZ.utf-8
> locale.
>
>
> HTH,
> Corinna

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin
  2023-03-14  1:30   ` Yeo Kai Wei
@ 2023-03-14  3:44     ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2023-03-14  4:20       ` Brian Inglis
  2023-03-14 10:17     ` Corinna Vinschen
  1 sibling, 1 reply; 7+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2023-03-14  3:44 UTC (permalink / raw)
  To: Yeo Kai Wei, cygwin

Please pay close attention to how the command was shown to you, including the use of the whitespace:

> >    $ LC_MONETARY="en_ZM.utf-8" locale -ck LC_MONETARY

> In the terminal, when I use $LC_MONETARY = "en_ZM.utf-8" locale -ck
> LC_MONETARY
> Cygwin replies "-bash: LC_MONETARY: command not found"

The dollar sign in there was the shell prompt; not something you have to type.

So, this is basically what and how you should enter it:

LC_MONETARY="en_ZM.utf-8" locale -ck LC_MONETARY

HTH,

Anton Lavrentiev
Contractor NIH/NLM/NCBI


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin
  2023-03-14  3:44     ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
@ 2023-03-14  4:20       ` Brian Inglis
  0 siblings, 0 replies; 7+ messages in thread
From: Brian Inglis @ 2023-03-14  4:20 UTC (permalink / raw)
  To: cygwin

On 2023-03-13 21:44, Lavrentiev, Anton (NIH/NLM/NCBI) [C] via Cygwin wrote:
> Please pay close attention to how the command was shown to you, including the use of the whitespace:
> 
>>>     $ LC_MONETARY="en_ZM.utf-8" locale -ck LC_MONETARY
> 
>> In the terminal, when I use $LC_MONETARY = "en_ZM.utf-8" locale -ck
>> LC_MONETARY
>> Cygwin replies "-bash: LC_MONETARY: command not found"
> 
> The dollar sign in there was the shell prompt; not something you have to type.
> 
> So, this is basically what and how you should enter it:
> 
> LC_MONETARY="en_ZM.utf-8" locale -ck LC_MONETARY

Try it using a known good locale first, then that locale.
Shut down all Cygwin processes.
Run setup-x86_64:
Select Packages/View Full/Search cygwin/column New dropdown/bottom 
entry/3.5.0-0.231.g93f70d7849b8, same for -devel and -doc if desired, then 
Search Clear, reset View Pending, then Next, ...
Run your terminal, redo the commands above, and you should see correct data.

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin
  2023-03-14  1:30   ` Yeo Kai Wei
  2023-03-14  3:44     ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
@ 2023-03-14 10:17     ` Corinna Vinschen
  1 sibling, 0 replies; 7+ messages in thread
From: Corinna Vinschen @ 2023-03-14 10:17 UTC (permalink / raw)
  To: cygwin

On Mar 14 09:30, Yeo Kai Wei via Cygwin wrote:
> Hi Corinna,
> 
> I can't update to 3.5+, I tried reinstalling using the Cygwin setup
> 
> Using "uname -a", my current version is 3.4.6-1.x86_64.
> 
> I assume 3.5 hasn't been released officially.
> 
> May I know where to get the test release?

In setup.  Use the version pulldown menu on the right side of the
"New" column, or the "Test" check mark at the top right.


Corinna

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-14 10:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13  0:40 [ERROR] Locale Monetary Symbol Prints Wrongly on Windows : Cygwin Yeo Kai Wei
2023-03-13  5:40 ` Brian Inglis
2023-03-13 10:49 ` Corinna Vinschen
2023-03-14  1:30   ` Yeo Kai Wei
2023-03-14  3:44     ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-03-14  4:20       ` Brian Inglis
2023-03-14 10:17     ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).