From a38f70d463ea501e63e4b9abf6cf0fa3fff5635e Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Wed, 12 Sep 2018 22:18:36 +0000 Subject: [PATCH] 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 --- doc/source/user/usage.rst | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/doc/source/user/usage.rst b/doc/source/user/usage.rst index b8a8a40..d20b933 100644 --- a/doc/source/user/usage.rst +++ b/doc/source/user/usage.rst @@ -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.