From 9e2cfe97a42f2ef2978806ffb26046e0561cca56 Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Sun, 19 Feb 2023 15:04:10 +0100 Subject: [PATCH] Beaking backward compat. with 'get_translation' now requiring 'path_to_OUTPUT_file'. --- pytransifex/api.py | 12 +++++++++--- tests/test_api.py | 7 +++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pytransifex/api.py b/pytransifex/api.py index db9b77c..e08a817 100644 --- a/pytransifex/api.py +++ b/pytransifex/api.py @@ -190,8 +190,8 @@ def get_translation( project_slug: str, resource_slug: str, language_code: str, - path_to_file: str, - ): + path_to_output_dir: str, + ) -> str: """Fetch the translation resource matching the given language""" language = tx_api.Language.get(code=language_code) @@ -203,13 +203,19 @@ def get_translation( ) translated_content = requests.get(url).text - Path.mkdir(Path(path_to_file), parents=True, exist_ok=True) + path_to_output_dir_as_path = Path(path_to_output_dir) + Path.mkdir(path_to_output_dir_as_path, parents=True, exist_ok=True) + path_to_file = path_to_output_dir_as_path.joinpath( + f"{resource_slug}_{language_code}" + ) + with open(path_to_file, "w") as fh: fh.write(translated_content) logging.info( f"Translations downloaded and written to file (resource: {resource_slug})" ) + return str(path_to_file) else: raise ValueError( diff --git a/tests/test_api.py b/tests/test_api.py index c0d3bea..4c89233 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -80,14 +80,13 @@ def test7_list_languages(self): assert languages is not None def test8_get_translation(self): - path_to_file = self.output_dir.joinpath(f"{self.resource_slug}.po") - self.tx.get_translation( + path_to_ouput_file = self.tx.get_translation( project_slug=self.project_slug, resource_slug=self.resource_slug, language_code="fr_CH", - path_to_file=str(path_to_file), + path_to_output_dir=str(self.output_dir), ) - assert Path.exists(Path.joinpath(self.output_dir, self.resource_slug)) + assert Path.exists(Path(path_to_ouput_file)) def test9_project_exists(self): verdict = self.tx.project_exists(project_slug=self.project_slug)