Plasma: Custom region/formats and invalid locale

Hi!

I use Plasma and have set Region (under Settings > Regional Settings > Formats) to Swedish to display time and numbers in a Swedish format but still use English as language. After logging out and in again the settings are applied and it works as expected. The problem is that changing this setting also sets the LANG environment variable to “en_SE.UTF-8”, a locale that does not exist. This gives you error messages if you run certain programs.


daniel@vmware:~> locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_SE.UTF-8
LC_CTYPE="en_SE.UTF-8"
LC_NUMERIC="en_SE.UTF-8"
LC_TIME="en_SE.UTF-8"
LC_COLLATE="en_SE.UTF-8"
LC_MONETARY="en_SE.UTF-8"
LC_MESSAGES="en_SE.UTF-8"
LC_PAPER="en_SE.UTF-8"
LC_NAME="en_SE.UTF-8"
LC_ADDRESS="en_SE.UTF-8"
LC_TELEPHONE="en_SE.UTF-8"
LC_MEASUREMENT="en_SE.UTF-8"
LC_IDENTIFICATION="en_SE.UTF-8"
LC_ALL=

daniel@vmware:~> localectl list-locales | grep en_SE
daniel@vmware:~>


daniel@vmware:~> localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: se
      X11 Layout: se
       X11 Model: microsoftpro
     X11 Options: terminate:ctrl_alt_bksp

daniel@vmware:~> cat /etc/locale.conf
LANG=en_US.UTF-8

daniel@vmware:~> cat ~/.config/plasma-localerc
[Formats]
LANG=en_SE.UTF-8

I tried to do the same thing in Fedora (same Plasma version) but the LANG environment variable is still set to en_US.UTF-8. After some digging it looks like Fedora have a script called lang.sh in /etc/profile.d that sets the LANG variable back to en_US.UTF-8 again so this issue does not occur. I also tried an installation with GNOME and changed Formats to Swedish under “Region & Language” and GNOME does not change the LANG variable at all.


[daniel@fedora ~]$ locale
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=

[daniel@fedora ~]$ localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: se
      X11 Layout: se

[daniel@fedora ~]$ cat /etc/locale.conf
LANG="en_US.UTF-8"

[daniel@fedora ~]$ cat ~/.config/plasma-localerc
[Formats]
LANG=en_SE.UTF-8

So I think my question is what the best way to solve this is and if Plasma actually should touch the LANG variable. I assume one solution could be to just “overwrite” LANG variable in my .bashrc/.profile, so a similar approach to what Fedora does. Or are there a better way to fix this? I still want LANG to be set to en_US.UTF-8 overall, I just want to change the formats of numbers/date in Plasma.

Thanks in advance!
/Daniel

You are not alone in fighting the fact that KDE does not support one to have an ISO formatted date regardless of other locale settings. This was/is the subject of much oproar on the KDE forums.

And several programs suffer of this. See e.g. this thread: https://forums.opensuse.org/showthread.php/567145-exiftool-generate-perl-error-Setting-locale-failed-Please-check-that-your-locale-settings (specially the second page).

Alas, I am still not sure if there is a nice solution >:)

Thank you for the reply! Yeah, I feel like this is a pretty common thing you want to change as a end user. I will keep an eye out for any updates then! I will go through KDE forums and see if I can find more user suggestions but it does not look very active. Maybe try the KDE subreddit.

/Daniel

Hi, me too have this problem, let me know if you find a nice solution:shame:

Hi again!

I created a post on the KDE subreddit but I didn’t get any response. But I did look around a little bit more and found a few topics with the same issue. The reply in this post suggested to just set the LANG variable in your .bashrc file to overwrite it. Again, this looks like the same approach as Fedora.

This post solved it by keeping Region set to en_US.UTF-8 but setting all other options to your language which would be sv_SE.UTF-8 in my case. So the settings looks like this. Output from locale below:


daniel@vmware:~> locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=sv_SE.UTF-8
LC_TIME=sv_SE.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=sv_SE.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=sv_SE.UTF-8
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

So this will keep LANG set to en_US.UTF-8 in the shell but set a few LC-variables to sv_SE.UTF-8. The reason I don’t want to set Region to sv_SE.UTF-8 as well is because that would change the language in Plasma to Swedish. If you think about it this is probably what you want. This will keep the same “experience” in the terminal as in Plasma.

I also have to correct myself. In the previous post I wrote that GNOME does not touch the LANG at all. It actually does set some of the LC variables when you set formats under “Region & Language”, so it looks very similar to the settings above.


daniel@localhost:~> locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=sv_SE.UTF-8
LC_TIME=sv_SE.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=sv_SE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=sv_SE.UTF-8
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT=sv_SE.UTF-8
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

But this probably what I will do.

Another thread posted a link to this merge request on KDEs GitLab where they are reworking parts of Language and Formats. I’m not enough of a programmer to know how and if it actually changes something related to this, but it is possible that it will be easier in the future!

/Daniel

The most important part is implementing locale generator “on the fly”, so possible combination of language settings is not limited to what is shipped with glibc.

Even here in this international forum it’s bass-ackwards day-month-year instead of iso8601. :frowning: