Bug 491305 - Changing the Regional Settings in System Settings does not change the LC_* vars in the shell (even after rebooting)
Summary: Changing the Regional Settings in System Settings does not change the LC_* va...
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_regionandlang (show other bugs)
Version: 5.27.11
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-05 15:05 UTC by jcrmatos
Modified: 2024-10-01 15:28 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.2.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jcrmatos 2024-08-05 15:05:45 UTC
SUMMARY
Changing the regional settings does not change the LC_* vars in the shell.

STEPS TO REPRODUCE
1. Change the Regional Settings in the System Settings
2. Reboot

OBSERVED RESULT
The LC_* vars in the shell were not changed.

EXPECTED RESULT
The LC_* vars in the shell change according to the Regional Settings in the System Settings.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma: Kubuntu 24.04
KDE Plasma Version: 5.27.11
KDE Frameworks Version: 5.115.0
Qt Version: 5.15.13

ADDITIONAL INFORMATION
Comment 1 hanyoung 2024-08-05 15:09:36 UTC
> Change the Regional Settings in the System Settings

Did you only change the "Language" section or the other sections as well (like "Time" for example)

If you only changed "Language", then this is the expected behavior. "Language" only modify $LANG and $LANGUAGE.

If not, please paste the contents of ~/.config/plasma-localerc
Comment 2 jcrmatos 2024-08-05 16:26:11 UTC
(In reply to hanyoung from comment #1)

No, I changed all the settings.
After changing the defaults to what I want and rebooted, all seemed fine, but if I changed them to the defaults and reboot again, the ~/.config/plasma-localerc is changed (which is correct) but the bash LC_* vars aren't.

Here are the contents of ~/.config/plasma-localerc after I changed the settings to what I want. These are correct:
[Formats]
LANG=en_US.UTF-8
LC_ADDRESS=C
LC_MEASUREMENT=C
LC_MONETARY=pt_PT.UTF-8
LC_NAME=C
LC_NUMERIC=pt_PT.UTF-8
LC_PAPER=C
LC_TELEPHONE=C
LC_TIME=C

And here are the LC_* bash vars (which are correct):
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE=pt_PT.UTF-8
LC_NUMERIC=pt_PT.UTF-8
LC_TIME=pt_PT.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=pt_PT.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=pt_PT.UTF-8
LC_NAME=pt_PT.UTF-8
LC_ADDRESS=pt_PT.UTF-8
LC_TELEPHONE=pt_PT.UTF-8
LC_MEASUREMENT=pt_PT.UTF-8
LC_IDENTIFICATION=pt_PT.UTF-8
LC_ALL=

If I change the Regional Settings to the defaults and reboot again, the ~/.config/plasma-localerc changes to this (which is correct):
[Formats]
LANG=en_US.UTF-8

but the LC_* bash vars don't change.

> > Change the Regional Settings in the System Settings
> 
> Did you only change the "Language" section or the other sections as well
> (like "Time" for example)
> 
> If you only changed "Language", then this is the expected behavior.
> "Language" only modify $LANG and $LANGUAGE.
> 
> If not, please paste the contents of ~/.config/plasma-localerc
Comment 3 jcrmatos 2024-08-05 20:06:19 UTC
I forgot to change the status.
Comment 4 Nate Graham 2024-08-05 21:00:59 UTC
I can't reproduce the issue with current it master. Is this something that would have gotten fixed in Plasma 6, Han?
Comment 5 hanyoung 2024-08-06 14:46:54 UTC
> I can't reproduce the issue with current it master. Is this something that would have gotten fixed in Plasma 6, Han?

I don't think so. 

> but the LC_* bash vars don't change.

AFAIK, kde only loads ~/.config/plasma-localerc on start up. So if the config file is correct, but locale output isn't, high chance the env come from elsewhere
Comment 6 jcrmatos 2024-08-06 15:22:47 UTC
(In reply to hanyoung from comment #5)
> > I can't reproduce the issue with current it master. Is this something that would have gotten fixed in Plasma 6, Han?
> 
> I don't think so. 
> 
> > but the LC_* bash vars don't change.
> 
> AFAIK, kde only loads ~/.config/plasma-localerc on start up. So if the
> config file is correct, but locale output isn't, high chance the env come
> from elsewhere

When changing the settings in the Regional Settings KDE changes ~/.config/plasma-localerc and the respective bash LC_* vars.
Which is correct.
But not when I select the defaults. That is the problem here.
Comment 7 hanyoung 2024-08-06 15:36:21 UTC
> But not when I select the defaults.

Is there any LC_* in ~/.config/plasma-localerc after clicking defaults?
Comment 8 jcrmatos 2024-08-06 15:53:31 UTC
(In reply to hanyoung from comment #7)
> > But not when I select the defaults.
> 
> Is there any LC_* in ~/.config/plasma-localerc after clicking defaults?

No, only this
[Formats]
LANG=en_US.UTF-8
Comment 9 hanyoung 2024-08-06 15:59:41 UTC
(In reply to jcrmatos from comment #8)
> (In reply to hanyoung from comment #7)
> > > But not when I select the defaults.
> > 
> > Is there any LC_* in ~/.config/plasma-localerc after clicking defaults?
> 
> No, only this
> [Formats]
> LANG=en_US.UTF-8

Then the incorrect bash LC_* vars aren't caused by systemsettings. You may have set them in other locations, maybe system wide settings?
Comment 10 jcrmatos 2024-08-06 16:08:00 UTC
(In reply to hanyoung from comment #9)
> (In reply to jcrmatos from comment #8)
> > (In reply to hanyoung from comment #7)
> > > > But not when I select the defaults.
> > > 
> > > Is there any LC_* in ~/.config/plasma-localerc after clicking defaults?
> > 
> > No, only this
> > [Formats]
> > LANG=en_US.UTF-8
> 
> Then the incorrect bash LC_* vars aren't caused by systemsettings. You may
> have set them in other locations, maybe system wide settings?

No, I haven't set them anywhere.
I only used systemsettings to change them and they are updated by systemsettings when I select anything but the defaults.
Only when I select the defaults they aren't updated.
The clue may be exactly why when selecting the defaults the ~/.config/plasma-localerc doesn't receive the same lines as when I change them the settings from the defaults.
Here is an example of what would be the "correct" defaults in ~/.config/plasma-localerc:
[Formats]
LANG=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_TIME=en_US.UTF-8

which would correspond to the defaults shown in systemsettings.
Comment 11 hanyoung 2024-08-06 16:13:49 UTC
> Here is an example of what would be the "correct" defaults in ~/.config/plasma-localerc

If LC_* are not explicitly set, they just default to whatever $LANG is. That's exactly why "defaults" button remove them from plasma-localerc
Comment 12 jcrmatos 2024-08-06 16:32:33 UTC
(In reply to hanyoung from comment #11)
> > Here is an example of what would be the "correct" defaults in ~/.config/plasma-localerc
> 
> If LC_* are not explicitly set, they just default to whatever $LANG is.
> That's exactly why "defaults" button remove them from plasma-localerc

In that case the LC_* vars in bash and the locale command should also be cleared or updated to the same value as LANG (en_US.UTF-8) so that the systemsettings, the bash LC_* vars and the locale command all the synced.
Comment 13 hanyoung 2024-08-06 16:37:32 UTC
> In that case the LC_* vars in bash and the locale command should also be cleared or updated to the same value as LANG (en_US.UTF-8) so that the systemsettings, the bash LC_* vars and the locale command all the synced.

There is nothing to sync here. Plasma will set the env if they are in plasma-localerc. There is no other persistent settings plasma uses.
Comment 14 jcrmatos 2024-08-06 16:41:35 UTC
(In reply to hanyoung from comment #13)
> > In that case the LC_* vars in bash and the locale command should also be cleared or updated to the same value as LANG (en_US.UTF-8) so that the systemsettings, the bash LC_* vars and the locale command all the synced.
> 
> There is nothing to sync here. Plasma will set the env if they are in
> plasma-localerc. There is no other persistent settings plasma uses.

I'm sorry to repeat myself, but if plasma updates the bash LC_* vars and the locale command output when I change the settings, which is the correct behavior, but does not do the same when I select the defaults, I believe this isn't correct. It's behavior should always be the same, don't you think?
Comment 15 hanyoung 2024-08-06 16:46:17 UTC
> but does not do the same when I select the defaults

What do you think plasma should do in that case? Override system settings? How does plasma know what your idea of "default locale" is? Default means plasma doesn't set anything and inherit from system.
Comment 16 jcrmatos 2024-08-06 16:55:03 UTC
(In reply to hanyoung from comment #15)
> > but does not do the same when I select the defaults
> 
> What do you think plasma should do in that case? Override system settings?
> How does plasma know what your idea of "default locale" is? Default means
> plasma doesn't set anything and inherit from system.

What I think it should do is exactly the same it does when I make any change from the defaults.
When I make a change from the defaults it fills all the LC_*.
This behavior works fine and syncs the plasma systemsettings with the LC_* bash vars and the locale output.

But when I change to the defaults it removes all of them from the plasma-localerc and keeps only LANG.
That is what seems to be the problem.

Maybe if instead of clearing all and keeping only LANG it kept all LC_* and simply changed them to the same default as LANG (en_US.UTF-8) the sync could be achieved when selecting the defaults?
Comment 17 hanyoung 2024-08-06 17:07:18 UTC
> Maybe if instead of clearing all and keeping only LANG it kept all LC_* and simply changed them to the same default as LANG (en_US.UTF-8) the sync could be achieved when selecting the defaults?

That's not defaults though. Your "incorrect LC_*" came from other places. Maybe system wide, or from display server env config like xorg. Overriding config from somewhere else is not default.
Comment 18 jcrmatos 2024-08-06 17:12:57 UTC
(In reply to hanyoung from comment #17)
> > Maybe if instead of clearing all and keeping only LANG it kept all LC_* and simply changed them to the same default as LANG (en_US.UTF-8) the sync could be achieved when selecting the defaults?
> 
> That's not defaults though. Your "incorrect LC_*" came from other places.
> Maybe system wide, or from display server env config like xorg. Overriding
> config from somewhere else is not default.

I just installed this system. It does not have any change to the default config except the selection of timezone and keyb layout on the installation.

I showed how the behavior of systemsettings isn't the same when changing the defaults vs when setting to the defaults.
In my opinion it should be the same in either action and if it was it would solve the lost sync between it and the LC_* bash vars and the locale output.
Comment 19 Akseli Lahtinen 2024-09-18 08:35:15 UTC
As far as I understand, if you set default values in the KCM, it will pick whatever values the system has (this can be the defaults of your distro or something else).

Is this what you mean? Also can you give us exact steps when testing this, so we can try to replicate it as close as possible?
Comment 20 jcrmatos 2024-09-22 15:18:01 UTC
(In reply to Akseli Lahtinen from comment #19)
> As far as I understand, if you set default values in the KCM, it will pick
> whatever values the system has (this can be the defaults of your distro or
> something else).
> 
> Is this what you mean? Also can you give us exact steps when testing this,
> so we can try to replicate it as close as possible?

This issue has 2 parts.

To make it easy for you to replicate, I created a new VM and made a clean install of kubuntu 24.04.1 desktop amd64 EFI.
I live in Lisbon, Portugal, so that you understand why the installer assumes that during installation.

The selections I had during installation were:
Language: American English	(pre-selected by the installer)
Region: Europe	(pre-selected by the installer)
Zone: Lisbon	(pre-selected by the installer)
Numbers and dates locale: European Portuguese (Portugal)	(pre-selected by the installer)
Keyboard mode: Generic 105-key PC	(pre-selected by the installer)
Keyboard layout: Portuguese, Default
Normal installation	(pre-selected by the installer)
Download and install updates following installation
Erase Disk, swap to file, btfrs

After the installation finished I checked these:
Login page is in English (correct) and hour and date are shown in Portuguese (correct).
Desktop shows pt (for the Portuguese keyboard, which is correct) and hour and date are in Portuguese format (correct).
The lock screen shows hour and date in Portuguese (correct).

Output of env | grep LANG
LANGUAGE=
LANG=en_US.UTF-8

Output of env | grep LC
LC_ADDRESS=pt_PT.UTF-8
LC_NAME=pt_PT.UTF-8
LC_MONETARY=pt_PT.UTF-8
LC_PAPER=pt_PT.UTF-8
LC_IDENTIFICATION=pt_PT.UTF-8
LC_TELEPHONE=pt_PT.UTF-8
LC_MEASUREMENT=pt_PT.UTF-8
LC_CTYPE=pt_PT.UTF-8
LC_TIME=pt_PT.UTF-8
LC_NUMERIC=pt_PT.UTF-8

Output of cat /etc/locale.conf
LANG=en_US.UTF-8
LC_ADDRESS=pt_PT.UTF-8
LC_IDENTIFICATION=pt_PT.UTF-8
LC_MEASUREMENT=pt_PT.UTF-8
LC_MONETARY=pt_PT.UTF-8
LC_NAME=pt_PT.UTF-8
LC_NUMERIC=pt_PT.UTF-8
LC_PAPER=pt_PT.UTF-8
LC_TELEPHONE=pt_PT.UTF-8
LC_TIME=pt_PT.UTF-8

It's not important for this issue, but note that LC_CTYPE is missing from /etc/locale.conf.

1st part of the issue is the following.

If I go to System Settings\Regional Settings\Region & Language, it shows Language American English (correct), but all the other items are wrong (they are all in American English instead of Portuguese like the /etc/locale.conf and the env vars LC_*).

To correct them I must install some necessary packages using the following commands
sudo apt install $(check-language-support)
sudo apt install hunspell hunspell-pt-br hunspell-pt-pt hyphen-pt-br hyphen-pt-pt language-pack-pt libreoffice-help-pt libreoffice-help-pt-br libreoffice-l10n-pt libreoffice-l10n-pt-br libreoffice-lightproof-pt-br mythes-pt-br mythes-pt-pt wbrazilian wportuguese
and reboot.

Next I modify all the wrong settings in System Settings\Regional Settings\Region & Language to european Portuguese (Portugal) pt_PT.UTF-8, and reboot.

Now everything seems OK.
If I go back to System Settings\Regional Settings\Region & Language all the settings are correct. The env vars LC_* and LANG and the /etc/locale.conf are all correct.

Now the 2nd part of the issue.

If I press the Defaults button, it changes all items to American English (correct).
I press Apply and reboot.

After rebooting the Login screen still shows the hour and date in Portuguese (incorrect).
After logging in, the desktop shows the hour and date in Portuguese (incorrect).
The env | grep LC command shows the same values as before (Portuguese), which are incorrect. They should all be en_US.UTF-8.

Output of env | grep LANG
LANGUAGE=en_US
LANG=en_US.UTF-8

These are correct, but notice that before the LANGUAGE var was blank. I don't see this as  a problem or important, but just wanted to highlight it.

The /etc/locale.conf still remains with the old values (all Portuguese except for the LANG), which is incorrect.

The lock screen also shows the hour and date in Portuguese, which is incorrect.

So, summarizing:
1. The settings on the System Settings\Regional Settings\Region & Language after installation do not match the installation selections;
2. After changing the System Settings\Regional Settings\Region & Language  to the Defaults, it doesn't update the Login screen, the desktop hour/date, the lock screen, the env vars LC_* or the /etc/locale.conf.

In my opinion changing the System Settings\Regional Settings\Region & Language should update all of the above so that the system is in sync either on the GUI or the shell.

I have print-screens that I can send you, if you need to.

Thanks.
Comment 21 hanyoung 2024-09-22 15:33:03 UTC
Ah, so the problem is Kubuntu installer set the system-wide locale settings, but Plasma can only change user locale. When you install the system with Portuguese, the LC_* are set in /etc/locale.conf. But when you set language in Plasma, we override LANG and LANGUAGE in ~/.config/plasma-localerc. But we DO NOT change LC_* by default. Because LC_* should inherit LANG if not explicitly set.

We didn't expect system-wide setting to explicitly set LC_* vars, because ideally they should be unset and inherit from LANG. I think an easy way to fix this problem would be to check LC_* vars when user is setting LANG in Plasma Language & Lang KCM.
If the LC_* is explicitly set, and the setting is not coming from Plasma, we also override LC_* in ~/.config/plasma-localerc.
Comment 22 jcrmatos 2024-09-22 16:53:33 UTC
(In reply to hanyoung from comment #21)
> Ah, so the problem is Kubuntu installer set the system-wide locale settings,
> but Plasma can only change user locale. When you install the system with
> Portuguese, the LC_* are set in /etc/locale.conf. But when you set language
> in Plasma, we override LANG and LANGUAGE in ~/.config/plasma-localerc. But
> we DO NOT change LC_* by default. Because LC_* should inherit LANG if not
> explicitly set.
> 
> We didn't expect system-wide setting to explicitly set LC_* vars, because
> ideally they should be unset and inherit from LANG. I think an easy way to
> fix this problem would be to check LC_* vars when user is setting LANG in
> Plasma Language & Lang KCM.
> If the LC_* is explicitly set, and the setting is not coming from Plasma, we
> also override LC_* in ~/.config/plasma-localerc.

If it helps, the contents of ~/.config/plasma-localerc in the 3 stages are the following.

1. After installation, ~/.config/plasma-localerc has this content
[Formats]
LANG=en_US.UTF-8

2. After correcting all the options (except the system language that always remain American English) in System Settings\Regional Settings\Region & Language to Portuguese, ~/.config/plasma-localerc has this content
[Formats]
LANG=en_US.UTF-8
LC_ADDRESS=pt_PT.UTF-8
LC_MEASUREMENT=pt_PT.UTF-8
LC_MONETARY=pt_PT.UTF-8
LC_NAME=pt_PT.UTF-8
LC_NUMERIC=pt_PT.UTF-8
LC_PAPER=pt_PT.UTF-8
LC_TELEPHONE=pt_PT.UTF-8
LC_TIME=pt_PT.UTF-8

Please note that LC_IDENTIFICATION and LC_CTYPE are not present. Shouldn't they be?

3. After pressing the Defaults button and rebooting, ~/.config/plasma-localerc has this content
[Formats]
LANG=en_US.UTF-8


If I understood correctly your 2nd paragraph, that would solve only the GUI part of the 2nd part of the issue. It would still remain unsynced between the GUI and the shell. Am I wrong?

And what would be a possible correction for the 1st part?
Comment 23 Bug Janitor Service 2024-09-23 16:53:07 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4739
Comment 24 hanyoung 2024-09-30 10:09:45 UTC
Git commit 5a687105d02d3882accd80d251861f264be22c18 by Han Young.
Committed on 30/09/2024 at 10:09.
Pushed by hanyoung into branch 'master'.

kcm_regionandlang: always set LC_* when changing language

If the LC_* is not set with Plasma (~/.config/plasma-localerc),
they inherit system-wide setting. However, we don't take system-wide setting
into account when displaying LC_* vars. As the result, the UI may display
incorrect results. Always set LC_* when changing language to avoid this issue.

M  +4    -0    kcms/region_language/kcmregionandlang.cpp
M  +12   -0    kcms/region_language/regionandlangsettings.cpp
M  +23   -0    kcms/region_language/regionandlangsettings.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/5a687105d02d3882accd80d251861f264be22c18
Comment 25 Nate Graham 2024-09-30 13:39:33 UTC
Git commit fecb669d90835d7cc6855944ca842e150bcf77c3 by Nate Graham.
Committed on 30/09/2024 at 13:16.
Pushed by ngraham into branch 'Plasma/6.2'.

kcm_regionandlang: always set LC_* when changing language

If the LC_* is not set with Plasma (~/.config/plasma-localerc),
they inherit system-wide setting. However, we don't take system-wide setting
into account when displaying LC_* vars. As the result, the UI may display
incorrect results. Always set LC_* when changing language to avoid this issue.


(cherry picked from commit 5a687105d02d3882accd80d251861f264be22c18)

Co-authored-by: Han Young <hanyoung@protonmail.com>

M  +4    -0    kcms/region_language/kcmregionandlang.cpp
M  +12   -0    kcms/region_language/regionandlangsettings.cpp
M  +23   -0    kcms/region_language/regionandlangsettings.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/fecb669d90835d7cc6855944ca842e150bcf77c3