Switch command output language from native language to english

How can I switch the command output language from my native language to English, so I can post my Ask Ubuntu question with English command output (error messages)?

4

9 Answers

export LC_ALL=C is enough. All subsequent command output will be in English.

More information: What does "LC_ALL=C" do?

If you want to revert to the native language, unset the LC_ALL variable:

unset LC_ALL
3

bash function for terminal

Here is my bash function to switch between DE and EN locales.

You may extend this code with your preferred languages. To use this, put it in your ~/.bashrc (or ~/.bash_profile)-

Call it with _configure_locale EN to switch to English.

function _configure_locale() { # [profile] local profile=${1:-EN} case ${profile} in DE|DE_DE|de_DE) LC_ALL="de_DE.UTF-8" LANG="de_DE.UTF-8" LANGUAGE="de_DE:de:en_US:en" ;; EN|EN_US|en|en_US) LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8" LANGUAGE="en_US:en" ;; *) echo "ALERT" "${FUNCNAME}: unknown profile '${profile}'" ;; esac LC_PAPER="de_DE.UTF-8"; # independent from locale LESSCHARSET="utf-8"; # independent from locale MM_CHARSET="utf-8" # independent from locale echo "locale settings" "${LANG}"; export LC_ALL LANG LANGUAGE LC_PAPER LESSCHARSET MM_CHARSET
}

In general I suggest to change all 3 environment variables LC_ALL, LANG, LANGUAGE to avoid misbehaviours of some programs.

Adapting to your language

Extending the code to your native language is quite simple. You can find the needed values by invoking the following command

env |egrep -e 'LC_ALL|LANG'
3

Open a terminal Ctrl+Alt+T and type:

LANG=en_US.UTF-8 bash

or:

LC_ALL=C bash

Now the terminal output is in english language. You can check it with locale.

It is possible to make a command to do that with a permanent alias. Open the .bashrc file with your preferred editor and put the following code in there:

alias basheng='LANG=en_US.UTF-8 bash'

or:

alias basheng='LC_ALL=C bash'

Restart the Bash shell. Now you have the command basheng. Type it in the Bash to get an english Bash shell. To leave the english shell type exit.

Source:

4

This is configured via locale settings, which can be set via environment variable. There are four layers of variables; the first one that is set takes precedence:

  • LANGUAGE — don't use it, it's rarely useful and can cause bugs. Unfortunately, some versions of Ubuntu set it, so you may need to unset it.
  • LC_ALL — overrides category-specific settings, meant primarily to be used by programs that want to run in the default locale. Not meant to be used as global settings.
  • Category-specific variables beginning with LC_: LC_CTYPE, LC_MESSAGES, LC_TIME, ….
  • LANG — sets the default locale for all categories, meant to be used in a global user settings.

The “plain” locale, with all messages untranslated, default time and number formats, ASCII as the character set, etc. is called C. This locale is present on every system.

Thus, to run a program with messages in English, run

unset LANGUAGE; LC_MESSAGES=C myprogram --option

or

unset LANGUAGE
export LC_MESSAGES=C
myprogram --option
myotherprogram

To run a program with all localization turned off, run

env -u LANGUAGE LC_ALL=C myprogram --option

but beware that this switches the character encoding to ASCII (so no Unicode, latin-1, etc.).

See What should I set my locale to and what are the implications of doing so? for a more detailed overview of locales.

7

in your ~/.bashrc

unset LC_ALL
export LC_MESSAGES=C

then

source ~/.bashrc

Check it

$ locale
LANG=pl_PL.utf8
LANGUAGE=
LC_CTYPE="pl_PL.utf8"
LC_NUMERIC="pl_PL.utf8"
LC_TIME="pl_PL.utf8"
LC_COLLATE="pl_PL.utf8"
LC_MONETARY="pl_PL.utf8"
LC_MESSAGES=C
LC_PAPER="pl_PL.utf8"
LC_NAME="pl_PL.utf8"
LC_ADDRESS="pl_PL.utf8"
LC_TELEPHONE="pl_PL.utf8"
LC_MEASUREMENT="pl_PL.utf8"
LC_IDENTIFICATION="pl_PL.utf8"
LC_ALL=

Why unset first?

LC_ALL Overrides individual LC_* settings: if LC_ALL is set, none of the below have any effect.

2

Easiest way is to open the terminal by pressing Alt+F2 and running this command:

env LANGUAGE=en gnome-terminal

Related bug to language change/switching settings in Fedora(30) ex: ENG to Native to ENG

There is env variable that doesn't change back to EN, namely for example from Bulgarian (bg). Example:

# LANGUAGE=en_GB:bg

has to change to:

# LANGUAGE=en_GB:en

Solution(remove # and execute):

# export LANGUAGE=en_GB:en
  1. Click on the gear icon on the left (system settings on Unity panel)
  2. Click on Language Support
  3. Select Regional Formats
  4. Set your "Display numbers, dates, and currency amount ..." to English.
  5. Logout the session and Login again (Required!)

Done.

To change the terminal language to English permanently, use:

echo 'export LANG=C' >> ~/.bashrc && exec "$BASH"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like