Untitled
unknown
plain_text
15 days ago
3.0 kB
3
Indexable
import os import subprocess import argparse def process_vue_file(file_path, json_file_path, log_file): # Check if the file has already been processed with open(log_file, 'r') as f: if file_path in f.read(): print(f"Skipping {file_path} as it has already been processed.") return False # Prepare the instructions for Aider instructions = ( "Migrate this Vue component to use vue-i18n for internationalization." "Identify human-readable English text strings like 'Hello World' and replace them with calls to vue-i18n, e.g., {{ $t('hello-world') }}. " "Also, add corresponding entries to the en.json file, e.g., 'hello-world': 'Hello World'." "$t is already available globally. You do not need to import any additional libraries whatsoever." "Some components do not have any english strings that need translating, in which case you can skip the component but also add it to the log file." "When adding new entries to the en.json file, add them at the root level, do not nest" ).strip() # Construct the bash command bash_command = f'aider --message "{instructions}" {file_path} {json_file_path}' # Execute the bash command try: subprocess.run(bash_command, shell=True, check=True) print(f"Successfully processed {file_path}") # Log the processed file with open(log_file, 'a') as f: f.write(f"{file_path}\n") return True except subprocess.CalledProcessError as e: print(f"Error processing {file_path}: {e}") return False def process_folder(folder_path, json_file_path, log_file, limit=None): processed_count = 0 for root, dirs, files in os.walk(folder_path): for file in files: if file.endswith('.vue'): file_path = os.path.join(root, file) if process_vue_file(file_path, json_file_path, log_file): processed_count += 1 if limit is not None and processed_count >= limit: print(f"Reached the limit of {limit} files processed.") return if __name__ == "__main__": parser = argparse.ArgumentParser(description="Process Vue files for i18n migration.") parser.add_argument("--path", required=True, help="Path to the folder containing Vue files") parser.add_argument("--limit", type=int, help="Maximum number of files to process") args = parser.parse_args() # Path to the en.json file json_file_path = "src/lang/locale/en.json" # Path to the log file log_file = "aider-log.txt" # Create the log file if it doesn't exist if not os.path.exists(log_file): open(log_file, 'w').close() # Process the folder process_folder(args.path, json_file_path, log_file, args.limit) print("Processing complete. Check aider-log.txt for the list of processed files.") # Usage: # python aiderTranslate.py --path src/components --limit 1
Editor is loading...
Leave a Comment