Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

At System Administration Language support Text. I can only choose standard locales, but I would like to fine-tune. For example in Windows I could customise things like time and date format, measure units, decimal separator, currency, etc manually - how can I do this in Ubuntu?

share|improve this question
add comment

2 Answers 2

Not sure what kind of customization you want, but you can set some locale variables using your ~/.locale. For example, to get english messages but german time and the likes I use

export LC_ALL=""
export LANG="en_GB.utf8"
export LC_CTYPE="de_DE.utf8"
export LC_NUMERIC="de_DE.utf8"
export LC_TIME="de_DE.utf8"
export LC_COLLATE="de_DE.utf8"
export LC_MONETARY="de_DE.utf8"
export LC_MESSAGES="en_GB.utf8"
export LC_PAPER="de_DE.utf8"
export LC_NAME="en_GB.utf8"
export LC_ADDRESS="de_DE.utf8"
export LC_TELEPHONE="de_DE.utf8"
export LC_MEASUREMENT="de_DE.utf8"
export LC_IDENTIFICATION="de_DE.utf8"

Generating custom locales is also possible. See e.g. this guide for dates.

share|improve this answer
    
No, I want lower level customization. For example: English messages, metric units, modified Czech date/time (DD.MM.YYYY HH:mm instead of D.M.YYYY H.MM), a dot as a decimal separator (there is a comma for this in Czech locale) and € as the currency (there is Kč currency in Czech locale). –  Ivan Jan 13 '11 at 9:20
    
I see. Taking en_US for LC_NUMERIC and de_DE for LC_MONETARY and LC_MEASUREMENT gives you other side effects? See also the new link for generating a personal locale. –  Carsten Thiel Jan 13 '11 at 11:03
    
the instructions behind the Link seem to answer the question wonderfully, maybe you could replicate the most important bits here, in case the link isn't reachable some day? –  Stefano Palazzo Jan 13 '11 at 14:04
add comment

This answer will demonstrate how to fully customize a locale, optionally using an existing locale as a base. The type of locale that will be used in this answer is the i18n type; such type of locale will be implied in every mention of the word "locale" in the body of the answer.

Find a guide

The first thing you need to customize a locale, is get to know the format of the locale. This web locale editor has a comprehensive description of every field in a locale, despite not being usable by just anyone in a right-away manner. This will be the guide to use.

Needed tools

The only tools you need to work with locales are

  1. A text editor. Any will do, though VIM will excell.
  2. A text-to-unicode converter. It would be most expected that you didn't have one, so I will provide you with a simple one. Read the next subsection to obtain it.

I recommend you to create a directory and save everything related with the work you will do on the locale to it.

Text-to-unicode converter (encodestr)

NOTE: if you are using non-common characters you may have problems with the script I write below; you might want to take a look at the alternative scripts linked by nass.

Save the following code to a file. This file will be identified by your system as a python script, which is alright because it is one. This guide assumes you called the script encodestr.

#!/usr/bin/python

def encode(string):
    newstring = str()
    for ch in string:
        newstring += "<U%04X>" % ord(ch)
    return newstring

if __name__ == '__main__':
    import sys
    print encode(sys.argv[1])

After you have saved it, give the file execution permission - this will come in handy. You can do that using nautilus, or by running from a terminal the following command, on the directory in which you saved the script: chmod +x encodestr.

You can now test this script by running on the same directory: ./encodestr hello. You should get an output equal to <U0068><U0065><U006C><U006C><U006F>.

Modify an existing locale

Modifying an existing locale is the easiest case, as ideally you will pick a locale that fits your needs almost totally, in which case you need to make only small modifications. To tailor it, you can use the guide to know which of the sections are the ones you want to change, and how you can change them. All the installed locales reside in /usr/share/i18n/locales, however the guide contains pretty much every locale ever created.

However, the first thing you will notice when you open a locale is that you will read english words as much as weird <UXXXX> codes. You will need to be able to create these codes - this is where the encodestr script comes.

When you know which sections you have to change, you need to know each field contained in the section.

For example, the LC_TIME section contains the field t_fmt, and many others. Each field has its own description on the guide.

Now that you know which fields to modify, use the guide again to find out what values does the field accept.

For example, the field t_fmt accepts text and the common strfmt variables.

Just when you know what to write on the fields you want to modify, run the text through the encodestr script to get its encoded equivalent.

NOTE: Not every field needs to be encoded, use an existing locale as a reference if needed.

For example, if you want to have the time format Time: %T in the t_fmt field, run ./encodestr "Time: %T"; this will return <U0054><U0069><U006D><U0065><U003A><U0020><U0025><U0054> and so you will have the line t_fmt <U0054><U0069><U006D><U0065><U003A><U0020><U0025><U0054> in your locale (in it's respective section, of course).

After you have modified every field you wanted to, you will need to proceed to install the locale to the system, so it can be used. Proceed to the installation section for this.

Creating a locale from scratch

As opposed to modifying one, the other method you can use to create your custom locale is working on it from scratch. This is not very difficult if - again - you use the guide. Here's a useful tip though: you can copy sections from other locales without actual copy and paste methods. You just have to follow this format:

LC_SECTION
copy "locale"
END LC_SECTION

Where LC_SECTION is the section you want to modify, and locale is the locale you want to copy that section from.

For example, if you want to copy the time format in the English locale, you would have this text your custom locale file:

LC_TIME
copy "en_GB"
END LC_TIME

And that saves you a lot of work and assures that any change made to the referenced locale will be mirrored to yours.

Installing your custom locale

The steps I am going to show below may not be optimal, but work.

  1. Compile your locale. Don't panic! This takes no time. Just run the command sudo localedef -i custom -f UTF-8 custom.UTF-8 -c -v where custom is the name of your locale.

  2. Copy your locale to the /usr/share/i18n/locales/ directory. You will definitely need sudo priviledges to do this, and you can do it with the command sudo cp locale /usr/share/i18n/locales/ where locale is the filename of your custom locale.

  3. Run the magic command. I actually don't know what exactly this command does, but it is crucial. Run sudo locale-gen. It is most probable it generates references to the available locales where needed.

  4. Tell your system to use the locale. If you want the locale to be used on a system-wide manner, modify the /etc/environment file. If not, you can modify your ~/.profile file, or any other one that is sourced at startup. If you don't know what the latter means don't worry, just use the ~/.profile file. To know what you have to write in it, first run the locale command. It should issue a list with items like LANGUAGE, LC_MESSAGES, LC_CTYPE and many others. You will write, for each of the sections you want (listed by the previous command), on separate lines, this SECTION="locale" where SECTION is the section and locale the name of your custom locale.

For example, if you want to use the time format from the Netherlands, but the english language, write:

LANGUAGE="en_GB:en"
LC_TIME="nl_NL"

NOTE: If you want to use one locale for every locale setting, write LC_ALL="locale" where locale is the name of your custom locale. If you want to use a locale for everything but for the language, you can write LANG="locale" and (on another line, of course) LANGUAGE="locale":XX where XX is the 2 letter code for the language you want.

For example, if you want to use the Dutch locale and the English language, you could use:

LANG="nl_NL"
LANGUAGE="nl_NL:en"

You have finished

The next time you log in, your locale should be in use. You can test this by running the locale command again.

Please comment about inconsistencies or false statements in this guide!

share|improve this answer
    
Hi there, The python code you use, does not work for all cases. For greek chars πμ, it outputs <U00CF><U0080><U00CE><U00BC>, instead of the expected characters <U03C0><U03BC>. Here is a link that works. –  nass Aug 29 '13 at 18:26
    
Thanks for your input! I have included your comment in the text where it was due :) –  Wolter Hellmund Aug 29 '13 at 19:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.