Test fixtures for working with oslo_i18n.
Bases: Fixture
Fixture to prefix lazy translation enabled messages
Use of this fixture will cause messages supporting lazy translation to be replaced with the message id prefixed with ‘domain/language:’. For example, ‘oslo/en_US: message about something’. It will also override the available languages returned from oslo_18n.get_available_languages to the specified languages.
This will enable tests to ensure that messages were translated lazily with the specified language and not immediately with the default language.
NOTE that this does not work unless lazy translation is enabled, so it uses the ToggleLazy fixture to enable lazy translation.
languages (list of strings) – list of languages to support. If not specified (None) then [‘en_US’] is used.
Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
None.
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
Bases: Fixture
Fixture to toggle lazy translation on or off for a test.
Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
None.
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
Bases: Fixture
Fixture for managing translatable strings.
This class provides methods for creating translatable strings using both lazy translation and immediate translation. It can be used to generate the different types of messages returned from oslo_i18n to test code that may need to know about the type to handle them differently (for example, error handling in WSGI apps, or logging).
Use this class to generate messages instead of toggling the global lazy flag and using the regular translation factory.
Return a string as though it had been translated immediately.
msg (str or unicode) – Input message string. May optionally include positional or named string interpolation markers.
Return a lazily translated message.
msg (str or unicode) – Input message string. May optionally include positional or named string interpolation markers.
logging utilities for translation
Bases: MemoryHandler
Handler that translates records before logging them.
When lazy translation is enabled in the application (see
enable_lazy()
), the TranslationHandler
uses its locale configuration setting to determine how to
translate LogRecord objects before forwarding them to the
logging.Handler.
When lazy translation is disabled, the message in the LogRecord is converted to unicode without any changes and then forwarded to the logging.Handler.
The handler can be configured declaratively in the
logging.conf
as follows:
[handlers]
keys = translatedlog, translator
[handler_translatedlog]
class = handlers.WatchedFileHandler
args = ('/var/log/api-localized.log',)
formatter = context
[handler_translator]
class = oslo_i18n.log.TranslationHandler
target = translatedlog
args = ('zh_CN',)
If the specified locale is not available in the system, the handler will log in the default locale.
Emit a record.
Append the record. If shouldFlush() tells us to, call flush() to process the buffer.
Set the formatter for this handler.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.