I've created my own custom locale
s and placed them in /etc/locale.conf
which successfully takes effect if I log in on a virtual console (Ctrl+Alt+F2). In my Gnome3 session those variables are not set, though. For terminal applications I could just place them in the .bashrc
but that won't help me with graphical applications like Thunderbird and Pidgin.
I have tried to follow these hints: Locale settings in shell initialization not used by GNOME session and even emulated the bug in Locale – ArchWiki by creating a .pam_environment
file, but the locale
s are still those set by Gnome3. There is a configuration dialogue in the Gnome settings but it only allows to set a very limited set of predefined locale
combinations and no way to customize them.
The relevant files in my home directory:
user@localhost:~$ ls -lah .dmrc .pam_environment .session .xsession .xsessionrc
lrwxrwxrwx. 1 user user 16 12. Jun 08:57 .dmrc -> /etc/locale.conf
lrwxrwxrwx. 1 user user 16 11. Jun 20:23 .pam_environment -> /etc/locale.conf
lrwxrwxrwx. 1 user user 16 12. Jun 09:09 .session -> /etc/locale.conf
lrwxrwxrwx. 1 user user 16 12. Jun 09:07 .xsession -> /etc/locale.conf
lrwxrwxrwx. 1 user user 9 13. Jun 11:22 .xsessionrc -> .xsession
-rw-rw-r--. 1 user user 66 13. Jun 11:13 .profile
user@localhost:~$ cat .profile
source /etc/locale.conf
The contents of /etc/locale.conf
:
LANG="en_US.utf8"
LC_TIME="de_MY.utf8" # NB: de_MY
LC_MONETARY="de_DE.utf8"
LC_PAPER="de_DE.utf8"
LC_NAME="de_DE.utf8"
LC_ADDRESS="de_DE.utf8"
LC_TELEPHONE="de_DE.utf8"
LC_MEASUREMENT="de_DE.utf8"
LC_IDENTIFICATION="de_DE.utf8"
Does anyone know how to set custom locale
s in Gnome3 ?
Best Answer
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:
To see the current locale status we can run:
GNOME Settings
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 inorg.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
andfirst_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: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 fromhe_IL
and on the way replace all the occurrences of a string he_IL inside the file with 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):For those who haven't chosen their favorite editor yet and vim is not their cup of tea, can use gedit :)
The file structure is not very complicated. Essentially, it is constructed from sections. From locale(5) man pages:
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:
The complete documentation on a locale definition file can be accessed via:
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
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:
The rest of the categories I left as they are or replaced their content with the copy directive as in:
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: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: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 withLC_
to your new locale. For example:GNOME Settings
To activate the new locale in GNOME run the following command. Replace
hc_IL
with your locale: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.
Use GNOME Shell and locale dependent applications (graphical and console) and check that they behave as expected with the new locale. E.g. if you customized LC_TIME you can run the
date
command to validate the date format: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.