Date: Sun, 19 Jul 2020 20:58:08 +0300 From: Yuri Pankov <yuripv@yuripv.dev> To: freebsd-questions@freebsd.org Subject: Re: Locale oddity Message-ID: <0467d480-ba58-3d5d-ca77-34d784b667f9@yuripv.dev> In-Reply-To: <slrnrh8vv3.j55.listmail@smtp.simply.com> References: <slrnrh8vv3.j55.listmail@smtp.simply.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Morten Bo Johansen via freebsd-questions wrote: > Hi > > (This is FreeBSD 12.1-RELEASE-p7 amd64) > > If I unset the $LANG variable, then all other LC_* category > locale variables will automatically be set to "C" except for > the $LC_ALL variable: > > ~/ % LANG= locale > LANG= > LC_CTYPE="C" > LC_COLLATE="C" > LC_TIME="C" > LC_NUMERIC="C" > LC_MONETARY="C" > LC_MESSAGES="C" > LC_ALL= > > Otherwise they are: > > ~/ % locale > LANG=da_DK.UTF-8 > LC_CTYPE="da_DK.UTF-8" > LC_COLLATE="da_DK.UTF-8" > LC_TIME="da_DK.UTF-8" > LC_NUMERIC="da_DK.UTF-8" > LC_MONETARY="da_DK.UTF-8" > LC_MESSAGES="da_DK.UTF-8" > LC_ALL= > > I don't understand this behaviour. Could someone explain the > logic of this to me? > > To me it seems like a bug. 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: -------- The values of locale categories shall be determined by a precedence order; the first condition met below determines the value: 1. If the LC_ALL environment variable is defined and is not null, the value of LC_ALL shall be used. 2. If the LC_* environment variable (LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) is defined and is not null, the value of the environment variable shall be used to initialize the category that corresponds to the environment variable. 3. If the LANG environment variable is defined and is not null, the value of the LANG environment variable shall be used. 4. If the LANG environment variable is not set or is set to the empty string, the implementation-defined default locale shall be used. -------- Going backwards, when you unset LANG, the last rule is applied, and our default locale is C. If you have LANG set, rule 3 is applied . Rules 1 and 2 are mostly used as overrides over the system-wide LANG setting, so LC_* variables are NOT set by default.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0467d480-ba58-3d5d-ca77-34d784b667f9>