Create translator functions
Translate critical-level log messages.
Translate error-level log messages.
Translate info-level log messages.
Translate warning-level log messages.
The default translation function.
See also
An example of using a TranslatorFactory is provided in Creating an Integration Module.
Convenience function for configuring _() to use lazy gettext
Call this at the start of execution to enable the gettextutils._ function to use lazy gettext functionality. This is useful if your project is importing _ directly instead of using the gettextutils.install() way of importing the _ function.
Parameters: | enable (bool) – Flag indicating whether lazy translation should be turned on or off. Defaults to True. |
---|
See also
Gets the translated unicode representation of the given object.
If the object is not translatable it is returned as-is.
If the desired_locale argument is None the object is translated to the system locale.
Parameters: |
|
---|---|
Returns: | the translated object in unicode, or the original object if it could not be translated |
Lists the available languages for the given translation domain.
Parameters: | domain – the domain to get languages for |
---|
logging utilities for translation
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.
Test fixtures for working with oslo.i18n.
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.
Parameters: | msg (str or unicode) – Input message string. May optionally include positional or named string interpolation markers. |
---|
Return a lazily translated message.
Parameters: | msg (str or unicode) – Input message string. May optionally include positional or named string interpolation markers. |
---|