Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Beaking backward compat. with 'get_translation' now requiring 'path_t…
Browse files Browse the repository at this point in the history
…o_OUTPUT_file'.
  • Loading branch information
why-not-try-calmer committed Feb 19, 2023
1 parent b05ed9c commit 9e2cfe9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 9 additions & 3 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9e2cfe9

Please sign in to comment.