在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.py
import oslo_i18n
DOMAIN = '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_critical
def 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显示的.
oslo_i18n
最新推荐文章于 2024-08-03 13:19:01 发布