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)?
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
-
1Thats 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ïeulJun 7, 2020 at 13:59
-
1It stops working after you close Konsole and open a new one. The new Konsole is in the old (non-English) language– parsecerAug 21, 2021 at 3:20
-
-
just put
export LC_ALL=C
into your~/.bashrc
file for applying permanent changes Jan 24 at 11:03
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'
-
The script needs changing for another language than German (DE)? I search for a solution independent from the native language.– BuZZ-dEEMar 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 againstlocale -a
to make sure the requested locale is actually installed.– bitmaskMar 6, 2013 at 0:30 -
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:
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. Nov 2, 2014 at 16:04
-
@GunnarHjalmarsson The main problem with
LANGUAGE
is that it takes precedence overLC_ALL
, which causes bugs because programs setLC_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 unsettingLANGUAGE
. 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
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.
-
1I 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.– xerufMay 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ïeulJun 7, 2020 at 13:57
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
- Click on the gear icon on the left (system settings on Unity panel)
- Click on Language Support
- Select Regional Formats
- Set your "Display numbers, dates, and currency amount ..." to English.
- Logout the session and Login again (Required!)
Done.
To change the terminal language to English permanently, use:
echo 'export LANG=C' >> ~/.bashrc && exec "$BASH"
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.