Locale settings: Difference between revisions

From HPCwiki
Jump to navigation Jump to search
No edit summary
Tag: Manual revert
Phase 1 § 5 P1.5.4: style polish — drop leading = title =, convert indented-code to syntaxhighlight, remove first-person example, add sections + See also (via update-page on MediaWiki MCP Server)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
= How to change language settings =
Locale settings control how Linux presents language-dependent things: the language of prompts and error messages, how dates, numbers and currency are formatted, and how "special" characters are handled.


Language settings are used within Linux to decide things like the language of prompts, date and monetary settings, and how to handle "special" characters.
Because Anunna is used by people with many different backgrounds, the cluster sets no default locale — the operating system's own defaults apply, so everything works out of the box. If you want different behaviour, set your preferred locale yourself. Put the settings in your <code>~/.bashrc</code>, and also inside any job scripts, since scripts do not normally read your <code>~/.bashrc</code>.


As the HPC is used by people with very diverse backgrounds, we do not set a default setting for this.
== Seeing the current settings ==
Of course, the OS still has defaults, so everything still works.


If you want to change the default, the best way is to add your preferred setting to your .bashrc, and also to run scripts, as they usually don't load your .bashrc .
To list the locale categories and the value each currently uses:


To see the available categories and the language they use, use this:
<syntaxhighlight lang="bash">
locale
locale
To see the available language options, use this:
</syntaxhighlight>
locale -a
As you saw, there are two main categories, '''LANG''' and '''LC_*'''.
If you want to change them, you will have to change them separately, like this:
export LANG=nl_NL.utf8
export LC_ALL=nl_NL.utf8


After the above, you will have error messages in Dutch, and the currency symbol will be the Euro sign.
To list the locales available on the system:
To see what the active settings are for a certain category, you can (e.g. MONETARY) do this:
 
locale -k LC_MONETARY
<syntaxhighlight lang="bash">
locale -a
</syntaxhighlight>
 
To see the detailed keywords of one category (for example monetary formatting):
 
<syntaxhighlight lang="bash">
locale -k LC_MONETARY
</syntaxhighlight>
 
There are two kinds of setting: <code>LANG</code>, the overall default, and the individual <code>LC_*</code> category variables (such as <code>LC_NUMERIC</code> or <code>LC_TIME</code>) that override <code>LANG</code> for one category each.
 
== Changing your locale ==
 
Set <code>LANG</code> (and optionally <code>LC_ALL</code>, which forces every category at once):
 
<syntaxhighlight lang="bash">
export LANG=nl_NL.utf8
export LC_ALL=nl_NL.utf8
</syntaxhighlight>
 
After this you would get error messages in Dutch and the euro sign as the currency symbol.
 
Note that <code>LC_ALL</code> overrides everything else, so leave it unset if you want to mix categories (see below).
 
== Mixing categories ==
 
A common wish is to mix locales — for example English-language messages but Danish date and number formatting (which gives unambiguous <code>YYYY-MM-DD</code> dates), with an Irish locale for the decimal separator so numbers use a dot. Because <code>LC_ALL</code> overrides individual categories, first clear it, set a base for all categories, then override the few you want:
 
<syntaxhighlight lang="bash">
# LC_ALL overrides per-category settings, so clear it first
unset LC_ALL
 
# Set every category to English with Danish conventions (e.g. correct dates)
for item in $(locale | grep LC | grep -v LC_ALL | cut -f1 -d'='); do
  export ${item}=en_DK.UTF-8
done
 
# Override numeric and monetary formatting to get a dot as the decimal separator
export LC_NUMERIC=en_IE.utf8
export LC_MONETARY=en_IE.utf8
</syntaxhighlight>
 
With that in place, <code>locale</code> reports a mixed setup like:
 
<syntaxhighlight lang="text">
LANG=en_IE.UTF-8
LANGUAGE=
LC_CTYPE=en_DK.UTF-8
LC_NUMERIC=en_IE.UTF-8
LC_TIME=en_DK.UTF-8
LC_COLLATE=en_DK.UTF-8
LC_MONETARY=en_IE.UTF-8
LC_MESSAGES=en_DK.UTF-8
LC_PAPER=en_DK.UTF-8
LC_NAME=nl_NL.utf8
LC_ADDRESS=nl_NL.utf8
LC_TELEPHONE=nl_NL.utf8
LC_MEASUREMENT=en_DK.UTF-8
LC_IDENTIFICATION=en_DK.UTF-8
LC_ALL=
</syntaxhighlight>
 
== See also ==
 
* [[Installing Personal Software]]

Latest revision as of 13:45, 16 June 2026

Locale settings control how Linux presents language-dependent things: the language of prompts and error messages, how dates, numbers and currency are formatted, and how "special" characters are handled.

Because Anunna is used by people with many different backgrounds, the cluster sets no default locale — the operating system's own defaults apply, so everything works out of the box. If you want different behaviour, set your preferred locale yourself. Put the settings in your ~/.bashrc, and also inside any job scripts, since scripts do not normally read your ~/.bashrc.

Seeing the current settings

To list the locale categories and the value each currently uses:

locale

To list the locales available on the system:

locale -a

To see the detailed keywords of one category (for example monetary formatting):

locale -k LC_MONETARY

There are two kinds of setting: LANG, the overall default, and the individual LC_* category variables (such as LC_NUMERIC or LC_TIME) that override LANG for one category each.

Changing your locale

Set LANG (and optionally LC_ALL, which forces every category at once):

export LANG=nl_NL.utf8
export LC_ALL=nl_NL.utf8

After this you would get error messages in Dutch and the euro sign as the currency symbol.

Note that LC_ALL overrides everything else, so leave it unset if you want to mix categories (see below).

Mixing categories

A common wish is to mix locales — for example English-language messages but Danish date and number formatting (which gives unambiguous YYYY-MM-DD dates), with an Irish locale for the decimal separator so numbers use a dot. Because LC_ALL overrides individual categories, first clear it, set a base for all categories, then override the few you want:

# LC_ALL overrides per-category settings, so clear it first
unset LC_ALL

# Set every category to English with Danish conventions (e.g. correct dates)
for item in $(locale | grep LC | grep -v LC_ALL | cut -f1 -d'='); do
  export ${item}=en_DK.UTF-8
done

# Override numeric and monetary formatting to get a dot as the decimal separator
export LC_NUMERIC=en_IE.utf8
export LC_MONETARY=en_IE.utf8

With that in place, locale reports a mixed setup like:

LANG=en_IE.UTF-8
LANGUAGE=
LC_CTYPE=en_DK.UTF-8
LC_NUMERIC=en_IE.UTF-8
LC_TIME=en_DK.UTF-8
LC_COLLATE=en_DK.UTF-8
LC_MONETARY=en_IE.UTF-8
LC_MESSAGES=en_DK.UTF-8
LC_PAPER=en_DK.UTF-8
LC_NAME=nl_NL.utf8
LC_ADDRESS=nl_NL.utf8
LC_TELEPHONE=nl_NL.utf8
LC_MEASUREMENT=en_DK.UTF-8
LC_IDENTIFICATION=en_DK.UTF-8
LC_ALL=

See also