Mercurial/Python-下划线功能做什么? [英] Mercurial/Python - What Does The Underscore Function Do?

查看:102
本文介绍了Mercurial/Python-下划线功能做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mercurial中,许多扩展将其帮助/语法字符串包装在下划线函数的调用中,如下所示:

In Mercurial, many of the extensions wrap their help/syntax string in a call to an underscore function, like so:

 _('[OPTION] [QUEUE]')

这使我感到困惑,因为它似乎没有必要(书写扩展说明不要提及它),并且在类中似乎没有定义_,所以我想知道这是否是我不理解的某些特殊语法,也许是表示lambda的另一种方式,或者是标识功能?另外,我想知道这种方法(无论它是什么)相对于文档建议的原始字符串有什么好处.

This confuses me, because it does not seem necessary (the Writing Extensions instructions don't mention it) and there doesn't seem to be a _ defined in the class, so I'm wondering if this is some special syntax that I don't understand, perhaps another way to say lambda, or maybe the identity function? Additionally I'm wondering what the benefit of this methodology (whatever it is) is over just the raw string like the documentation suggests.

我在Python文档中没有看到任何提及此功能的信息,因此我不确定这是一个Python问题还是Mercurial问题.

Nothing I've seen in the Python documentation mentions such a function, so I'm not sure if this is really a Python question, or a Mercurial question.

这里有两个使用此结构的示例(请查看文件底部附近的cmdtable词典)

Here are two examples that use this structure (look at the cmdtable dictionary near the bottom of the file)

  • https://www.mercurial-scm.org/repo/hg/file/42408cd43f55/hgext/mq.py
  • https://www.mercurial-scm.org/repo/hg/file/42408cd43f55/hgext/graphlog.py

推荐答案

看第45行:

from mercurial.i18n import _

这是国际化软件包 gettext 中的常见缩写,也可能是其他软件包,用于将参数转换为程序当前运行语言的函数.为方便起见,它缩写为_,因为它几乎用于显示给用户的每条消息.

This is the usual abbreviation in the internationalization package gettext, and possibly other packages too, for the function that returns a translation of its argument to the language the program is currently running in. It's abbreviated to _ for convenience, since it's used for just about every message displayed to the user.

看起来像Mercurial将其包装在自己的模块中. ("i18n"代表国际化",因为在"i"和"n"之间有18个字母.)

Looks like Mercurial wraps it in their own module. ("i18n" stands for "internationalization" because there are 18 letters in between "i" and "n".)

这篇关于Mercurial/Python-下划线功能做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆