Bug 354984 - Selecting a "C" locale generates an unusable value for LC_*
Summary: Selecting a "C" locale generates an unusable value for LC_*
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_formats (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Sebastian Kügler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-07 12:45 UTC by Jonathan Marten
Modified: 2015-11-09 13:29 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Marten 2015-11-07 12:45:00 UTC
If the "Default (C)" locale (to use the standard POSIX formatting) is selected either for the main "Region" or any of the "Detailed" settings, the value written out (in common with all the others) has an encoding suffix added.  For example, with the settings:

Region:  United Kingdom - British English (en_GB)
Numbers:  No change
Time:   Default (C)
Currency:  United Kingdom - British English (en_GB)
Measurement Units:  France - francais (fr_FR)
Collation and Sorting:  Default (C)

the file $XDG_CONFIG_HOME/plasma-locale-settings.sh written out is:

# Generated script, do not edit
# Exports language-format specific env vars from startkde.
# This script has been generated from kcmshell5 formats.
# It will automatically be overwritten from there.
export LANG=en_GB.UTF-8
export LC_TIME=C.UTF-8
export LC_MONETARY=en_GB.UTF-8
export LC_MEASUREMENT=fr_FR.UTF-8
export LC_COLLATE=C.UTF-8
export LANGUAGE=en_GB

The settings for LC_TIME and LC_COLLATE, though, are not accepted by the locale system:

$ source $XDG_CONFIG_HOME/plasma-locale-settings.sh
bash: warning: setlocale: LC_TIME: cannot change locale (C.UTF-8)
bash: warning: setlocale: LC_COLLATE: cannot change locale (C.UTF-8): No such file or directory

$ perl -e 'print "Hello, world\n"'
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_GB",
        LC_ALL = (unset),
        LC_MONETARY = "en_GB.UTF-8",
        LC_COLLATE = "C.UTF-8",
        LC_MEASUREMENT = "fr_FR.UTF-8",
        LC_TIME = "C.UTF-8",
        LANG = "en_GB.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_GB.UTF-8").
Hello, world

Manually editing the file to read:

# Generated script, do not edit
# Exports language-format specific env vars from startkde.
# This script has been generated from kcmshell5 formats.
# It will automatically be overwritten from there.
export LANG=en_GB.UTF-8
export LC_TIME=C
export LC_MONETARY=en_GB.UTF-8
export LC_MEASUREMENT=fr_FR.UTF-8
export LC_COLLATE=C
export LANGUAGE=en_GB

gives the expected results with no error messages:

$ source $XDG_CONFIG_HOME/plasma-locale-settings.sh
$ perl -e 'print "Hello, world\n"'
Hello, world

The source of the ".UTF-8" suffix is QTextCodec::codecForLocale(), added near the top of KCMFormats::addLocaleToCombo() with the comment:

 // explicitely add the encoding, otherwise Qt doesn't accept dead keys and garbles the output as well

The special value "C", though, should be written out unadorned, although I don't know whether this will have any implications as hinted in the comment.

Reproducible: Always

Steps to Reproduce:
1.  Set region/language settings as above in 'kcmshell5 formats'
2.  Log out and in again, or source the config file in a shell.
3.  Observe error messages from bash, perl etc.




Version (not in the preset list for this component) is current Git master:
systemsettings 5.4.90

The intent of this combination of settings is to achieve general formatting suitable for the UK, but with dates in the POSIX format (named months instead of numeric months), metric measurements, and sorting in the shell being case sensitive.
Comment 1 Jonathan Marten 2015-11-07 13:17:01 UTC
https://git.reviewboard.kde.org/r/125984/
Comment 2 Jonathan Marten 2015-11-09 13:29:49 UTC
Git commit 78f02ac2ed40e88d6f069f35794d991b40a33139 by Jonathan Marten.
Committed on 09/11/2015 at 13:28.
Pushed by marten into branch 'master'.

Do not write out an unusable LC_* value for the "C" locale
REVIEW:125984

M  +3    -1    kcms/formats/kcmformats.cpp

http://commits.kde.org/plasma-desktop/78f02ac2ed40e88d6f069f35794d991b40a33139