Difference between revisions of "Locale"

From ArchWiki
Jump to: navigation, search
m (Added link to czech version)
(Complete redo of this HOWTO. More structured, some information added.)
Line 2: Line 2:
 
[[Category:HOWTOs (English)]]
 
[[Category:HOWTOs (English)]]
 
{{i18n_links_start}}
 
{{i18n_links_start}}
 +
{{i18n_entry|Deutsch|Locales konfigurieren}}
 
{{i18n_entry|English|Configuring locales}}
 
{{i18n_entry|English|Configuring locales}}
 
{{i18n_entry|Česky|Nastavení locales}}
 
{{i18n_entry|Česky|Nastavení locales}}
 
{{i18n_entry|Українська|Локаль}}
 
{{i18n_entry|Українська|Локаль}}
 
{{i18n_links_end}}
 
{{i18n_links_end}}
Configuring (adding and removing) locales is a breeze. As super user, edit <code>/etc/locale.gen</code>, uncommenting (removing "#" from the beginning of appropriate lines) the locales you require. Then, run <code>locale-gen</code>. If you now run <code>locale -a</code>, you should see the locales you have specified.
+
==Introduction==
 +
Locales are used in Linux to define which language the user uses. As the locales define the charset which the user uses as well, setting up the correct locale is especially important if the language contains non-ASCII characters.
  
For your locale to come into effect, you must set it in <tt>/etc/rc.conf</tt>. Pick the desired locale from your earlier <tt>locale -a</tt> output and edit the default setting of
+
Locales are defined as following:
 +
[language[_territory][.codeset][@modifier]]
 +
 
 +
In this howto we're setting up a system that uses the en_US.UTF-8 locale, but you can follow this article easily if you want to setup another locale.
 +
 
 +
==Enabling necessary locales==
 +
First you have to enable the locales you want being supported by your system. To enable or disable them, the file '''/etc/locale.gen''' is used. It contains every locale you can enable, and you have just to uncomment lines you want to do so.
 +
 
 +
As we want to setup an english UTF-8 conform system, we want to enable en_US.UTF-8. But for compatibility to programs that don't support UTF-8 yet, it's recommended to support any other locale, prefixed with en_US as well. Having this in mind, we enable this set of locales:
 +
en_US.UTF8    UTF-8
 +
en_US  ISO-8859-1
 +
 
 +
After you've enabled the necessary locales, you have to run locale-gen as root to update them:
 +
# locale-gen
 +
Generating locales...
 +
  en_US.UTF-8... done
 +
  en_US.ISO-8859-1... done
 +
Generation complete.
 +
 
 +
'''Note:''' Though it's most likely just one language you use on your computer it can be helpful or even necessary to enable other locales as well. For example if you're running a multi-user system with users that don't speak en_US, they won't be happy until their individual locale is at least supported by your system.
 +
 
 +
==Setting system wide locale==
 +
To define which locale should be used by the system, you can easily add your locale to your '''/etc/rc.conf''' file. As we've just added ISO-8859 support just for (backward-)compability, we add en_US.utf-8 here:
 
  LOCALE="en_US.utf8"
 
  LOCALE="en_US.utf8"
  
 +
The system wide locale will be updated after rebooting your computer.
 +
 +
==Setting per user locale==
 +
As we discussed earlier, some users might want to define a different locale than the system ones.
 +
In this case, you can export LC_ALL in your '''~/.bashrc'''.
 +
For example you can use the en_US.iso8859 locale, though there is not advance of using it.
 +
export LC_ALL=en_US.iso8859
 +
 +
Your locales will be updated as soon as you re-source your ~/.bashrc. This happens on login or alternatively you can type:
 +
source ~/.bashrc
 +
 +
==Troubleshooting==
 +
===How can I obtain the available locale names?===
 +
You can get the correct names of all available locales with this command:
 +
locale -a
 +
===How can I see which locale I am using?===
 +
Which locale is currently in use is viewable simply by typing:
 +
locale
 +
===My terminal doesn't support UTF-8 characters===
 +
Unfortunately some terminals don't support UTF-8. In this case, you have to use different terminal.
  
This is a system-wide setting, so if you have multiple users on your machine, they might prefer to set their own locale in a login script, for example <tt>.bashrc</tt>. Just add
+
'''List of terminals that support UTF-8:'''
export LANG="de_DE@euro"
+
* gnome-terminal
... for example.
+
* gnustep-terminal
 +
* mlterm
 +
* urxvt (rxvt-unicode)
 +
* xfce-terminal
 +
* xterm
 +
'''Note:''' This list may be incomplete.
  
Configuring a locale will allow some terminals (such as xterm) to display non-Latin characters properly. If you need bidirectional support (required for Arabic and Hebrew, for instance), consider installing [[mlterm]].
+
===xterm doesn't support UTF-8 characters for me===
 +
xterm only supports UTF-8 if you run it as uxterm or xterm -u8.

Revision as of 12:42, 21 August 2007

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Introduction

Locales are used in Linux to define which language the user uses. As the locales define the charset which the user uses as well, setting up the correct locale is especially important if the language contains non-ASCII characters.

Locales are defined as following:

[language[_territory][.codeset][@modifier]]

In this howto we're setting up a system that uses the en_US.UTF-8 locale, but you can follow this article easily if you want to setup another locale.

Enabling necessary locales

First you have to enable the locales you want being supported by your system. To enable or disable them, the file /etc/locale.gen is used. It contains every locale you can enable, and you have just to uncomment lines you want to do so.

As we want to setup an english UTF-8 conform system, we want to enable en_US.UTF-8. But for compatibility to programs that don't support UTF-8 yet, it's recommended to support any other locale, prefixed with en_US as well. Having this in mind, we enable this set of locales:

en_US.UTF8    UTF-8
en_US  ISO-8859-1

After you've enabled the necessary locales, you have to run locale-gen as root to update them:

# locale-gen
Generating locales...
  en_US.UTF-8... done
  en_US.ISO-8859-1... done
Generation complete.

Note: Though it's most likely just one language you use on your computer it can be helpful or even necessary to enable other locales as well. For example if you're running a multi-user system with users that don't speak en_US, they won't be happy until their individual locale is at least supported by your system.

Setting system wide locale

To define which locale should be used by the system, you can easily add your locale to your /etc/rc.conf file. As we've just added ISO-8859 support just for (backward-)compability, we add en_US.utf-8 here:

LOCALE="en_US.utf8"

The system wide locale will be updated after rebooting your computer.

Setting per user locale

As we discussed earlier, some users might want to define a different locale than the system ones. In this case, you can export LC_ALL in your ~/.bashrc. For example you can use the en_US.iso8859 locale, though there is not advance of using it.

export LC_ALL=en_US.iso8859

Your locales will be updated as soon as you re-source your ~/.bashrc. This happens on login or alternatively you can type:

source ~/.bashrc

Troubleshooting

How can I obtain the available locale names?

You can get the correct names of all available locales with this command:

locale -a

How can I see which locale I am using?

Which locale is currently in use is viewable simply by typing:

locale

My terminal doesn't support UTF-8 characters

Unfortunately some terminals don't support UTF-8. In this case, you have to use different terminal.

List of terminals that support UTF-8:

  • gnome-terminal
  • gnustep-terminal
  • mlterm
  • urxvt (rxvt-unicode)
  • xfce-terminal
  • xterm

Note: This list may be incomplete.

xterm doesn't support UTF-8 characters for me

xterm only supports UTF-8 if you run it as uxterm or xterm -u8.