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.
The TranslationHandler takes a locale and a target logging.Handler object to forward LogRecord objects to after translating them. This handler depends on Message objects being logged, instead of regular strings.
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.