109

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

BuZZ-dEE
  • 14,223
  • 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. – Eliah Kagan Mar 05 '13 at 13:49
  • 5
    @EliahKagan yes, you are right, but anyway I think it is useful. – BuZZ-dEE Mar 05 '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 05 '13 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.) – Gilles 'SO- stop being evil' Nov 03 '14 at 19:45

9 Answers9

111

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
Eric Carvalho
  • 54,385
  • 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. https://askubuntu.com/a/818241/227400 was better. – Maïeul Jun 07 '20 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 '21 at 03:20
  • See rofrol 's answer below for permanent solution – parsecer Aug 21 '21 at 03:23
  • just put export LC_ALL=C into your ~/.bashrc file for applying permanent changes – cestpasmoi Jan 24 '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'
guntbert
  • 13,134
  • The script needs changing for another language than German (DE)? I search for a solution independent from the native language. – BuZZ-dEE Mar 05 '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 06 '13 at 00:30
  • @buzz-dee: see updated answer – H.-Dirk Schmitt Mar 06 '13 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:

BuZZ-dEE
  • 14,223
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.

  • 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 02 '14 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 'SO- stop being evil' Nov 03 '14 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 03 '14 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 'SO- stop being evil' Nov 03 '14 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 03 '14 at 21:25
  • @GunnarHjalmarsson I have updated my answer to discuss LANGUAGE. – Gilles 'SO- stop being evil' Nov 03 '14 at 21:46
  • Saw it. So now it works at least. ;) – Gunnar Hjalmarsson Nov 03 '14 at 22:12
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

rofrol
  • 210
  • 2
  • 9
  • 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 07 '18 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 07 '20 at 13:57
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
Vasil
  • 11
1

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

env LANGUAGE=en gnome-terminal
Gunnar Hjalmarsson
  • 33,540
  • 3
  • 64
  • 94
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.

Robin Hsu
  • 123
0

To change the terminal language to English permanently, use:

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