manila/doc/source/devref/i18n.rst
Tom Barron 66a6505d79 remove hacking rule that enforces log translation
Log translation is no longer being done [1] [2] so there
is no point in enforcing it going forwards.

Remove the hacking enforcement so that new commits need
not include this unused feature and so that we can remove
this unused il8n markup in existing code.

[1] http://lists.openstack.org/pipermail/openstack-dev/2017-March/thread.html#113365
[2] https://review.openstack.org/#/c/446762/

Change-Id: I31f35b0597e161a1654467f5a0a2348789292d83
2017-03-17 05:54:03 -04:00

1.5 KiB

Internationalization

Manila uses gettext so that user-facing strings appear in the appropriate language in different locales.

Beginning with the Pike series, OpenStack no longer supports log translation. It is not useful to add translation instructions to new code, and the instructions can be removed from old code.

Other user-facing strings, e.g. in exception messages, should be translated.

To use gettext, make sure that the strings passed to the logger are wrapped in a _() function call. For example:

msg = _("Share group %s not found.") % share_group_id
raise exc.HTTPNotFound(explanation=msg)

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 the LocalizationTestCase.test_multiple_positional_format_placeholders test to fail in manila/tests/test_localization.py.

The _() function is brought into the global scope by doing:

from manila.openstack.common import gettextutils
gettextutils.install("manila")

These lines are needed in any toplevel script before any manila modules are imported. If this code is missing, it may result in an error that looks like:

NameError: name '_' is not defined