Skip to content

Commit 6268c54

Browse files
committed
Improve translations processing logic take 5
1 parent e301e08 commit 6268c54

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

scripts/process_translations.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
convert_percents_to_braces,
1616
file_updated,
1717
get_percent_placeholders,
18+
git_add,
1819
parse_resx_filename,
1920
)
2021

@@ -120,6 +121,7 @@ def convert_po_to_lng(*, project_path, english_lng, file, language_code, languag
120121
)
121122
with lng_file.open("w", encoding="utf-8", newline="") as f:
122123
json.dump(lng, f, ensure_ascii=False, indent=2, sort_keys=True)
124+
git_add(lng_file)
123125
logger.info(f"Po file converted to lng file {lng_file}')")
124126

125127

@@ -270,6 +272,7 @@ def generate_resx_from_lng(lng, source_resx_file):
270272
value.text = convert_percents_to_braces(lng[identifier])
271273
with target_resx_file.open("wb") as f:
272274
f.write(ElementTree.tostring(root, encoding="utf-8"))
275+
git_add(target_resx_file)
273276
logger.info("Resx file generated")
274277
return errors
275278

@@ -312,6 +315,7 @@ def process_language_docs(docs_dir):
312315
def convert_docs_po_to_md_file(po_file):
313316
logger.info(f"Converting docs po file {po_file} to md file")
314317
source_md_file = po_file.parent.parent / "en" / po_file.with_suffix(".md").name
318+
target_md_file = po_file.with_suffix(".md")
315319
if not source_md_file.is_file():
316320
return [
317321
f"Failed to find source file for {po_file}. File {source_md_file} not found."
@@ -330,7 +334,7 @@ def convert_docs_po_to_md_file(po_file):
330334
"-p",
331335
po_file,
332336
"-s",
333-
po_file.with_suffix(".md"),
337+
target_md_file,
334338
source_md_file,
335339
],
336340
stdin=subprocess.DEVNULL,
@@ -340,6 +344,7 @@ def convert_docs_po_to_md_file(po_file):
340344
process.communicate(None, timeout=10)
341345
if process.returncode != 0:
342346
raise RuntimeError(f"po2md failed with code {process.returncode}")
347+
git_add(target_md_file)
343348
logger.info("Po file converted to md")
344349
return []
345350

scripts/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ def file_updated(file_path):
4242
return return_code == 0
4343

4444

45+
def git_add(file_path):
46+
file_path = Path(file_path).resolve()
47+
quoted_file_path = shlex.quote(file_path.name)
48+
subprocess.call(
49+
["git", "add", quoted_file_path],
50+
cwd=str(file_path.parent),
51+
stdout=subprocess.DEVNULL,
52+
stderr=subprocess.DEVNULL,
53+
)
54+
55+
4556
def parse_resx_filename(resx_filename):
4657
match = RESX_FILE_REGEX.match(resx_filename)
4758
return match[1], match[2]

0 commit comments

Comments
 (0)