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)?
Solution 1:
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
Solution 2:
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'
Solution 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:
- Change the Language in a Linux (BaSH) Shell
- export LC_ALL=C
- Creating permanent executable aliases
Solution 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.