nova/doc/source/reference/i18n.rst
Stephen Finucane 45a88f08b4 hacking: Modify checks for translated logs
The N319 check previously asserted that debug-level logs were not
translated. Now that we've removed all log translations, we can
generalize this to all logs. We reuse the same number since these
numbers are really just metadata and not public contracts.

This also allows us to update the N323 and N326 checks, which ensure we
import the translation function, '_', wherever it's used and don't
concatenate translated and non-translated strings. Since we're no longer
translating logs and the '_LE', '_LW' and '_LI' symbols are no longer
provided, we don't need to consider logs in either of these cases.

Change-Id: I64d139ad660bc382e8b9d7c8cd03352b26aadafd
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2020-05-27 09:41:30 +00:00

1.5 KiB

Internationalization

Nova uses the :oslo.i18n-doc:oslo.i18n library <> to support internationalization. The oslo.i18n library is built on top of gettext and provides functions that are used to enable user-facing strings such as log messages to appear in the appropriate language in different locales.

Nova exposes the oslo.i18n library support via the nova/i18n.py integration module. This module provides the functions needed to wrap translatable strings. It provides the _() wrapper for general user-facing messages (such as ones that end up in command line responses, or responses over the network).

One upon a time there was an effort to translate log messages in OpenStack projects. But starting with the Ocata release these are no longer being supported. Log messages should not be translated.

You should use the basic wrapper _() for strings which are not log messages that are expected to get to an end user:

raise nova.SomeException(_('Invalid service catalogue'))

Do not use locals() for formatting messages because:

  1. It is not as clear as using explicit dicts.
  2. It could produce hidden errors during refactoring.
  3. Changing the name of a variable causes a change in the message.
  4. It creates a lot of otherwise unused variables.

If you do not follow the project conventions, your code may cause hacking checks to fail.

The _() function can be imported with :

from nova.i18n import _