Background Information
I tested the solution on Fedora 21 with GNOME Shell 3.14.4, but I believe it can be applied to other versions as well.
First thing to understand is that GNOME desktop environment overrides the system-wide locale definitions and thus is not affected by /etc/locale.conf
. In addition, there are might be applications that have their own locale configuration and don't use the system or GNOME settings at all. In this guide I will describe a way to customize the locale settings to your needs and GNOME and the system will be consistent from the locale perspective.
Checking Current Locale Status
System-wide Settings
From Fedora 21 System Administrator's Guide:
System-wide locale settings are stored in the /etc/locale.conf
file, which is read at early boot by the systemd daemon. The locale settings configured in /etc/locale.conf
are inherited by every service or user, unless individual programs or individual users override them.
To see the current locale status we can run:
$ localectl status
System Locale: LANG=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
VC Keymap: us
X11 Layout: us
GNOME Settings
$ gsettings get org.gnome.system.locale region
'en_US.UTF-8'
GNOME has only one setting. By giving a quick look at the source code of gnome-control-center it seems that when the set_localed_locale()
function is called, it sets all the following categories (LC_TIME, LC_NUMERIC, LC_MONETARY, LC_MEASUREMENT, LC_PAPER) to the same one locale defined in org.gnome.system.locale region
.
Mixing different locale settings seems impossible without creating a custom locale, but fortunately it's not a very complex task.
Creating Custom Locale
I think the easiest way to explain is by example. In my specific case I wanted to have a custom locale, primarily based on Hebrew (he_IL) but with LC_NAME, LC_MESSAGES from en_US and LC_TIME (with modified first_weekday
and first_workday
) from en_GB.
Grabbing Locale Definition Files
You should have an idea which locales you want to mix. First we need to locate the related definition files, which can be found in /usr/share/i18n/locales/
.
Back to my example, I needed the following: he_IL, en_US and en_GB. I set up a working folder in my home and copied the required files into it:
$ cd /usr/share/i18n/locales
$ mkdir -v ~/custom-locale ; cp -v he_IL en_US en_GB ~/custom-locale/
Creating a New Definition File
I decided to call my locale hc_IL and took he_IL as a basis. The following lines create a new file hc_IL
with the contents from he_IL
and on the way replace all the occurrences of a string he_IL inside the file with hc_IL.
$ cd ~/custom-locale/
$ sed 's/he_IL/hc_IL/g' he_IL > hc_IL
Modifying the New Definition File
Now we can customize the new locale to our needs. Open the newly created file ~/custom-locale/hc_IL
with your favorite text editor. I use vim (it has proper syntax highlighting for locale definition files):
$ vim ~/custom-locale/hc_IL
For those who haven't chosen their favorite editor yet and vim is not their cup of tea, can use gedit :)
$ gedit ~/custom-locale/hc_IL
The file structure is not very complicated. Essentially, it is constructed from sections. From locale(5) man pages:
The locale definition has one part for each locale category. Each part
can be copied from another existing locale or can be defined from
scratch. If the category should be copied, the only valid keyword in
the definition is copy followed by the name of the locale which should be copied.
The notion of copy is very useful. It saves time and the resulting file is clear and concise. For example, instead of copying entire sections around, you can have:
LC_MESSAGES
copy "en_US"
END LC_MESSAGES
The complete documentation on a locale definition file can be accessed via:
$ man 5 locale
Although, if you just want to create a custom locale, which is a mix of existing ones there's no need to understand every detail.
In my case I modified the following categories and keywords:
LC_IDENTIFICATION
title "Custom Hebrew locale"
source "mydomain.ws"
address "http:////www.mydomain.ws"
contact ""
email "admin@mydomain.ws"
tel ""
fax ""
language "Hebrew"
territory "Israel"
revision "1.0"
date "2015-04-21"
Note: All the "category.." lines in the LC_IDENTIFICATION section have been modified during the file creation using sed
. So we don't need to touch them anymore.
LC_TIME
I copied the complete section from en_GB and modified only the lines that indicate the first day of week and the first work day:
first_weekday 1
first_workday 1
The rest of the categories I left as they are or replaced their content with the copy directive as in:
LC_NAME
copy "en_US"
END LC_NAME
That's it, the definition file is ready. Don't forget to save the file :)
Compile and Copy the New Locale
Compilation of the new locale is done using the following command as root or using sudo. Replace hc_IL
with your locale:
$ sudo localedef -c -v -i hc_IL -f UTF-8 hc_IL.UTF-8
If the compilation is successful the compiled locale data is added to the archive file /usr/lib/locale/locale-archive
.
Copy the new locale definition file to the locale definitions directory. Replace hc_IL
with your locale:
$ sudo cp -v hc_IL /usr/share/i18n/locales/
Activating the New Locale
In this step we want to configure the system and GNOME to use the new locale.
System-wide Settings
Edit the /etc/locale.conf
file as root and set every line that starts with LC_
to your new locale. For example:
LANG=en_US.UTF-8
LC_NUMERIC=hc_IL.utf8
LC_TIME=hc_IL.utf8
LC_MONETARY=hc_IL.utf8
LC_PAPER=hc_IL.utf8
LC_MEASUREMENT=hc_IL.utf8
GNOME Settings
To activate the new locale in GNOME run the following command. Replace hc_IL
with your locale:
$ gsettings set org.gnome.system.locale region "hc_IL.utf8"
Validating the New Settings
The last step is to validate that everything works as expected. To reload all the settings the easiest for me was to reboot.
Note: Everything was tested on Fedora 21 with GNOME 3.14. Other Linux distributions may require additional or different steps.
Please comment if you find any issues with the instructions.
That is because a starting X session never reads your ~/.bashrc
and ~/.profile
. Usually, the desktop manager is started as root or its own user from an init script. The resulting process usually has the environment of the init process when it hits the desktop manager starting script. (I will not talk about less established init implementations at this point.)
After login it spawns a child process, which inherits just that environment. The child process drops privileges to your uid and runs /etc/X11/Xsession
, which usually simply runs all the scripts in /etc/X11/Xsession.d
. These scripts usually either set environment variables, or, specifically modify the invocation of the desktop environment.
In that directory you may find a file like 40x11-common_xsessionrc
on Debian systems, which sources your ~/.xsessionrc
. The last file in /etc/X11/Xsession.d
will start your desktop environment. All your GUI processes will be spawned from this process, thus inherit the environment set up through /etc/X11/Xsession.d
and consequently your ~/.xsessionrc
.
~/.xsessionrc
is a script file, which may source ~/.bashrc
but that's really bad style, because then your DE sources it, the terminal process inherits that environment and then bash sources ~/.bashrc
again, which may have unwanted side effects.
However, it is totally acceptible to have a ~/.myenvironmentvariables
, which contains stricly (environment) variable definitions and is sourced by ~/.bashrc
and ~/.xsessionrc
. If you do that, all your processes will inherit the variables specified in ~/.myenvironmentvariables
, especially the shell scripts you double click in Nautilus.
Best Answer
According to Ubuntu's Wiki on Environment Variables either in
~/.pam_environment
or in/etc/environment
, depending on what you want it for all users, or just your user.And