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
This commit is contained in:
Tom Barron 2017-03-16 20:06:00 -04:00
parent 24a650d0be
commit 66a6505d79
3 changed files with 16 additions and 57 deletions

View File

@ -17,11 +17,6 @@ Manila Specific Commandments
- [M325] str() and unicode() cannot be used on an exception. Remove or use six.text_type().
- [M326] Translated messages cannot be concatenated. String should be
included in translated message.
- [M328] LOG.critical messages require translations _LC()!
- [M328] LOG.error and LOG.exception messages require translations _LE()!
- [M329] LOG.info messages require translations _LI()!
- [M330] LOG.warning messages require translations _LW()!
- [M331] Log messages require translations!
- [M333] ``oslo_`` should be used instead of ``oslo.``
- [M336] Must use a dict comprehension instead of a dict constructor
with a sequence of key-value pairs.
@ -32,19 +27,14 @@ Manila Specific Commandments
LOG Translations
----------------
LOG.debug messages will not get translated. Use ``_LI()`` for
``LOG.info``, ``_LW`` for ``LOG.warning``, ``_LE`` for ``LOG.error``
and ``LOG.exception``, and ``_LC()`` for ``LOG.critical``.
Beginning with the Pike series, OpenStack no longer supports log translation.
It is not useful to add translation instructions to new code, the
instructions can be removed from old code, and the hacking checks that
enforced use of special translation markers for log messages have been
removed.
``_()`` is preferred for any user facing message, even if it is also
going to a log file. This ensures that the translated version of the
message will be available to the user.
The log marker functions (``_LI()``, ``_LW()``, ``_LE()``, and ``_LC()``)
must only be used when the message is only sent directly to the log.
Anytime that the message will be passed outside of the current context
(for example as part of an exception) the ``_()`` marker function
must be used.
Other user-facing strings, e.g. in exception messages, should be translated
using ``_()``.
A common pattern is to define a single message object and use it more
than once, for the log call and the exception. In that case, ``_()``

View File

@ -1,13 +1,19 @@
Internationalization
====================
Manila uses `gettext <http://docs.python.org/library/gettext.html>`_ so that
user-facing strings such as log messages appear in the appropriate
language in different locales.
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::
LOG.info(_("block_device_mapping %s"), block_device_mapping)
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.

View File

@ -36,16 +36,6 @@ Guidelines for writing new hacking checks
UNDERSCORE_IMPORT_FILES = []
log_translation = re.compile(
r"(.)*LOG\.(audit|error|info|critical|exception)\(\s*('|\")")
log_translation_LC = re.compile(
r"(.)*LOG\.(critical)\(\s*(_\(|'|\")")
log_translation_LE = re.compile(
r"(.)*LOG\.(error|exception)\(\s*(_\(|'|\")")
log_translation_LI = re.compile(
r"(.)*LOG\.(info)\(\s*(_\(|'|\")")
log_translation_LW = re.compile(
r"(.)*LOG\.(warning|warn)\(\s*(_\(|'|\")")
translated_log = re.compile(
r"(.)*LOG\.(audit|error|info|warn|warning|critical|exception)"
"\(\s*_\(\s*('|\")")
@ -189,32 +179,6 @@ class CheckLoggingFormatArgs(BaseASTChecker):
return super(CheckLoggingFormatArgs, self).generic_visit(node)
def validate_log_translations(logical_line, physical_line, filename):
# Translations are not required in the test and tempest
# directories.
if ("manila/tests" in filename or "manila_tempest_tests" in filename or
"contrib/tempest" in filename):
return
if pep8.noqa(physical_line):
return
msg = "M327: LOG.critical messages require translations `_LC()`!"
if log_translation_LC.match(logical_line):
yield (0, msg)
msg = ("M328: LOG.error and LOG.exception messages require translations "
"`_LE()`!")
if log_translation_LE.match(logical_line):
yield (0, msg)
msg = "M329: LOG.info messages require translations `_LI()`!"
if log_translation_LI.match(logical_line):
yield (0, msg)
msg = "M330: LOG.warning messages require translations `_LW()`!"
if log_translation_LW.match(logical_line):
yield (0, msg)
msg = "M331: Log messages require translations!"
if log_translation.match(logical_line):
yield (0, msg)
def check_explicit_underscore_import(logical_line, filename):
"""Check for explicit import of the _ function
@ -375,7 +339,6 @@ def no_log_warn_check(logical_line):
def factory(register):
register(validate_log_translations)
register(check_explicit_underscore_import)
register(no_translate_debug_logs)
register(CheckForStrUnicodeExc)