oslo_i18n

来源:互联网 发布:金相自动分析软件 编辑:程序博客网 时间:2024/05/22 11:53
在nova中经常看到下面的code            if requested_topology and not instance_topology:                if pci_requests.requests:                    return (_("Requested instance NUMA topology together with "                              "requested PCI devices cannot fit the given "                              "host NUMA topology"))                else:                    return (_("Requested instance NUMA topology cannot fit "                              "the given host NUMA topology"))这个字符串前面的_是啥意思呢?仔细看from nova.i18n import _原来是从nova.i18n导入的,那在看看nova.i18n.pyimport oslo_i18nDOMAIN = 'nova'_translators = oslo_i18n.TranslatorFactory(domain=DOMAIN)# The primary translation function using the well-known name "_"_ = _translators.primary# Translators for log levels.## The abbreviated names are meant to reflect the usual use of a short# name like '_'. The "L" is for "log" and the other letter comes from# the level._LI = _translators.log_info_LW = _translators.log_warning_LE = _translators.log_error_LC = _translators.log_criticaldef translate(value, user_locale):    return oslo_i18n.translate(value, user_locale)def get_available_languages():    return oslo_i18n.get_available_languages(DOMAIN)原来_ = _translators.primary。最终发现都是用oslo_i18n这个包的解释如下:https://docs.openstack.org/nova/pike/reference/i18n.html原来_ 是用于字符串显示的国际化的,简单理解解释显示成个个国家自己的语言。而_LI = _translators.log_info_LW = _translators.log_warning_LE = _translators.log_error_LC = _translators.log_critical是用于不同级别log显示的.

原创粉丝点击