diff --git a/pytransifex/api.py b/pytransifex/api.py index 201121f..3d71c54 100644 --- a/pytransifex/api.py +++ b/pytransifex/api.py @@ -229,33 +229,15 @@ def get_translation( ) @ensure_login - def list_languages(self, project_slug: str, resource_slug: str) -> list[str]: + def list_languages(self, project_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): - 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) - - logger.info(f"Obtained these languages: {language_codes}") - return language_codes + languages = project.fetch("languages").all() + return [lang.code for lang in languages] - raise ValueError( - f"Unable to find any resource with this slug: '{resource_slug}'" - ) raise ValueError( f"Unable to find any project with this slug: '{project_slug}'" ) diff --git a/pytransifex/interfaces.py b/pytransifex/interfaces.py index 8268dd3..efc4a0e 100644 --- a/pytransifex/interfaces.py +++ b/pytransifex/interfaces.py @@ -61,7 +61,7 @@ def get_translation( raise NotImplementedError @abstractmethod - def list_languages(self, project_slug: str, resource_slug: str) -> list[Any]: + def list_languages(self, project_slug: str) -> list[Any]: raise NotImplementedError @abstractmethod diff --git a/tests/test_api.py b/tests/test_api.py index 6e03ecb..3c661cc 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -77,9 +77,7 @@ def test6_create_language(self): self.tx.create_language(project_slug=self.project_slug, language_code="fr_CH") def test7_list_languages(self): - languages = self.tx.list_languages( - project_slug=self.project_slug, resource_slug=self.resource_slug - ) + languages = self.tx.list_languages(project_slug=self.project_slug) logger.info(f"Languages found: {languages}") assert languages