diff --git a/src/copy_on_other_languages.py b/src/copy_on_other_languages.py index 78b5e42..1c9602a 100644 --- a/src/copy_on_other_languages.py +++ b/src/copy_on_other_languages.py @@ -1,3 +1,4 @@ +import logging import os import shutil import sys @@ -15,15 +16,20 @@ def copy_on_other_languages(localisation_dir, source_lang, dest_langs): # Delete destination directories if they exist shutil.rmtree(os.path.join(localisation_dir, dest_lang), ignore_errors=True) - # Copy English directory + # Copy source directory shutil.copytree(os.path.join(localisation_dir, source_lang), os.path.join(localisation_dir, dest_lang)) # Edit copied files for root, _, files in os.walk(os.path.join(localisation_dir, dest_lang)): for file in files: - with open(os.path.join(root, file), 'r') as f: - lines = f.readlines() + with open(os.path.join(root, file), 'r', encoding='utf-8') as f: + try: + lines = f.readlines() + except UnicodeDecodeError as e: + logging.error(f'Error when parsing {file}') + logging.exception(e) + continue with open(os.path.join(root, file.replace(f'{source_lang}.yml', f'{dest_lang}.yml')), 'w', encoding='utf-8') as f: f.write(f'\ufeffl_{dest_lang}:\n') @@ -33,4 +39,5 @@ def copy_on_other_languages(localisation_dir, source_lang, dest_langs): if __name__ == '__main__': + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') copy_on_other_languages(sys.argv[1], sys.argv[2], sys.argv[3:])