110

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
  • 5
    This is somewhat misleading. It is not actually necessary for people to do this. (If you think we should require OPs to burden themselves this way, please post on meta before instructing anyone to do so.) They can change LANG like this, and it might help, but we do not require copied error messages to be in English. We require what the author has written to be in English (though we usually translate it instead of closing questions). So a question written in English with Spanish terminal text is fine, while a question written in Spanish with English terminal text is not. Mar 5, 2013 at 13:49
  • 5
    @EliahKagan yes, you are right, but anyway I think it is useful.
    – BuZZ-dEE
    Mar 5, 2013 at 13:54
  • 2
    I agree, it is useful for people to be able to do this, and good you've posted this question! However, it's important people know we don't require them to do this (but do require that questions and answers themselves be written in English). Mar 5, 2013 at 13:56
  • 9
    @EliahKagan On the contrary, it is very important to post actual error messages, and highly preferable to post them in English because that's what the main audience of this site can recognize and test. (And never, ever post a re-translated error message. Always copy-paste, because the exact wording, punctuation, even spacing can be significant.) Nov 3, 2014 at 19:45

9 Answers 9

112

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
4
  • 1
    Thats is problematic if you may want have output in other language than english. I did not be able to use any accentued character after this setting. askubuntu.com/a/818241/227400 was better.
    – Maïeul
    Jun 7, 2020 at 13:59
  • 1
    It stops working after you close Konsole and open a new one. The new Konsole is in the old (non-English) language
    – parsecer
    Aug 21, 2021 at 3:20
  • See rofrol 's answer below for permanent solution
    – parsecer
    Aug 21, 2021 at 3:23
  • just put export LC_ALL=C into your ~/.bashrc file for applying permanent changes
    – cestpasmoi
    Jan 24 at 11:03
15

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
  • The script needs changing for another language than German (DE)? I search for a solution independent from the native language.
    – BuZZ-dEE
    Mar 5, 2013 at 23:48
  • @BuZZ-dEE: You can (and probably should) easily adapt this by throwing out the case and specifying the input to conform to the <lang>_<country> format. Then you can just pass it through, assuming UTF-8. If you're really keen on a tidy solution, you should probably check the user input against locale -a to make sure the requested locale is actually installed.
    – bitmask
    Mar 6, 2013 at 0:30
  • @buzz-dee: see updated answer Mar 6, 2013 at 16:27
12

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
  • Setting LANG is not sufficient to chance all output.
    – bitmask
    Mar 5, 2013 at 19:12
  • @bitmask is this: LANG=en_US.UTF-8 && LC_ALL=en_US.UTF-8 && LANGUAGE=en_US.UTF-8 bash better?
    – BuZZ-dEE
    Mar 5, 2013 at 23:46
  • 2
    Actually, that should be LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8 $SHELL.
    – bitmask
    Mar 6, 2013 at 0:27
  • Only LC_ALL=C bash work for me.
    – liquide
    May 27, 2016 at 10:00
6

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
  • Don't use LANGUAGE?? I don't know which OS you are on, but on Ubuntu LANGUAGE is used by default all the time via the installer and various GUIs. Which bugs are those, btw? I also read the answer you linked to, and even if it contains useful general info, the recommendation is simply not good advice on an Ubuntu desktop. Nov 2, 2014 at 16:04
  • @GunnarHjalmarsson The main problem with LANGUAGE is that it takes precedence over LC_ALL, which causes bugs because programs set LC_ALL to get predictable output and then get confused because they aren't getting the expected output. Nov 3, 2014 at 19:24
  • Well, the Ubuntu GUIs set both LANG and LANGUAGE consistently (and LC_MESSAGES inherits from LANG), which ought to prevent that kind of confusion. The reason why LANGUAGE is set is that Language Support has an interface for setting a priority list. Nov 3, 2014 at 19:39
  • @GunnarHjalmarsson I know. Setting LANGUAGE is a bad idea nonetheless, because the benefits are very thin whereas the bugs can be annoying and hard to find. You are right though, I should mention unsetting LANGUAGE. Nov 3, 2014 at 19:46
  • Answers here is not a proper place to debate design issues. Such discussions are better held at e.g. ubuntu-devel-discuss. To be helpful to users, I really think that an answer should be based on the current design, whether you think it's optimal or not. And please note that "some versions" are all supported versions of Ubuntu desktop and derivatives, possibly with the exception of Kubuntu. Nov 3, 2014 at 21:25
4

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.

https://help.ubuntu.com/community/Locale

2
  • 1
    I don't know why this answer got downvoted. Yes it could use some more explanation, but unlike the accepted answer, it shows how to make it permanent and is more specific.
    – xeruf
    May 7, 2018 at 14:56
  • that is for my case the best answer. I want to have output in french (with full unicode, for example for commit message) but output in english. Thats is done
    – Maïeul
    Jun 7, 2020 at 13:57
1

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

env LANGUAGE=en gnome-terminal
1

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
0
  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.

0

To change the terminal language to English permanently, use:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .