How to change the encoding in Ubuntu

Say we wish to change the locale to Spanish UTF-8, what do we need to do?

Step 1: List the available/installed locales in the system:

bash$> locale -a

As you can observe, there is no Spanish locale installed, so we will first need to generate/compile it. The reason why not all locales are installed is to save space. Each locale approximately occupies 50MB,  and since most users only need a few locales, it would be a huge loss of space to install them all..

Step 2: Install the locale Since the locale we want to set is not installed on our system, we need to install it.

bash$> /usr/sbin/locale-gen es_ES.UTF-8

Generating locales… es_ES.UTF-8… done Generation complete.

Note: To know which locales you can generate, take a look at the file /usr/share/i18n/SUPPORTED. I.e:

es_ES.UTF-8 #UTF-8
es_ES # ISO-8859-1

After installing the locale, it should now be available on our system:

bash$> locale -a

Step 3: Update the locale

bash$> /usr/sbin/update-locale LANG=es_ES.UTF-8

This actually only changes the contents of /etc/default/locale. You might as well update that file  manually to change the encoding.

Step 4: Open a new terminal / log in again

bash$> locale
LANG=es_ES.UTF-8 # Default value used in case one of below is not set
LC_CTYPE=”es_ES.UTF-8″ # Character encoding to be used
LC_NUMERIC=”es_ES.UTF-8″ # How to format numbers. I.e decimal separator as dot or comma.
LC_TIME=”es_ES.UTF-8″ # How to format date and time. For example 12 or 24 hour clock
LC_COLLATE=”es_ES.UTF-8″ # Defines how strings are alphabetically sorted.
LC_MONETARY=”es_ES.UTF-8″ # The currency (name and symbol) for the selected country
LC_MESSAGES=”es_ES.UTF-8″ # Language in which the messages (terminal) should be printed
LC_PAPER=”es_ES.UTF-8″ # Paper formats for the country
LC_NAME=”es_ES.UTF-8″ # How names or persons are formatted (firstname lastname)
LC_ADDRESS=”es_ES.UTF-8″ # Format of addresses
LC_TELEPHONE=”es_ES.UTF-8″ # Idem for telephones
LC_MEASUREMENT=”es_ES.UTF-8″ # Defines whether to use pounds, kilograms, etc
LC_IDENTIFICATION=”es_ES.UTF-8″ # Nobody knows!
LC_ALL= # Overrides all the previous!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s