Back to snippets
oslo_i18n_translator_factory_initialization_and_string_translation.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_and_string_translation.py
1import oslo_i18n
2
3# 1. Initialize the integration module for your specific library or application
4# In a real project, this is typically done in a 'PROJECT/i18n.py' file.
5_translators = oslo_i18n.TranslatorFactory(domain='my_app')
6
7# 2. Define the translation functions
8# The primary translation function for the main log levels and messages
9_ = _translators.primary
10
11# 3. Usage example
12def main():
13 # Marking a string for translation
14 # The actual translation happens at runtime based on the system locale
15 print(_("Hello, world! This is a translatable message."))
16
17if __name__ == "__main__":
18 main()