-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_potfiles.py
More file actions
56 lines (43 loc) · 1.7 KB
/
update_potfiles.py
File metadata and controls
56 lines (43 loc) · 1.7 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
from typing import List
import sys
import os
SRC_DIR = 'src/'
POTFILES_PATH = os.getenv('POTFILES_FILE') or ''
def find_translation_files() -> List[str]:
translation_files: List[str] = []
for root, _, files in os.walk(SRC_DIR):
for filename in files:
file_path = os.path.join(root, filename)
# Only check text-based files (e.g., .py, .html, etc.)
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
if "_('" in content or '_("' in content:
translation_files.append(file_path)
except (UnicodeDecodeError, FileNotFoundError):
# Skip files that can't be decoded (binary or unreadable)
continue
# Manually add in non-src files to be translated
translation_files += [
'data/io.github.flattool.Brim.desktop.in',
'data/io.github.flattool.Brim.metainfo.xml.in',
'data/io.github.flattool.Brim.gschema.xml',
]
translation_files = sorted(translation_files)
return translation_files
def write_to_file(file_paths: List[str]):
with open(POTFILES_PATH, 'w') as f:
for line in file_paths:
f.write(f'{line}\n')
print('Wrote', line, 'to', POTFILES_PATH)
if __name__ == "__main__":
if not os.path.exists(POTFILES_PATH):
print('No POTFIELS file found at:', POTFILES_PATH)
sys.exit(1)
if not os.path.exists(SRC_DIR):
print('SRC_DIR path is not found, path:', SRC_DIR)
sys.exit(1)
translation_files = find_translation_files()
write_to_file(translation_files)
print('Updated', POTFILES_PATH, '\n')