bash 如何更改 Git 命令行界面的语言?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10633564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:07:30  来源:igfitidea点击:

How does one change the language of the command line interface of Git?

bashgitlocalizationenvironment-variableslocale

提问by user905686

I'd like to change the language of git (to English) in my Linux installation without changing the language for other programs and couldn't find the settings. How to do it?

我想在我的 Linux 安装中更改 git 的语言(为英语),而不更改其他程序的语言并且找不到设置。怎么做?

回答by Bengt

Add these lines to your ~/.bashrcor ~/.bash_profileto force git to display all messages in English:

将这些行添加到您的~/.bashrc~/.bash_profile强制 git 以英语显示所有消息:

# Set Git language to English
#alias git='LANG=en_US git'
alias git='LANG=en_GB git'

The alias needs to override LC_ALLon some systems, when the environment variable LC_ALLis set, which has precedence over LANG. See the UNIX Specification - Environment Variablesfor further explanation.

LC_ALLLC_ALL设置了环境变量时,别名需要在某些系统上覆盖,它优先于LANG. 有关进一步说明,请参阅UNIX 规范 - 环境变量

# Set Git language to English
#alias git='LC_ALL=en_US git'
alias git='LC_ALL=en_GB git'

In case you added these lines to ~/.bashrcthe alias will be defined when a new interactive shell gets started. In case you added it to ~/.bash_profilethe alias will be applied when logging in.

如果您将这些行添加到~/.bashrc别名将在新的交互式 shell 启动时定义。如果您将其添加到~/.bash_profile别名将在登录时应用。

回答by rubo77

If you just want to have one command in english instead you can just write LC_ALL=Cbefore the command, for example:

如果您只想使用一个英文命令,您可以LC_ALL=C在命令前写,例如:

LC_ALL=C git status

will result in

会导致

# On branch master
nothing to commit, working directory clean

The locale as used in Cis English and always available without installing additional language packs
(see https://askubuntu.com/a/142814/34298)

使用的语言环境C是英语,无需安装其他语言包即可始终使用
(请参阅https://askubuntu.com/a/142814/34298

To change it for the whole current bash session just enter

要为整个当前 bash 会话更改它,只需输入

LANG=C

To change it for example to german enter

要将其更改为例如德语输入

LANG=de_DE.UTF-8

回答by Donald Duck

Adding this line solved the problem for me:

添加此行为我解决了问题:

$ more ~/.bash_profile
export LANG=en_US

回答by VonC

Note: since Git 2.3.1+ (Q1/Q2 2015), Git will add Accept-Language header if possible.
See commit f18604bby Yi EungJun (eungjun-yi)

注意:从 Git 2.3.1+(2015 年第一季度/第二季度)开始,如果可能,Git 将添加 Accept-Language 标头。
提交f18604b易EungJun( eungjun-yi

Add an Accept-Languageheader which indicates the user's preferred languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGESand $LANG.

This gives git servers a chance to display remote error messages in the user's preferred language.

添加Accept-Language,其指示用户的首选语言由定义的头$LANGUAGE$LC_ALL$LC_MESSAGES$LANG

这使 git 服务器有机会以用户的首选语言显示远程错误消息。



You have locale for git guior other GUIs, but not for the command-line, considering it was one of the questions of GitSurvey 2010

你有git gui其他 GUI 的语言环境但不是命令行,考虑到它是GitSurvey 2010的问题之一

localization of command-line messages (i18n)    258     3.6%    

Of course, since 2010, as po/READMEdescribes:

当然,自 2010 年以来,如po/README描述:

Before strings can be translated they first have to be marked for translation.

Git uses an internationalization interface that wraps the system's gettextlibrary, so most of the advice in your gettext documentation (on GNU systems info gettextin a terminal) applies.

在字符串可以被翻译之前,它们首先必须被标记为翻译。

Git 使用包装系统gettextlibrary的国际化接口 ,因此您的 gettext 文档(在info gettext终端中的GNU 系统上)中的大部分建议都适用。

In place since git 1.7.9+(January 2012):

git 1.7.9+(2012 年 1 月)开始:

Git uses gettextto translate its most common interface messages into the user's language if translations are available and the locale is appropriately set.
Distributors can drop new POfiles in po/to add new translations.

gettext如果翻译可用并且区域设置适当设置,Git 用于将其最常见的界面消息翻译成用户的语言
分销商可以放入新PO文件po/以添加新翻译。

So, if your update has mess up the translation, check what gettextuses:
See, for instance, "Locale Environment Variables"

因此,如果您的更新弄乱了翻译,请检查gettext使用了什么:
例如,请参阅“区域设置环境变量

A locale is composed of several locale categories, see Aspects. When a program looks up locale dependent values, it does this according to the following environment variables, in priority order:

语言环境由多个语言环境类别组成,请参阅方面。当程序查找依赖于语言环境的值时,它会根据以下环境变量按优先级顺序执行此操作:

LANGUAGE
LC_ALL
LC_xxx, according to selected locale category: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, ...
LANG 

Variables whose value is set but is empty are ignored in this lookup.

LANGis the normal environment variable for specifying a locale. As a user, you normally set this variable (unless some of the other variables have already been set by the system, in /etc/profileor similar initialization files).

LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, and so on, are the environment variables meant to override LANGand affecting a single locale category only.
For example, assume you are a Swedish user in Spain, and you want your programs to handle numbers and dates according to Spanish conventions, and only the messages should be in Swedish. Then you could create a locale named ‘sv_ES' or ‘sv_ES.UTF-8' by use of the localedefprogram. But it is simpler, and achieves the same effect, to set the LANGvariable to es_ES.UTF-8and the LC_MESSAGESvariable to sv_SE.UTF-8; these two locales come already preinstalled with the operating system.

LC_ALLis an environment variable that overrides all of these. It is typically used in scripts that run particular programs. For example, configure scripts generated by GNU autoconfuse LC_ALLto make sure that the configuration tests don't operate in locale dependent ways.

Some systems, unfortunately, set LC_ALLin /etc/profileor in similar initialization files. As a user, you therefore have to unset this variable if you want to set LANGand optionally some of the other LC_xxxvariables.

在此查找中忽略其值已设置但为空的变量。

LANG是用于指定语言环境的普通环境变量。作为用户,您通常会设置此变量(除非系统已在/etc/profile或类似的初始化文件中设置了某些其他变量)。

LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, 等是旨在覆盖LANG和仅影响单个语言环境类别的环境变量。
例如,假设您是西班牙的瑞典用户,并且您希望您的程序根据西班牙惯例处理数字和日期,并且只有消息应该是瑞典语。然后,您可以使用该程序创建名为“ sv_ES”或“ sv_ES.UTF-8”的语言环境localedef。但是更简单,并且达到相同的效果,将LANG变量设置为es_ES.UTF-8,将LC_MESSAGES变量设置为sv_SE.UTF-8;这两个语言环境已经预装在操作系统中。

LC_ALL是一个覆盖所有这些的环境变量。它通常用于运行特定程序的脚本。例如,通过GNU生成的配置脚本autoconf使用LC_ALL,以确保配置测试不依赖于语言环境的方式运作。

不幸的是,某些系统设置LC_ALL/etc/profile或类似的初始化文件中。因此,作为用户,如果您想设置LANG和可选的一些其他LC_xxx变量,则必须取消设置此变量。

回答by iapetus

Run LC_MESSAGES=C git, not LC_ALL=C or LANG=C and no need delete or rename files.

运行LC_MESSAGES=C git,而不是 LC_ALL=C 或 LANG=C 并且不需要删除或重命名文件。

This command change output Git messages to english.

此命令将输出 Git 消息更改为英语。

回答by Oliver Watkins

GIT defaults to english if it cannot find the Locale language.

如果找不到 Locale 语言,GIT 默认为英语。

So if you want GIT to be in english, just sabotage the language file that it is running with. In my case it was always running with german (ie: de.msg).

因此,如果您希望 GIT 为英文,只需破坏它正在运行的语言文件即可。在我的情况下,它总是以德语运行(即:de.msg)。

If I deleted it or renamed the it, then it defaulted to english.

如果我删除它或重命名它,那么它默认为英文。

enter image description here

在此处输入图片说明

Here I renamed the file

在这里,我重命名了文件

enter image description here

在此处输入图片说明

回答by Svetoslav

As Bengt suggested : Add these lines to your ~/.bashrcor ~/.bash_profileto force git to display all messages in English: vim ~/.bashrc- for this profile (if you are user ubuntuand you edit this it will be only for this user); add this lines:

正如 Bengt 建议的那样:将这些行添加到您的~/.bashrc~/.bash_profile强制 git 以英语显示所有消息: vim ~/.bashrc- 对于此配置文件(如果您是用户ubuntu并且您编辑此配置文件,它将仅适用于该用户);添加这一行:

# Set Git language to English
#alias git='LANG=en_US git'
alias git='LANG=en_GB git'
#you can add also 
LANG=en_GB

and after you close the file you need to write in shell:

关闭文件后,您需要在 shell 中写入:

source ~/.bashrc 

to reload new settings or exit the terminal and connect again :)

重新加载新设置或退出终端并再次连接:)

回答by Phan Van Linh

Here is my solution to change git language follow answer thisand this

这是我更改 git 语言的解决方案,请按照回答这个这个

1) nano ~/.bashrc
2) add alias git='LANG=en_GB git'to the file
2) save the file
4) source ~/.bashrc

1) nano ~/.bashrc
2) 添加alias git='LANG=en_GB git'到文件
2) 保存文件
4)source ~/.bashrc

Now your git already change the language. However, IFafter your restart terminal and it not working anymore, you need to

现在你的 git 已经改变了语言。但是,如果重启终端后它不再工作,你需要

4.1) nano ~/.profile
4.2) add source ~/.bashrc
4.3) save the file

4.1) nano ~/.profile
4.2) 添加source ~/.bashrc
4.3) 保存文件

it will make source ~/.bashrcrun whenever you open the terminal

source ~/.bashrc每当您打开终端时,它都会运行

Hope it help

希望有帮助