How to get current or set wanted regional format in the terminal?

17,535

Solution 1

Regional Formats changes the following variables:

LC_NUMERIC
LC_TIME
LC_MONETARY

You can use locale to check the current set format.

ron@ron:~$ locale
LANG=en_US
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=

If you want to see all the locale available in your system you can use:

ron@ron:~$ locale -a
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8

To change, for example, the date format to US you can use:

LC_TIME=en_US.UTF-8 

To change it permanently:

sudo update-locale LC_TIME=en_US.UTF-8

You can also manually edit the file /etc/default/locale instead of update-locale, if you wish so. Changes will be applied the next time you log-in.

Refer to Locale - Community Help Wiki for more details. man 5 locale will you more options to find-tune any of the formats.

Solution 2

This command sets regional formats to en_US.UTF-8 in the same manner as Language Support:

dbus-send --print-reply --system --dest=org.freedesktop.Accounts /org/freedesktop/Accounts/User$UID org.freedesktop.Accounts.User.SetFormatsLocale string:'en_US.UTF-8'

It updates your user setting in accountsservice and the file ~/.pam_environment.

/etc/default/locale is updated by Language Support only if you click the Apply System-Wide button.

Haven't figured out the corresponding command to check the current format.

Can't help wondering why you want to do it. It's normally not a good idea to mess with these settings manually on an Ubuntu deskop. Language Support does the right thing.

Solution 3

You could check the LANGUAGE variable in your shell with:

echo $LANGUAGE

The output for my system running GB English is:

en_GB:en
Share:
17,535

Related videos on Youtube

Gertjan
Author by

Gertjan

C++, OpenCV, Matlab, Ubuntu

Updated on September 18, 2022

Comments

  • Gertjan
    Gertjan over 1 year

    I'm looking for single line terminal commands to:

    • check my current regional format or
    • set the regional format to English US.

    Currently to change this I have to go to Settings->Language Support->Regional Formats

    (Distro: Ubuntu 14.04 LTS, should preferably also work in 16.04 LTS)

    • rll
      rll almost 8 years
      I don't know why you ask this, but in my case I need to know because the language support freezes when I try to change the regional formats.
  • Gertjan
    Gertjan about 8 years
    Thanks. I noticed some strange behavior: initially all the variables in /etc/default/locale were set to nl_BE.UTF-8 except LANG, which was set to en_US.UTF-8. The command sudo update-locale LC_TIME=en_US.UTF-8 did what I expected. But when I tried to set the regional format in the Ubuntu settings window, locale was still the same as before.
  • Gunnar Hjalmarsson
    Gunnar Hjalmarsson about 8 years
    There are more variables than those you mention which are changed when you set Regional Format via Language Support.
  • Gertjan
    Gertjan about 8 years
    Why: 1) I like the terminal, 2) I had a problem with a third party xml parser that didn't parse floating points correctly because of the dot/comma difference for numeric notations. Changing the regional format for LC_NUMERIC from nl_BE to en_US fixed it