diff --git a/infomaniak-build-tools/translate_release_notes.py b/infomaniak-build-tools/translate_release_notes.py index 3d0c58bfb..6021e98c7 100755 --- a/infomaniak-build-tools/translate_release_notes.py +++ b/infomaniak-build-tools/translate_release_notes.py @@ -22,6 +22,7 @@ import deepl import errno import os +from pathlib import Path import re import shutil import subprocess @@ -54,18 +55,23 @@ def version_regex(arg_value, pattern=re.compile(r'^(\d+\.)?(\d+\.)?(\*|\d+)')): parser.add_argument('-d', '--date', metavar="", type=int, help='The planned release date (defaults to today)', default=datetime.date.today().strftime('%Y%m%d')) args = parser.parse_args() -if not os.path.isfile(f"kDrive-template.html"): - sys.exit("Unable to find kDrive-template.html."); +if not os.path.isfile("kDrive-template.html"): + sys.exit("Unable to find 'kDrive-template.html'.") fullName = f"kDrive-{args.version}.{args.date}" -dirPath = f"../release_notes/{fullName}" +dirPath = Path(__file__).parent.parent / "release_notes" + +if not dirPath.exists(): + sys.exit(f"Release notes path does not exist: '{dirPath}'. \nAborting.") + +dirPath = dirPath / Path(fullName) deepl_key = os.getenv("DEEPL_AUTH_KEY") if not deepl_key: - sys.exit("error: The DeepL API key is not set in env"); + sys.exit("error: The DeepL API key is not set in env") translator = deepl.Translator(deepl_key) -target_lang = [ +target_languages = [ 'FR', 'DE', 'ES', @@ -78,16 +84,15 @@ def version_regex(arg_value, pattern=re.compile(r'^(\d+\.)?(\d+\.)?(\*|\d+)')): 'macOS' ] -def split_os(lang): - lang_ext = f"-{lang.lower()}" if lang != 'en' else "" +def split_os(lang, fullName): + lang_ext = lang.lower() for os_name in os_list: - os_ext = f"-{os_name.lower()}" if os_name != 'macOS' else "" - if os_name != 'macOS': - shutil.copyfile(f"{fullName}{lang_ext}.html", f"{fullName}{os_ext}{lang_ext}.html") - with open(f"{fullName}{os_ext}{lang_ext}.html", "r") as f: + os_ext = os_name.lower() + shutil.copyfile(f"{fullName}-{lang_ext}.html", f"{fullName}-{os_ext}-{lang_ext}.html") + with open(f"{fullName}-{os_ext}-{lang_ext}.html", "r") as f: lines = f.readlines() - with open(f"{fullName}{os_ext}{lang_ext}.html", "w") as f: + with open(f"{fullName}-{os_ext}-{lang_ext}.html", "w") as f: for line in lines: if any(os_note in line for os_note in os_list): if (f"