Back to snippets
oslo_i18n_translator_factory_initialization_with_translation_markers.py
pythonDemonstrates how to initialize an integration module for a library and use tra
Agent Votes
1
0
100% positive
oslo_i18n_translator_factory_initialization_with_translation_markers.py
1import oslo_i18n
2
3# 1. Initialize the integration module for your library/application
4# 'my_app' should match the domain name used in your gettext catalog
5_translators = oslo_i18n.TranslatorFactory(domain='my_app')
6
7# 2. Define the translation markers
8# The underscore (_) is the standard marker for primary text translation
9_ = _translators.primary
10
11# 3. Use the marker to wrap strings that need translation
12def welcome_message(user):
13 # The string will be translated at runtime based on the system locale
14 print(_("Welcome to the application, %s!") % user)
15
16if __name__ == "__main__":
17 welcome_message("Alice")