-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpo2xls.py
60 lines (50 loc) · 1.89 KB
/
po2xls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import click
import polib
import openpyxl
from pathlib import Path
from po_excel_translate import ColumnHeaders, PortableObjectFile, PortableObjectFileToXLSX, CommentType
# Widths are in range [0, 200]
@click.command()
@click.option(
"-c",
"--comments",
multiple=True,
default=[str(CommentType.SOURCE)],
type=click.Choice([str(i) for i in CommentType.get_all()]),
help="Comments to include in the spreadsheet",
show_default=True,
)
@click.option(
"--width-message-context", type=click.IntRange(0, 200), default=20, help="Width of the namespace", show_default=True
)
@click.option(
"--width-message-id", type=click.IntRange(0, 200), default=80, help="Width of the message id", show_default=True
)
@click.option("-o", "--output", type=str, default="messages.xlsx", help="Output file", show_default=True)
@click.argument("catalogs_paths", metavar="CATALOG", nargs=-1, required=True, type=click.Path())
def main(comments, width_message_context, width_message_id, output, catalogs_paths):
"""
Convert .PO files to an XLSX file.
po-to-xls tries to guess the locale for PO files by looking at the
"Language" key in the PO metadata, falling back to the filename. You
can also specify the locale manually by adding prefixing the filename
with "<locale>:". For example: "nl:locales/nl/mydomain.po".
"""
po_files = []
for path in catalogs_paths:
po_files.append(PortableObjectFile(path))
comment_types = []
for s in comments:
comment_types.append(CommentType(s))
output_file_path = Path(output)
PortableObjectFileToXLSX(
po_files=po_files,
comment_types=comment_types,
output_file_path=output_file_path,
width_message_context=width_message_context,
width_message_id=width_message_id,
)
print(f"Generated {output_file_path.absolute()}")
if __name__ == "__main__":
main()