Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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)?

share|improve this question
4  
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. –  Eliah Kagan Mar 5 '13 at 13:49
2  
@EliahKagan yes, you are right, but anyway I think it is useful. –  BuZZ-dEE Mar 5 '13 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). –  Eliah Kagan Mar 5 '13 at 13:56
1  
@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.) –  Gilles Nov 3 at 19:45

5 Answers 5

up vote 5 down vote accepted

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

share|improve this answer

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.

share|improve this answer
    
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. –  Gunnar Hjalmarsson Nov 2 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. –  Gilles Nov 3 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. –  Gunnar Hjalmarsson Nov 3 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. –  Gilles Nov 3 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. –  Gunnar Hjalmarsson Nov 3 at 21:25

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

env LANGUAGE=en gnome-terminal
share|improve this answer

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'
share|improve this answer
    
The script needs changing for another language than German (DE)? I search for a solution independent from the native language. –  BuZZ-dEE Mar 5 '13 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 '13 at 0:30
    
@buzz-dee: see updated answer –  H.-Dirk Schmitt Mar 6 '13 at 16:27

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:

share|improve this answer
    
Setting LANG is not sufficient to chance all output. –  bitmask Mar 5 '13 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 '13 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 '13 at 0:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.