public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* Add locale.exe option for querying Windows UI languages
@ 2011-10-08  9:24 Andy Koppe
  2011-10-08 15:04 ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Koppe @ 2011-10-08  9:24 UTC (permalink / raw)
  To: cygwin-patches

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

The attached patch adds a --interface/-i option to locale.exe that
makes the --system/-s and --user/-u options print the respective
default UI language instead of the default locale.

	* locale.cc: Add --interface option for printing Windows default UI
	languages.

For background, here's what Windows' various default locales and languages do:

- LOCALE_USER_DEFAULT: This reflects the setting on the Formats tab of
the (Windows 7) Region&Language control panel, which affects the
format of times, dates, numbers, and currency.

- LOCALE_SYSTEM_DEFAULT: This reflects the "Language for non-Unicode
programs" on the Adminstrative tab of Region&Language control panel,
which also determines the ANSI and OEM codepages.

- GetUserDefaultUILanguage(): This is the current user's Windows UI
language, also called display language. On Windows installs with
multiple UI languages, a setting for this appears on the "Keyboards
and Languages" tab of the Region&Language control panel.

- GetSystemDefaultUILanguage(): The is the system-wide UI language
used for things that aren't user-specific, e.g. the login screen. As
far as I know it's determined at Windows install time and can''t be
changed.

(The latter two APIs are available from Windows 2000 onwards.)

Looking at those, and if we wanted to base the Cygwin locale settings
on the Windows ones, I think LC_NUMERIC, LC_TIME, and LC_MONETARY
should be determined by LOCALE_USER_DEFAULT, but LC_MESSAGES should be
determined by GetUserDefaultUILanguage(). Not sure about LC_CTYPE and
LC_COLLATE, but I suppose it would make sense for character
classification and sorting to match the UI language.

See also this blog post by MS's "Dr International" Michael Kaplan:
http://blogs.msdn.com/b/michkap/archive/2006/05/13/596971.aspx

Andy

[-- Attachment #2: ui_lang.patch --]
[-- Type: application/octet-stream, Size: 1778 bytes --]

Index: winsup/utils/locale.cc
===================================================================
RCS file: /cvs/src/src/winsup/utils/locale.cc,v
retrieving revision 1.11
diff -u -r1.11 locale.cc
--- winsup/utils/locale.cc	3 May 2011 10:34:25 -0000	1.11
+++ winsup/utils/locale.cc	8 Oct 2011 08:11:52 -0000
@@ -58,6 +58,7 @@
 	   "  -m, --charmaps       List all available character maps\n"
 	   "  -s, --system         Print system default locale\n"
 	   "  -u, --user           Print user's default locale\n"
+	   "  -i, --interface      Print default UI language instead of locale\n"
 	   "  -U, --utf            Attach \".UTF-8\" to the result\n"
 	   "  -v, --verbose        More verbose output\n"
 	   "  -h, --help           This text\n",
@@ -72,12 +73,13 @@
   {"charmaps", no_argument, NULL, 'm'},
   {"system", no_argument, NULL, 's'},
   {"user", no_argument, NULL, 'u'},
+  {"interface", no_argument, NULL, 'i'},
   {"utf", no_argument, NULL, 'U'},
   {"verbose", no_argument, NULL, 'v'},
   {"help", no_argument, NULL, 'h'},
   {0, no_argument, NULL, 0}
 };
-const char *opts = "achkmsuUv";
+const char *opts = "achkmsuiUv";
 
 int
 getlocale (LCID lcid, char *name)
@@ -747,6 +749,7 @@
 {
   int opt;
   LCID lcid = 0;
+  int ui_lang = 0;
   int all = 0;
   int cat = 0;
   int key = 0;
@@ -777,6 +780,9 @@
       case 'u':
       	lcid = LOCALE_USER_DEFAULT;
 	break;
+      case 'i':
+	ui_lang = 1;
+	break;
       case 'U':
       	utf = ".UTF-8";
 	break;
@@ -796,6 +802,13 @@
     print_charmaps ();
   else if (lcid)
     {
+      if (ui_lang)
+	{
+	  if (lcid == LOCALE_SYSTEM_DEFAULT)
+	    lcid = GetSystemDefaultUILanguage();
+	  else
+	    lcid = GetUserDefaultUILanguage();
+	}
       if (getlocale (lcid, name))
 	printf ("%s%s\n", name, utf);
     }

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

* Re: Add locale.exe option for querying Windows UI languages
  2011-10-08  9:24 Add locale.exe option for querying Windows UI languages Andy Koppe
@ 2011-10-08 15:04 ` Corinna Vinschen
  2011-10-09 10:31   ` Andy Koppe
  0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2011-10-08 15:04 UTC (permalink / raw)
  To: cygwin-patches

Hi Andy,

On Oct  8 10:24, Andy Koppe wrote:
> The attached patch adds a --interface/-i option to locale.exe that
> makes the --system/-s and --user/-u options print the respective
> default UI language instead of the default locale.
> 
> 	* locale.cc: Add --interface option for printing Windows default UI
> 	languages.
> 
> For background, here's what Windows' various default locales and languages do:
> 
> - LOCALE_USER_DEFAULT: This reflects the setting on the Formats tab of
> the (Windows 7) Region&Language control panel, which affects the
> format of times, dates, numbers, and currency.
> 
> - LOCALE_SYSTEM_DEFAULT: This reflects the "Language for non-Unicode
> programs" on the Adminstrative tab of Region&Language control panel,
> which also determines the ANSI and OEM codepages.
> 
> - GetUserDefaultUILanguage(): This is the current user's Windows UI
> language, also called display language. On Windows installs with
> multiple UI languages, a setting for this appears on the "Keyboards
> and Languages" tab of the Region&Language control panel.
> 
> - GetSystemDefaultUILanguage(): The is the system-wide UI language
> used for things that aren't user-specific, e.g. the login screen. As
> far as I know it's determined at Windows install time and can''t be
> changed.

I like the idea of the patch, but I'm wondering if this is the right
approach.  I wasn't aware of the difference between the LOCALE_FOO_DEFAULT
values and what the GetFooDefaultUILanguage functions return, otherwise
I would have probably used the GetFooDefaultUILanguage functions right from
the start.

What I mean is this.  The locale -u/-s functionality was supposed to be
used to set the $LANG value preferredly.  Since LANG means language in
the first place, the UI language is a much more natural choice for the
default -s/-u functionality, isn't it?

Therefore, afaics, it would be better if we change locale to use the
GetFooDefaultUILanguage functions by default, and we add a modifier
(-r/--region?) to switch to LOCALE_FOO_DEFAULT.

Either way, the usage output will have to be improved.  Maybe we should
explicitely state that the values printed refer to the Windows values,
and that one of them is the UI locale and the other is the... hmm...
how to say it..., maybe the "region settings locale" or so.

> Looking at those, and if we wanted to base the Cygwin locale settings
> on the Windows ones, I think LC_NUMERIC, LC_TIME, and LC_MONETARY
> should be determined by LOCALE_USER_DEFAULT, but LC_MESSAGES should be
> determined by GetUserDefaultUILanguage(). Not sure about LC_CTYPE and
> LC_COLLATE, but I suppose it would make sense for character
> classification and sorting to match the UI language.

The system should not set the LC_xxx values at all.  From my POV the
system should only default to some $LANG, while setting the LC_xxx
values is the job of the user if the $LANG value doesn't suffice.
However, if the user wants to do that, we will have the new flag.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

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

* Re: Add locale.exe option for querying Windows UI languages
  2011-10-08 15:04 ` Corinna Vinschen
@ 2011-10-09 10:31   ` Andy Koppe
  2011-10-10  9:53     ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Koppe @ 2011-10-09 10:31 UTC (permalink / raw)
  To: cygwin-patches

On 8 October 2011 16:03, Corinna Vinschen wrote:
>
> On Oct  8 10:24, Andy Koppe wrote:
>> The attached patch adds a --interface/-i option to locale.exe that
>> makes the --system/-s and --user/-u options print the respective
>> default UI language instead of the default locale.
>>
>>       * locale.cc: Add --interface option for printing Windows default UI
>>       languages.
>>
>> For background, here's what Windows' various default locales and languages do:
>>
>> - LOCALE_USER_DEFAULT: This reflects the setting on the Formats tab of
>> the (Windows 7) Region&Language control panel, which affects the
>> format of times, dates, numbers, and currency.
>>
>> - LOCALE_SYSTEM_DEFAULT: This reflects the "Language for non-Unicode
>> programs" on the Adminstrative tab of Region&Language control panel,
>> which also determines the ANSI and OEM codepages.
>>
>> - GetUserDefaultUILanguage(): This is the current user's Windows UI
>> language, also called display language. On Windows installs with
>> multiple UI languages, a setting for this appears on the "Keyboards
>> and Languages" tab of the Region&Language control panel.
>>
>> - GetSystemDefaultUILanguage(): The is the system-wide UI language
>> used for things that aren't user-specific, e.g. the login screen. As
>> far as I know it's determined at Windows install time and can''t be
>> changed.
>
> I like the idea of the patch, but I'm wondering if this is the right
> approach.  I wasn't aware of the difference between the LOCALE_FOO_DEFAULT
> values and what the GetFooDefaultUILanguage functions return, otherwise
> I would have probably used the GetFooDefaultUILanguage functions right from
> the start.
>
> What I mean is this.  The locale -u/-s functionality was supposed to be
> used to set the $LANG value preferredly.  Since LANG means language in
> the first place, the UI language is a much more natural choice for the
> default -s/-u functionality, isn't it?

Makes sense.

> Therefore, afaics, it would be better if we change locale to use the
> GetFooDefaultUILanguage functions by default, and we add a modifier
> (-r/--region?) to switch to LOCALE_FOO_DEFAULT.
>
> Either way, the usage output will have to be improved.  Maybe we should
> explicitely state that the values printed refer to the Windows values,
> and that one of them is the UI locale and the other is the... hmm...
> how to say it..., maybe the "region settings locale" or so.

How about having one option for each of the Windows settings, and
dividing the help output into groups, like so:

POSIX locale options:
  -a, --all-locales    List all available supported locales
  -c, --category-name  List information about given category NAME
  -k, --keyword-name   Print information about given keyword NAME
  -m, --charmaps       List all available character maps

Windows locale options:
  -u, --user-lang      Print user default UI language
  -s, --system-lang    Print system default UI language
  -f, --format         Print user format setting for times, numbers & currency
  -n, --non-unicode    Print system locale for non-Unicode programs
  -U, --utf            Attach ".UTF-8" to the result

Other options:
  -v, --verbose        More verbose output
  -h, --help           This text


>> Looking at those, and if we wanted to base the Cygwin locale settings
>> on the Windows ones, I think LC_NUMERIC, LC_TIME, and LC_MONETARY
>> should be determined by LOCALE_USER_DEFAULT, but LC_MESSAGES should be
>> determined by GetUserDefaultUILanguage(). Not sure about LC_CTYPE and
>> LC_COLLATE, but I suppose it would make sense for character
>> classification and sorting to match the UI language.
>
> The system should not set the LC_xxx values at all.  From my POV the
> system should only default to some $LANG, while setting the LC_xxx
> values is the job of the user if the $LANG value doesn't suffice.

Not sure about that, but it's not really worth discussing unless we do
decide to follow the Windows setting(s) by default.

Andy

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

* Re: Add locale.exe option for querying Windows UI languages
  2011-10-09 10:31   ` Andy Koppe
@ 2011-10-10  9:53     ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2011-10-10  9:53 UTC (permalink / raw)
  To: cygwin-patches

On Oct  9 11:31, Andy Koppe wrote:
> On 8 October 2011 16:03, Corinna Vinschen wrote:
> > Therefore, afaics, it would be better if we change locale to use the
> > GetFooDefaultUILanguage functions by default, and we add a modifier
> > (-r/--region?) to switch to LOCALE_FOO_DEFAULT.
> >
> > Either way, the usage output will have to be improved.  Maybe we should
> > explicitely state that the values printed refer to the Windows values,
> > and that one of them is the UI locale and the other is the... hmm...
> > how to say it..., maybe the "region settings locale" or so.
> 
> How about having one option for each of the Windows settings, and
> dividing the help output into groups, like so:
> 
> POSIX locale options:
>   -a, --all-locales    List all available supported locales
>   -c, --category-name  List information about given category NAME
>   -k, --keyword-name   Print information about given keyword NAME
>   -m, --charmaps       List all available character maps
> 
> Windows locale options:
>   -u, --user-lang      Print user default UI language
>   -s, --system-lang    Print system default UI language
>   -f, --format         Print user format setting for times, numbers & currency
>   -n, --non-unicode    Print system locale for non-Unicode programs
>   -U, --utf            Attach ".UTF-8" to the result
> 
> Other options:
>   -v, --verbose        More verbose output
>   -h, --help           This text

I had something like this grouping in mind, too.  I applied a matching
patch now.  The help text is just a bit different since it's based on
the output of the glibc locale --help text.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

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

end of thread, other threads:[~2011-10-10  9:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-08  9:24 Add locale.exe option for querying Windows UI languages Andy Koppe
2011-10-08 15:04 ` Corinna Vinschen
2011-10-09 10:31   ` Andy Koppe
2011-10-10  9:53     ` 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).