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

List_languages fixed thx to Transifex support #22

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'"
)
Expand Down
2 changes: 1 addition & 1 deletion pytransifex/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down