blacked
modified: translate_content.py
This commit is contained in:
parent
3eb23977a0
commit
e14c9410ed
1 changed files with 15 additions and 5 deletions
|
|
@ -63,11 +63,17 @@ def replace_special_content(content):
|
|||
replaced_content = content
|
||||
for pattern, template in patterns:
|
||||
if "CODE" in template:
|
||||
replaced_content = pattern.sub(lambda m: replacer(m, template, "code"), replaced_content)
|
||||
replaced_content = pattern.sub(
|
||||
lambda m: replacer(m, template, "code"), replaced_content
|
||||
)
|
||||
elif "URI" in template:
|
||||
replaced_content = pattern.sub(lambda m: replacer(m, template, "uri"), replaced_content)
|
||||
replaced_content = pattern.sub(
|
||||
lambda m: replacer(m, template, "uri"), replaced_content
|
||||
)
|
||||
elif "IMG" in template:
|
||||
replaced_content = pattern.sub(lambda m: replacer(m, template, "img"), replaced_content)
|
||||
replaced_content = pattern.sub(
|
||||
lambda m: replacer(m, template, "img"), replaced_content
|
||||
)
|
||||
|
||||
return replaced_content, placeholders
|
||||
|
||||
|
|
@ -186,7 +192,9 @@ def process_file(file_path):
|
|||
translated_replaced_content = translate_text(replaced_content, lang_full)
|
||||
|
||||
# Restore special content
|
||||
translated_content = restore_special_content(translated_replaced_content, placeholders)
|
||||
translated_content = restore_special_content(
|
||||
translated_replaced_content, placeholders
|
||||
)
|
||||
full_rst_content = "".join(new_header) + translated_content
|
||||
|
||||
# Save .rst and calculate hash
|
||||
|
|
@ -220,7 +228,9 @@ def process_file(file_path):
|
|||
def main():
|
||||
for root, _, files in os.walk(CONTENT_DIR):
|
||||
for file in files:
|
||||
if file.endswith(".rst") and not any(f"/{lang}/" in root for lang in TOP_20_LANGS.keys()):
|
||||
if file.endswith(".rst") and not any(
|
||||
f"/{lang}/" in root for lang in TOP_20_LANGS.keys()
|
||||
):
|
||||
process_file(os.path.join(root, file))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue