Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [SOLVED] Strange locale behaviour (Read 733 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[SOLVED] Strange locale behaviour

I'm facing a strange issue. Need help/explanation.

In order to make Monday the first day of the week in XFCE I added and enabled the GB locale in /etc/locale.gen:

Code: [Select]
en_US.UTF-8 UTF-8
en_GB.UTF-8 UTF-8

Then I have set ONLY LC_TIME="en_GB.UTF-8" in /etc/default/locale.

But when I issue the locale command I get this:

Code: [Select]
LANG=en_GB.utf8
LC_CTYPE="en_GB.utf8"
LC_NUMERIC="en_GB.utf8"
LC_TIME="en_GB.utf8"
LC_COLLATE="en_GB.utf8"
LC_MONETARY="en_GB.utf8"
LC_MESSAGES="en_GB.utf8"
LC_PAPER="en_GB.utf8"
LC_NAME="en_GB.utf8"
LC_ADDRESS="en_GB.utf8"
LC_TELEPHONE="en_GB.utf8"
LC_MEASUREMENT="en_GB.utf8"
LC_IDENTIFICATION="en_GB.utf8"
LC_ALL=

Also, my /.dmrc became like this:

Code: [Select]
[Desktop]
Session=xfce
Language=en_GB.utf8

Can't figure out why all locale settings became GB.

Re: Strange locale behaviour

Reply #1
P.S.

Reverted LC_TIME back to en_US.UTF-8 in /etc/default/locale.

Now /etc/default/locale and /etc/locale.conf are identical and have en_US everywhere:

Code: [Select]
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

But nevertheless the locale command shows everythingl in en_GB

Why just enabling en_GB locale in /etc/locale.gen makes all my system in this locale?

It never happened to me before in other distros.

Re: Strange locale behaviour

Reply #2
Did you run
Code: [Select]
# locale-gen
after your changes? You can enable several locales in /etc/locale.gen (which I have done) and set the default from one of those enabled in /etc/locale.conf which works here - I'm not using /etc/default/locale to set my locale though, rather /etc/locale.conf, and I'm not attempting to do a fine grained selection.

Re: Strange locale behaviour

Reply #3
Did you run
Code: [Select]
# locale-gen
after your changes?

Quote
I added and enabled the GB locale
Yes, as I've said.

I tried both /etc/default/locale and /etc/locale.conf but it doesn't set only the time format to be in en_GB. It sets the whole system to that locale instead. And I don't know why, like wtf actually.

Even if I leave /etc/default/locale and /etc/locale.conf as they are by default in en_US, but simply add and enable the locale in /etc/locale.gen it nevertheless turns the system to en_GB.

My guess is that XFCE Calendar does it actually. And it also sets the /.dmrc

Idk, what to do here. Probably file a bug report there?

Re: Strange locale behaviour

Reply #4
This seems to give the desired result, setting it in in /etc/locale.conf didn't change anything for me. Then ag'ing  /etc reminded me I had set the lang in /etc/profile.d, not sure if it needs to be executable as the other files in there aren't, but anyway a quick test shows it should do what you want:
Code: [Select]
$ ls -l /etc/profile.d/customlocale.sh 
-rwxr-xr-x 1 root root 54 Apr 17 14:26 /etc/profile.d/customlocale.sh
$ cat /etc/profile.d/customlocale.sh
export LANG="en_US.utf8"
export LC_TIME="en_GB.UTF-8"
$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME=en_GB.UTF-8
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
Whether that means there is a bug in the other config locations, or that you have some other higher priority config over-riding those settings which you have not found yet, I don't know. If you are using a shell other than bash it might affect things too.

Re: Strange locale behaviour

Reply #5
Code: [Select]
$ ls -l /etc/profile.d/customlocale.sh 
-rwxr-xr-x 1 root root 54 Apr 17 14:26 /etc/profile.d/customlocale.sh
$ cat /etc/profile.d/customlocale.sh
export LANG="en_US.utf8"
export LC_TIME="en_GB.UTF-8"
$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME=en_GB.UTF-8
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

Thank you for your time! Ok, will try it.

Re: Strange locale behaviour

Reply #6
Anyway, in case it doesn't chage LC_TIME only, I don't care if the whole system is in en_GB. So, I'll mark it as solved. Thanks.



Re: [SOLVED] Strange locale behaviour

Reply #9
After some more investigation, the  /etc/profile.d/customlocale.sh file I created doesn't need to be executable. Adding some debug logging to /etc/profile.d/locale.sh might help reveal what is happening if you wanted to investigate further:
Code: [Select]
$ cat /etc/profile.d/locale.sh 
#!/bin/sh

# load locale.conf in XDG paths.
# /etc/locale.conf loads and overrides by kernel command line is done by systemd
# But we override it here, see FS#56688
echo "locale.sh starting" >/tmp/locale.sh.log
echo "LANG = $LANG" >>/tmp/locale.sh.log
if [ -z "$LANG" ]; then
  echo "went past test 1" >>/tmp/locale.sh.log
  if [ -n "$XDG_CONFIG_HOME" ] && [ -r "$XDG_CONFIG_HOME/locale.conf" ]; then
    . "$XDG_CONFIG_HOME/locale.conf"
  elif [ -n "$HOME" ] && [ -r "$HOME/.config/locale.conf" ]; then
    . "$HOME/.config/locale.conf"
  elif [ -r /etc/locale.conf ]; then
    . /etc/locale.conf
    echo "sourced /etc/locale.conf" >>/tmp/locale.sh.log
  fi
fi

# define default LANG to C if not already defined
LANG=${LANG:-C}

# export all locale (7) variables when they exist
export LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY
       LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
       LC_IDENTIFICATION

1) with customlocale.sh
$ cat /tmp/locale.sh.log
locale.sh starting
LANG = en_US.UTF-8

2) without customlocale.sh
$ cat /tmp/locale.sh.log
locale.sh starting
LANG =
went past test 1
sourced /etc/locale.conf


It never gets past the first test if LANG is already defined by the time this runs, so it never looks in all the other user configurable locations. Also it doesn't appear to look in /etc/default/locale.conf. But for me anyway, if I remove my user created customlocale.sh file which runs before locale.sh then I can set things in /etc/locale.conf and it works as expected. It doesn't really matter how you set the environment variables anyway I suppose, so long as they end up correct.

Re: [SOLVED] Strange locale behaviour

Reply #10
After some more investigation, the  /etc/profile.d/customlocale.sh file I created doesn't need to be executable. Adding some debug logging to /etc/profile.d/locale.sh might help reveal what is happening if you wanted to investigate further

It never gets past the first test if LANG is already defined by the time this runs, so it never looks in all the other user configurable locations. Also it doesn't appear to look in /etc/default/locale.conf. But for me anyway, if I remove my user created customlocale.sh file which runs before locale.sh then I can set things in /etc/locale.conf and it works as expected. It doesn't really matter how you set the environment variables anyway I suppose, so long as they end up correct.

Thank you very much! Now it all came together. The puzzle is now solved. Cheers!