From bd1884e51aae82cb3d9d036d960f20b897ce9efa Mon Sep 17 00:00:00 2001 From: Mark Sun <50621638+WeepsDanky@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:04:00 +0800 Subject: [PATCH] Update translate.py --- translate.py | 98 +--------------------------------------------------- 1 file changed, 1 insertion(+), 97 deletions(-) diff --git a/translate.py b/translate.py index 8350717..daf5bd6 100644 --- a/translate.py +++ b/translate.py @@ -63,100 +63,4 @@ def translate_markdown_files(input_folder, output_folder, target_language="japan print(f"Translation completed. Translated files are saved in {output_folder}") # Example usage -# translate_markdown_files("zh_CN/explore", "jp/explore", target_language="japanese") - -# ------------------------------------------------------------ -# Create a new folder for the translated files -import os -import shutil - -def create_empty_folders(source_dir, target_dir): - """ - Create a set of empty folders in the target directory with the same folder structure as the source directory. - - :param source_dir: Path to the source directory. - :param target_dir: Path to the target directory where the empty folders will be created. - """ - # Ensure the target directory exists - os.makedirs(target_dir, exist_ok=True) - - # Walk through the source directory - for dirpath, dirnames, filenames in os.walk(source_dir): - # Construct the path structure in the target directory - structure = os.path.join(target_dir, os.path.relpath(dirpath, source_dir)) - # Create each directory in the target directory - for dirname in dirnames: - os.makedirs(os.path.join(structure, dirname), exist_ok=True) - -# Example usage -source_directory = 'zh_CN' -target_directory = 'en/.gitbook' -# create_empty_folders(source_directory, target_directory) - - -# ------------------------------------------------------------ -import os -import re -import shutil - -def check_and_move_images(markdown_dir, images_dir, target_images_dir): - """ - Check if the images used in the markdown files exist and then move them to a specified location. - If images are already at the specified location, then check the existence. - - :param markdown_dir: Directory containing markdown files. - :param images_dir: Directory containing images referenced in the markdown files. - :param target_images_dir: Target directory to move the images to. - """ - # Regex to find markdown image syntax - img_regex = r'