forked from python/python-docs-ja
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_empty_msgstr.py
More file actions
42 lines (35 loc) · 1.65 KB
/
find_empty_msgstr.py
File metadata and controls
42 lines (35 loc) · 1.65 KB
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
#!/usr/bin/env python3
import re
import sys
def find_empty_msgstr(filename):
"""Find entries with truly empty msgstr"""
with open(filename, 'r', encoding='utf-8') as f:
content = f.read()
# Pattern to match complete po entries
pattern = r'(#:.*?\nmsgid.*?\nmsgstr[^\n]*(?:\n"[^"]*")*)'
entries = re.findall(pattern, content, re.DOTALL)
empty_entries = []
for entry in entries:
# Check if msgstr is truly empty (just msgstr "" with no following quoted strings)
if re.search(r'msgstr ""\s*\n(?![\s]*")', entry):
# Extract msgid content
msgid_match = re.search(r'msgid\s+"([^"]*)"(?:\s*\n\s*"([^"]*)")*', entry)
if msgid_match:
msgid_content = msgid_match.group(1)
if msgid_match.group(2):
msgid_content += msgid_match.group(2)
# Skip obvious code examples
if not any(x in msgid_content for x in ['def ', 'class ', '>>>', 'import ', 'return ']):
if msgid_content.strip(): # Non-empty msgid
empty_entries.append({
'msgid': msgid_content,
'entry': entry[:200] + '...' if len(entry) > 200 else entry
})
print(f"Found {len(empty_entries)} truly empty msgstr entries:")
for i, entry in enumerate(empty_entries[:10], 1):
print(f"{i}: {entry['msgid']}")
print(f" Entry: {entry['entry']}")
print()
if __name__ == "__main__":
filename = sys.argv[1] if len(sys.argv) > 1 else 'library/typing.po'
find_empty_msgstr(filename)