Skip to content

Commit 31c4563

Browse files
committed
Add docsstrings
1 parent 394d970 commit 31c4563

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

msg2po/po_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def _occ_sort_key(occ: tuple[str, str]) -> tuple[str, int]:
8888
return (occ[0], int(occ[1]))
8989

9090

91-
def sort_po(po: polib.POFile):
91+
def sort_po(po: polib.POFile) -> polib.POFile:
92+
"""Sort PO entries by occurrence (filepath, line number). Returns a new POFile."""
9293
for e in po:
9394
e.occurrences = sorted(e.occurrences, key=_occ_sort_key)
9495
old_metadata = po.metadata
@@ -119,7 +120,12 @@ def _clone_entry(e: polib.POEntry) -> polib.POEntry:
119120
return clone
120121

121122

122-
def po_make_unique(po):
123+
def po_make_unique(po: polib.POFile) -> polib.POFile:
124+
"""Deduplicate PO entries by (msgid, msgctxt), merging occurrences. Returns a new POFile.
125+
126+
Non-duplicate entries are shared (not cloned) between input and output.
127+
Duplicate entries are cloned before merging to avoid mutating the originals.
128+
"""
123129
entries_dict = OrderedDict()
124130
cloned = set() # keys that have been cloned (due to duplicates)
125131
old_metadata = po.metadata

0 commit comments

Comments
 (0)