Remove references to log translation functions

No new implementers of this library should be using the log-oriented
marker functions, so we shouldn't be providing examples of them.
This change removes them from the sample integration module and
updates the usage examples to reflect the current best practices.

Change-Id: I0ae89cb3500821465438ee1f5572ab5e3573044c
This commit is contained in:
Ben Nemec 2018-09-12 22:18:36 +00:00
parent e7b3ff2001
commit a38f70d463
1 changed files with 7 additions and 19 deletions

View File

@ -59,34 +59,22 @@ the marker functions the factory creates.
# requires oslo.i18n >=2.1.0
_P = _translators.plural_form
# Translators for log levels.
#
# NOTE(dhellmann): This is not needed for new projects as of the
# Pike series.
#
# 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 get_available_languages():
return oslo_i18n.get_available_languages(DOMAIN)
.. TODO: Provide examples for _C and _P
Then, in the rest of your code, use the appropriate marker function
for each message:
.. code-block:: python
from myapp._i18n import _, _LW, _LE
from myapp._i18n import _
# ...
variable = "openstack"
LOG.warning(_LW('warning message: %s'), variable)
some_object.name_msg = _('my name is: %s') % variable
# ...
@ -96,8 +84,8 @@ for each message:
except AnException1:
# Log only
LOG.exception(_LE('exception message'))
# Log only, log messages are no longer translated
LOG.exception('exception message')
except AnException2:
@ -119,7 +107,7 @@ for each message:
for import statements.
It is important to use the marker functions (e.g. _LI), rather than
It is important to use the marker functions (e.g. _), rather than
the longer form of the name, because the tool that scans the source
code for translatable strings looks for the marker function names.