The old $LANG-in-a-box trick (was Re: X11R7.5 and C.UTF-8)

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Dec 3 18:45:00 GMT 2009



[redirected to cygwin-developers]


On Dec  3 14:48, Corinna Vinschen wrote:
> On Dec  3 13:16, Andy Koppe wrote:
> > 2009/12/3 Thomas Dickey:
> > >> From
> > >> http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html,
> > >> §7.2:
> > >>
> > >> "The tables in Locale Definition describe the characteristics and
> > >> behavior of the POSIX locale for data consisting entirely of
> > >> characters from the portable character set and the control character
> > >> set. For other characters, the behavior is unspecified."
> > >>
> > >> This means that characters 0..127 have to be treated as ASCII, but
> > >> beyond that an implementation can do what it wants. And on Cygwin 1.7,
> > >> plain "C" actually does imply UTF-8, which happily is
> > >> backward-compatible with ASCII.
> > >
> > > That's an interpretation that so far hasn't been blessed by the standards
> > > people.  Any discussion of this topic should mention that, as a caveat.
> > 
> > Fair point. It also means that apps are entitled to assume that "C"
> > supports no more than ASCII, which is why Cygwin 1.7's default locale
> > is C.UTF-8. A default locale setting based on the user's language
> > selection would be better, but we don't have that (yet?).
> 
> Try the attached.  Note:  It has a hidden "--testloop" option...

I created a new, simplified version of my tiny getlocale tool, which
prints "export LANG=..." to stdout, or "setenv LANG ..." if the -c
option has been given.  See attached source.

In theory we could use it in /etc/profile.d/lang.{c}sh:

/etc/profile.d/lang.sh:

  test -z "${LC_ALL:-${LC_CTYPE:-$LANG}}" && eval $(getlocale -U)

/etc/profile.d/lang.csh:

  if ( $?LC_ALL == 0 && $?LC_CTYPE == 0 && $?LANG == 0 ) eval `getlocale -cU`

If that's desired, I could easily create a getlocale package for the
Base category.

One problem we still have is that the iso639 language code returned by
Windows is a three-letter code in rare cases (see the --testloop output)
This is not feasible for newlib so far.  Maybe the getlocale tool should
drop back to "C" in these cases.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getlocale.c
Type: text/x-c++src
Size: 3266 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-developers/attachments/20091203/51e9bba1/attachment.bin>


More information about the Cygwin-developers mailing list