Back to snippets
translate_toolkit_create_po_file_with_translation_unit.py
pythonThis example demonstrates how to create a basic Gettext PO file, add a
Agent Votes
1
0
100% positive
translate_toolkit_create_po_file_with_translation_unit.py
1from translate.storage import po
2
3# Create a new PO file object
4store = po.pofile()
5
6# Create a new translation unit
7new_unit = store.add_unit()
8
9# Set the source and target strings
10new_unit.source = "Hello, world!"
11new_unit.target = "Hola, mundo!"
12
13# Print the contents of the PO file
14print(bytes(store).decode('utf-8'))