Skip to content

Commit

Permalink
Call xgettext with UTF-8 and parse lines
Browse files Browse the repository at this point in the history
Reference: #13
Reference: #14
Reported-by: Armijn Hemel @armijnhemel
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Mar 15, 2024
1 parent 364314a commit d691562
Show file tree
Hide file tree
Showing 5 changed files with 3,359 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/source_inspector/strings_xgettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ def collect_strings(location, strip=False):

rc, result, err = command.execute(
cmd_loc="xgettext",
args=["--omit-header", "--no-wrap", "--extract-all", "--output=-", location],
args=[
"--omit-header",
"--no-wrap",
"--extract-all",
"--from-code=UTF-8",
"--output=-",
location,
],
to_files=False,
)

Expand Down Expand Up @@ -110,8 +117,14 @@ def parse_po_text(po_text, strip=False):
strings = []
for line in lines:
if line.startswith("#: "):
_, _, start_line = line.rpartition(":")
line_numbers.append(int(start_line.strip()))
# we can have either of these two forms:
# #: lineedit.c:1571 lineedit.c:1587 lineedit.c:163
# #: lineedit.c:1571
_, _, line = line.partition("#: ")
filename, _, _ = line.partition(":")
numbers = line.replace(filename + ":", "")
numbers = [int(l) for ln in numbers.split() if (l := ln.strip())]
line_numbers.extend(numbers)

elif line.startswith(
(
Expand Down
Loading

0 comments on commit d691562

Please sign in to comment.