File: i18n.rst

package info (click to toggle)
nova 2%3A22.0.1-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 47,176 kB
  • sloc: python: 375,733; pascal: 1,781; sh: 1,142; makefile: 149; xml: 83; sql: 43
file content (37 lines) | stat: -rw-r--r-- 1,516 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Internationalization
====================

Nova uses the :oslo.i18n-doc:`oslo.i18n library <>` to support
internationalization. The oslo.i18n library is built on top of `gettext
<http://docs.python.org/library/gettext.html>`_ 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 _