setlocale.sh can break user-chosen locales and encodings

Bug #1204182 reported by Graeme Hewson
36
This bug affects 7 people
Affects Status Importance Assigned to Milestone
kde-runtime (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

Country/Region & Language setting is very keen to write ~/.kde/env/setlocale.sh with the contents:

export LANG=en_US.UTF-8
export LANGUAGE=en_US:en

even when the Country is not United States of America.

To reproduce:

1. In Country/Region & Language setting, Country is United Kingdom (in my case). Also note that ~/.kde/env/setlocale.sh doesn't exist.

2. Make some change (I changed Short date format from DD/MM/YY to YYYY-MM-DD) and click Apply.

3. Note that setlocale.sh has been written as above, with en_US values.

This means that when KDE is restarted, all LC_* variables are en_US.UTF-8 instead of the previous values of en_GB.UTF-8.

One workaround is to delete ~/.kde/env/setlocale.sh after making the required changes in System Settings.

Another workaround is to set the Preferred Language as well as making the other required change (Preferred Languages was previously empty on my system). Setting this to British English causes ~/.kde/env/setlocale.sh to be written with the contents:

export LANG=en_GB.UTF-8
export LANGUAGE=en_GB:en

Now there's an extreme demonstration of the problem. With Country set to United Kingdom, clicking Defaults subtly changes the Country to System Country (United Kingdom). Clicking Apply then changes the contents of setlocale.sh from the en_GB values to en_US values, even though other settings (Money, etc.) are appropriate for the UK.

Expected behaviour:

~/.kde/env/setlocale.sh should not be written if it doesn't exist and it's not
necessary to write it (LC_* variables are set elsewhere).

Originally reported to KDE at https://bugs.kde.org/show_bug.cgi?id=322688. KDE developer says file isn't written by KDE, so must be due to distribution-specific patch.

ProblemType: Bug
DistroRelease: Ubuntu 13.04
Package: systemsettings 4:4.10.5-0ubuntu0.1
ProcVersionSignature: Ubuntu 3.8.0-26.38-generic 3.8.13.2
Uname: Linux 3.8.0-26-generic x86_64
NonfreeKernelModules: nvidia
ApportVersion: 2.9.2-0ubuntu8.1
Architecture: amd64
Date: Tue Jul 23 17:47:07 2013
EcryptfsInUse: Yes
ExecutablePath: /usr/bin/systemsettings
InstallationDate: Installed on 2012-01-02 (568 days ago)
InstallationMedia: Kubuntu 11.10 "Oneiric Ocelot" - Release amd64 (20111012)
MarkForUpload: True
ProcEnviron:
 LANGUAGE=en_GB:en
 PATH=(custom, user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_GB.UTF-8
 SHELL=/bin/bash
SourcePackage: kde-workspace
UpgradeStatus: Upgraded to raring on 2013-04-27 (87 days ago)

Revision history for this message
In , Graeme Hewson (ghewson) wrote :

Country/Region & Language setting is very keen to write ~/.kde/env/setlocale.sh with the contents:

export LANG=en_US.UTF-8
export LANGUAGE=en_US:en

even when the Country is not United States of America.

To reproduce:

1. In Country/Region & Language setting, Country is United Kingdom (in my case). Also note that ~/.kde/env/setlocale.sh doesn't exist. I'm using Kubuntu.

2. Make some change (I changed Short date format from DD/MM/YY to YYYY-MM-DD) and click Apply.

3. Note that setlocale.sh has been written as above, with en_US values.

This means that when KDE is restarted, all LC_* variables are en_US.UTF-8 instead of the previous values of en_GB.UTF-8.

One workaround is to delete ~/.kde/env/setlocale.sh after making the required changes in System Settings.

Another workaround is to set the Preferred Language as well as making the other required change (Preferred Languages was previously empty on my system). Setting this to British English causes ~/.kde/env/setlocale.sh to be written with the contents:

export LANG=en_GB.UTF-8
export LANGUAGE=en_GB:en

Now there's an extreme demonstration of the problem. With Country set to United Kingdom, clicking Defaults subtly changes the Country to System Country (United Kingdom). Clicking Apply then changes the contents of setlocale.sh from the en_GB values to en_US values, even though other settings (Money, etc.) are appropriate for the UK.

Expected behaviour:

~/.kde/env/setlocale.sh should not be written if it doesn't exist and it's not
necessary to write it (LC_* variables are set elsewhere).

Revision history for this message
In , Christoph-maxiom (christoph-maxiom) wrote :

Which distribution is that? KDE does not create that file, so it must be a distribution-specific patch.

Revision history for this message
Graeme Hewson (ghewson) wrote :
Revision history for this message
In , Graeme Hewson (ghewson) wrote :
Changed in kdebase-workspace:
importance: Unknown → Medium
status: Unknown → Incomplete
Revision history for this message
In , Christoph-maxiom (christoph-maxiom) wrote :

Merci, resolving downstream. Bug 319748 is related, not sure if it was also report to launchpad.

Changed in kdebase-workspace:
status: Incomplete → Unknown
Graeme Hewson (ghewson)
no longer affects: kdebase-workspace
Revision history for this message
Launchpad Janitor (janitor) wrote : Re: Locale wrongly defaults to en_US.UTF8

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in kde-workspace (Ubuntu):
status: New → Confirmed
Revision history for this message
Thomas Sisson (thomas-sisson-1) wrote :

Under previous KDE versions setlocale.sh did not appear in System Administration>Startup and Shutdown>Autostart. I cannot say for sure whether the script itself previous ran from a system folder, but it did not appear in the settings module.

I am actually in the U.S.A. and prefer US English, but I had to change settings in Common Appearance and Behavior>Locale>Country/Region & Language sometime after an upgrade to Kubuntu 13.10 from 13.04. My country presently is set at "System Country ()" which appears confusing even though I understand the system wide setting should be US. Under Preferred Languages I have several options on the left, but the list on the right has a single empty selection. I already have trouble with applications like Firefox and Thunderbird defaulting to British dictionaries, so I don't want to add alternate English variants. It appears that the generic en (possible international English) as well as en_US is simply unavailable. I don't know for sure if this is a related bug or an additional bug due to an attempted bug fix.

I have retained my KDE settings in my home folder under several upgrades from 12.04 LTS. I also have localepurge installed, but I have not had issues until recently.

I only wonder if this is a bug in locale or the KDE settings module, or possibly an inherent flaw in the way that computer locales and languages are set up. For instance, historically the default computer interface language has been a generic form of English dominated by American English.

Revision history for this message
Harald Sitter (apachelogger) wrote :

Different issue see bug 1255761

Revision history for this message
TJ (tj) wrote :

sudo grep -rn 'setlocale\.sh' /usr/lib/kde4/*
 Binary file /usr/lib/kde4/kcm_locale.so matches

dpkg-query -S /usr/lib/kde4/kcm_locale.so
 kde-runtime: /usr/lib/kde4/kcm_locale.so

apt-get source kde-runtime
cd kde-runtime-*

grep -rn 'setlocale\.sh' *
 debian/patches/kubuntu_langpack_install.diff:344:+ // Write LANG and LANGUAGE to ~/.kde/env/setlocale.sh
 debian/patches/kubuntu_langpack_install.diff:347:+ const QString envFile = envPath % QLatin1String("/setlocale.sh");
 kcontrol/locale/kcmlocale.cpp:679: // Write LANG and LANGUAGE to ~/.kde/env/setlocale.sh
 kcontrol/locale/kcmlocale.cpp:682: const QString envFile = envPath % QLatin1String("/setlocale.sh");

grep -C4 setlocale\.sh debian/patches/kubuntu_langpack_install.diff
     load();
     KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_LOCALE);
+
+ // -------------------------------------------------------------------------
+ // Write LANG and LANGUAGE to ~/.kde/env/setlocale.sh
+
+ const QString envPath = KGlobal::dirs()->localkdedir() % QLatin1String("/env");
+ const QString envFile = envPath % QLatin1String("/setlocale.sh");
+
+ // In terms of the locale KDE's language value can express more than the
+ // language (e.g. country in en_GB and region in ca@valencia).
+ // The country values always override whatever is specified in KDE.

grep -C3 langpack.*LANG debian/changelog

kde-runtime (4:4.10.2-0ubuntu3) raring-proposed; urgency=low

  * Make kubuntu_langpack_install.diff also set LANG and LANGUAGE.
    This is done via a kde environment script (sourced by startkde).
    kdesudo invoked applications as well as polkit actions and non-KDE
    applications require properly set LANG/LANGUAGE, otherwise they'll use

Revision history for this message
TJ (tj) wrote :

There is a much wider issue caused by the generated "~/.kde/env/setlocale.sh" script; it can somehow get 'stuck' on an incorrect encoding which can't be subsequently fixed via the GUI.

I have a system with:

cat /etc/default/locale
LANG="en_GB.UTF-8"

Prior to generation of "setlocale.sh" Konsole sessions would use this correctly.

At some point I used the KDE GUI to check the locales and decided to remove the "American English" language leaving just "British English". It seems that this caused the generation of the "setlocale.sh" script but I didn't realise until sometime later when working in a Konsole various tools reported "setlocale.sh: No such file or directory".

dpkg-query -S setlocale.sh

did not return any hits so I knew it wasn't a file shipped with a package but must be generated at some point.

"locale" reported everything set to "en_GB.ISO8859-1" and no matter what I did using the GUI Language settings or the system configuration (/etc/default/locale) I couldn't figure out what was controlling it.

Finally, after exhaustively searching the system locations where locales are set, I tried searching the user home directory which revealed the existence of this shell script:

grep -r 'ISO8859-1' ~/.*
 ./kde/env/setlocale.sh: LANG="en_GB.ISO8859-1"
./kde/env/setlocale.sh: LANGUAGE:"en_GB:en"

summary: - Locale wrongly defaults to en_US.UTF8
+ setlocale.sh can break user-chosen locales and encodings
Changed in kde-workspace (Ubuntu):
importance: Undecided → Medium
Changed in kde-runtime (Ubuntu):
importance: Undecided → Medium
status: New → Confirmed
Changed in kde-workspace (Ubuntu):
status: Confirmed → Invalid
no longer affects: kde-workspace (Ubuntu)
Revision history for this message
Harald Sitter (apachelogger) wrote :

14.04 will handle en_GB and en_US correctly and force UTF-8 encoding. Peopel who want a different encoding will simply not be able to use the GUI.

Changed in kde-runtime (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Petri Salmela (pesasa) wrote :

I'm living in Finland, but I use my system in English. Now setlocale.sh tries to set all my locales to en_FI.UTF-8, which dows not even exist. Breaks things badly.

Revision history for this message
V字龍(Vdragon) (vdragon) wrote :

Same as #12, the invalid locale here is en_TW.UTF-8.

Revision history for this message
V字龍(Vdragon) (vdragon) wrote :

@Harald
What fix has released anyway?

Revision history for this message
Tuomas Suutari (tuomas-suutari) wrote :

I have the same problem as in comment 12: setlocale.sh sets locale to non-existing locale, en_FI.UTF-8.

Clearly not fixed. This bug should be reopened.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.