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

Commit

Permalink
list_languages
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
why-not-try-calmer committed Feb 20, 2023
1 parent 7a906c6 commit ad0b32d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
24 changes: 19 additions & 5 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,30 @@ def get_translation(
)

@ensure_login
def list_languages(self, project_slug: str, resource_slug: str) -> list[Any]:
def list_languages(self, project_slug: str, resource_slug: str) -> list[str]:
"""
List languages for which there exist translations under the given resource.
"""
if self.projects:
if project := self.projects.get(slug=project_slug):
if resource := project.fetch("resources").get(slug=resource_slug):
logging.info(f"Obtained these languages")
# FIXME: Extract a list[str] mapping to resource languages
return resource
it = tx_api.ResourceLanguageStats.filter(
project=project, resource=resource
).all()

language_codes = []
for tr in it:
"""
FIXME
This is hideous and probably unsound for some language_codes.
Couldn't find a more direct accessor to language codes.
"""
code = str(tr).rsplit("_", 1)[-1][:-1]
language_codes.append(code)

logging.info(f"Obtained these languages: {language_codes}")
return language_codes

raise ValueError(
f"Unable to find any resource with this slug: '{resource_slug}'"
)
Expand All @@ -263,7 +277,7 @@ def create_language(
*,
project_slug: str,
language_code: str,
coordinators: None | list[Any] = None,
coordinators: None | list[str] = None,
):
"""Create a new language resource in the remote Transifex repository"""
if project := self.get_project(project_slug=project_slug):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test8_get_translation(self):

def test9_project_exists(self):
verdict = self.tx.project_exists(project_slug=self.project_slug)
assert verdict is not None
assert verdict

def test10_ping(self):
self.tx.ping()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test1_init(self):
assert passed

def test2_push(self):
result = self.runner.invoke(cli, ["push", "-in", str(self.path_to_file)])
result = self.runner.invoke(cli, ["push", "-in", str(self.path_to_input_dir)])
passed = result.exit_code == 0
logging.info(result.output)
assert passed
Expand Down
4 changes: 4 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ def test1_map_async(self):
def test2_map_async(self):
res = concurrently(fn=fn, args=self.args)
assert res == self.res


if __name__ == "__main__":
unittest.main()

0 comments on commit ad0b32d

Please sign in to comment.