-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupdate_potfiles.py
More file actions
executable file
·55 lines (42 loc) · 1.64 KB
/
update_potfiles.py
File metadata and controls
executable file
·55 lines (42 loc) · 1.64 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
#!/usr/bin/env python
import sys
import os
SRC_DIR = "src/"
POTFILES_PATH = f"{os.getenv('POTFILES_FILE')}"
def find_translation_files():
translation_files = []
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.Ignition.desktop.in",
"data/io.github.flattool.Ignition.metainfo.xml.in",
"data/io.github.flattool.Ignition.gschema.xml",
]
translation_files = sorted(translation_files)
return translation_files
def write_to_file(files):
with open(POTFILES_PATH, "w") as f:
for line in files:
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")