Skip to content

Commit 29f623d

Browse files
healqqclaude
andcommitted
fix: guard get_language_resources() response and document it (AX-147)
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ade93da commit 29f623d

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,25 @@ for language in deepl_client.get_languages_for_resource(
657657
# Example: "German (de) supports formality"
658658
```
659659

660+
#### Listing resources and their features
661+
662+
`get_language_resources()` uses the `/v3/languages/resources` endpoint and
663+
returns the resources the API offers (translate_text, glossary, write, etc.) as
664+
a list of `LanguageResourceInfo` objects. Each has `resource` (the name),
665+
`features` (a map from feature name to `ResourceFeature`) and
666+
`supports(feature)`. A `ResourceFeature` has `name`, `needs_source_support` and
667+
`needs_target_support`: `True` means the source (or target) language must
668+
support the feature for it to be available, `None` means the API did not
669+
specify it.
670+
671+
```python
672+
for resource in deepl_client.get_language_resources():
673+
for feature in resource.features.values():
674+
if feature.needs_target_support:
675+
print(f"{resource.resource}: {feature.name} needs target support")
676+
# Example: "translate_text: formality needs target support"
677+
```
678+
660679
#### Listing available glossary languages
661680

662681
Glossaries are supported for a subset of language pairs. To retrieve those

‎deepl/deepl_client.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ def get_language_resources(self) -> List[LanguageResourceInfo]:
746746
"v3/languages/resources", method="GET"
747747
)
748748
self._raise_for_status(status, content, json)
749-
return [LanguageResourceInfo.from_json(resource) for resource in json]
749+
resources = json if (json and isinstance(json, list)) else []
750+
return [LanguageResourceInfo.from_json(r) for r in resources]
750751

751752
def get_all_style_rules(
752753
self,

0 commit comments

Comments
 (0)