Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Jul 2020 12:53:55 +0200
From:      Polytropon <freebsd@edvax.de>
To:        mbj@mbjnet.dk
Cc:        Morten Bo Johansen via freebsd-questions <freebsd-questions@freebsd.org>, Morten Bo Johansen <listmail@mbjnet.dk>
Subject:   Re: Locale oddity
Message-ID:  <20200720125355.4fd333bf.freebsd@edvax.de>
In-Reply-To: <slrnrhap1p.1gr.listmail@smtp.simply.com>
References:  <slrnrh8vv3.j55.listmail@smtp.simply.com> <0467d480-ba58-3d5d-ca77-34d784b667f9@yuripv.dev> <slrnrhap1p.1gr.listmail@smtp.simply.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 20 Jul 2020 11:30:33 +0200, Morten Bo Johansen via freebsd-questions wrote:
> On 2020-07-19 Yuri Pankov wrote:
> 
> > I'm not sure what exactly you are asking, so I'll just quote the 
> > specification, 
> > https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html, 
> > for the logic used:
> 
> Well, the reason I was asking was that I was working on a
> script where one of the functions will determine the user's
> language reliably from the locale settings. Therefore I tried
> various error handling, like e.g. the LANG variable not being
> set, etc. and I noticed this behaviour and I wondered why. I
> see the rule #4 you are referring to, but the logic in it is
> still not clear to me: Some script or program might set the
> $LANG variable to an empty value and then the LC_* variables
> that I set myself will be changed behind my back?

No, the variables (being set, and how)won't affect one another.
Rule #4 states that if $LANG is not usable (and no other information
is present), the default "fallback locale" _should_ be used, which
is "C". So the "hierarchy" is this:

	1. LC_ALL
	2. LC_* depending on category
	3. LANG
	4. fallback (usually "C")

Just as an example, if you have not set $LANG, but you have set
the several $LC_* variables, except $LC_ALL, rule #2 applies.
With $LC_ALL set, all $LC_* variables will be overridden, as
says rule #1. If no $LC_<anything> is set, but $LANG is set,
rule #3 applies. If there is nothing set, rule #4 says to use
the implementation-specific locale, which usually is "C".

So the $LC_* variables you've set yourself will always keep
their value. The question simply is: Will a program use them
according to the standard? A program _might_ do the wrong thing
and even though you have set $LC_MESSAGES to "da_DK.UTF-8",
but the program expects and only reads $LANG, it could say
something like "no locale found, falling back to 'C' locale",
which of course is _not_ the correct (!) thing to do... :-)

The common solution is:

Use LC_ALL to define all locale types with the same value.

Use LC_* variables individually, but do not set LC_ALL, if
you want to have different locale interpretations for
different things, like collation information or decimal
notation according to your local language, but messages
in English.

Optionally set LANG to the value of LC_ALL.

Sidenote:

You can use the login.conf mechanism to have the system
set the variables for you; for example in ~/.login_conf:

	me:\
		:charset=UTF-8:\
		:lang=de_DE.UTF-8:

This should work as expected.





-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200720125355.4fd333bf.freebsd>