Skip to content

Commit

Permalink
add extract_prefix avoid prefix_path/README will save to README
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin-jun-xiang committed Sep 25, 2023
1 parent 4abc5d9 commit 3d0609d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion translation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import subprocess
from multiprocessing.dummy import Pool as ThreadPool

Expand Down Expand Up @@ -66,6 +67,15 @@ def translate_content(content, output_lang):
return response


def extract_prefix(filename):
"""Extract file prefix path"""
pattern = re.compile(r'(.*/).*')
match = pattern.match(filename)
prefix = match.group(1) if match else ''

return prefix


def main():
git_diff_command = "git diff --name-only HEAD~1 HEAD"
return_code, stdout, stderr = run_shell_command(git_diff_command)
Expand All @@ -81,14 +91,16 @@ def main():
return
print(f'{file} changed.')

prefix_path = extract_prefix(file)

with open(file, "r", encoding="utf-8") as f:
content = f.read()

def multi_exec(output_lang: str):
if output_lang in file:
return
translated_content = translate_content(content, output_lang)
output_file = f'README.{output_lang}.md'
output_file = f'{prefix_path}README.{output_lang}.md'
output_file = output_file.replace('.en', '')

with open(output_file, "w", encoding="utf-8") as f:
Expand Down

0 comments on commit 3d0609d

Please sign in to comment.