5 # The purpose of this script is to generate a multi-lingual en po file for
6 # Mailman Core. Multi-lingual PO files use both a .pot file and a reference po
7 # file. The reference in our case is en and is what is displayed in Weblate
10 # Since there are no utilities to create multi-lingual reference PO file, this
11 # script exists to solve that purpose. Here is how it works:
13 # It will read the default en po file and set all msgstr to be same as
14 # msgid. The only exception to this is email templates, where the msgid is the
15 # filename of the template and msgstr is the content of that file.
17 from pathlib
import Path
19 from babel
.messages
.pofile
import read_po
, write_po
20 from babel
.messages
.catalog
import Catalog
, Message
22 print('Please install `babel` to run this script.')
25 PO_PATH
= Path('src/mailman/messages/en/LC_MESSAGES/mailman.po')
26 TEMPLATE_BASE_PATH
= Path('src/mailman/templates/en')
30 "Read the po file path and return a Catalog object."
31 with path
.open() as fd
:
35 def put_po(path
, catalog
):
36 "Write the catalog object to the po file path."
37 with path
.open('bw') as fd
:
38 write_po(fd
, catalog
, include_previous
=True, width
=85, )
40 def get_template(name
):
41 "Get the template text with the name if it exists."
42 template_path
= TEMPLATE_BASE_PATH
/ name
43 if not template_path
.exists():
45 template_path
.read_text().rstrip('\n')
49 catalog
= get_po(PO_PATH
)
51 if each
.id.endswith('.txt'):
52 each
.string
= get_template(each
.id)
55 put_po(PO_PATH
, catalog
)
56 print(f
'Updated {PO_PATH}')