-
Notifications
You must be signed in to change notification settings - Fork 4
v3/languages beta #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
daniel-jones-dev
wants to merge
32
commits into
main
Choose a base branch
from
v3-languages-beta
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
v3/languages beta #239
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b85bd3e
Documentation edits made through Mintlify web editor
mintlify[bot] b245a45
updates to v3/languages endpoints
daniel-jones-dev af0c7bb
move v2 pages to legacy area
daniel-jones-dev 3f43396
consistent feature name "glossary_id"
daniel-jones-dev f9877b4
simple examples
daniel-jones-dev c60b15f
revert naming v2 languages legacy
daniel-jones-dev 9719d74
rewrites and improvements
daniel-jones-dev 7c3ff28
rewrites and improvements
daniel-jones-dev d5f1175
rewrites and improvements
daniel-jones-dev 3c88b7a
rewrites and improvements
daniel-jones-dev 789ac76
page title
daniel-jones-dev f2b6cee
whitespace
daniel-jones-dev 53a433d
add summary of example
daniel-jones-dev 9734348
add exceptions endpoint, better wording
daniel-jones-dev b8bfd8b
openapi for exceptions endpoint
daniel-jones-dev 7e2879b
rewording
daniel-jones-dev 3e1ca97
rewording
daniel-jones-dev 3e2fdad
remove old "glossary" feature
daniel-jones-dev f71f465
change "code" to "lang" for consistency
daniel-jones-dev b0c1cbc
rename glossary_id to glossary
daniel-jones-dev 932342a
clarify language code casing
daniel-jones-dev 250b870
add products endpoint
daniel-jones-dev 5cba33f
make product query parameter required
daniel-jones-dev f7e34bc
add docs about products endpoint
daniel-jones-dev cf656b0
removing source_lang and target_lang filters from source and target e…
daniel-jones-dev ad63ca0
reflow text in overview for clarity
daniel-jones-dev 23b93ff
better migration explanation for glossaries
daniel-jones-dev ea453c8
rewording Product features section
daniel-jones-dev 7c695b2
rewording
daniel-jones-dev 7e5ac35
rewording
daniel-jones-dev 5281a16
combine /source and /target endpoints
daniel-jones-dev e56d808
combine source and target
daniel-jones-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
170 changes: 170 additions & 0 deletions
170
api-reference/api-reference/retrieve-languages/language-feature-use-cases-beta.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| --- | ||
| title: 'Common use cases [BETA]' | ||
| description: "Pseudocode examples for common language and feature lookup patterns using the v3/languages endpoints." | ||
| --- | ||
|
|
||
| This page shows how to use the `/v3/languages` endpoints for common integration tasks. Examples are written | ||
| as pseudocode and are product-agnostic unless otherwise noted. | ||
|
|
||
| For background on how features and feature dependency types work, see the | ||
| [overview](/api-reference/api-reference/retrieve-languages/retrieve-supported-languages-by-product-beta). | ||
|
|
||
| <Note> | ||
| The examples below do not account for language pair exceptions. For most integrations this is fine — exceptions | ||
| are rare and the API handles them gracefully by disabling the unsupported feature rather than failing. If you | ||
| need precise feature support for specific language pairs, see | ||
| [Handling language pair exceptions](#handling-language-pair-exceptions) at the end of this page. | ||
| </Note> | ||
|
|
||
| --- | ||
|
|
||
| ## Populate source and target language dropdowns | ||
|
|
||
| A single call to `GET /v3/languages` returns all languages for a product. Filter by `usable_as_source` and | ||
| `usable_as_target` to populate each dropdown separately. | ||
|
|
||
| ``` | ||
| GET /v3/languages?product=translate_text | ||
|
|
||
| languages = response | ||
|
|
||
| source_options = languages.filter(l => l.usable_as_source) | ||
| target_options = languages.filter(l => l.usable_as_target) | ||
|
|
||
| render source_dropdown(source_options) | ||
| render target_dropdown(target_options) | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Show formality options only when supported | ||
|
|
||
| `formality` is a target-only feature. Check the selected target language's `features` array — no need to look | ||
| at the source language. | ||
|
|
||
| ``` | ||
| GET /v3/languages?product=translate_text | ||
|
|
||
| languages = response | ||
| target = languages.find(l => l.lang == selected_target_lang) | ||
|
|
||
| if target.features.includes("formality"): | ||
| show formality_selector // e.g. ["default", "more", "less"] | ||
| else: | ||
| hide formality_selector | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Check if a glossary can be used for a given language pair | ||
|
|
||
| `glossary` is a source-and-target feature — both languages must support it. | ||
|
|
||
| ``` | ||
| GET /v3/languages?product=translate_text | ||
|
|
||
| languages = response | ||
|
|
||
| source = languages.find(l => l.lang == source_lang) | ||
| target = languages.find(l => l.lang == target_lang) | ||
|
|
||
| glossary_allowed = source.features.includes("glossary") | ||
| and target.features.includes("glossary") | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## List target languages that accept glossaries from a given source language | ||
|
|
||
| Filter to targets where both the source and target support the `glossary` feature. | ||
|
|
||
| ``` | ||
| GET /v3/languages?product=translate_text | ||
|
|
||
| languages = response | ||
| source_lang = "en" | ||
|
|
||
| source = languages.find(l => l.lang == source_lang) | ||
|
|
||
| if not source.features.includes("glossary"): | ||
| return [] // source doesn't support glossary at all | ||
|
|
||
| targets_with_glossary = languages | ||
| .filter(l => l.usable_as_target) | ||
| .filter(l => l.features.includes("glossary")) | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Show writing style options for the Write product | ||
|
|
||
| `writing_style` is a target-only feature on the `write` product. Check the target language's `features` array. | ||
|
|
||
| ``` | ||
| GET /v3/languages?product=write | ||
|
|
||
| languages = response | ||
| target = languages.find(l => l.lang == selected_target_lang) | ||
|
|
||
| if target.features.includes("writing_style"): | ||
| show writing_style_selector | ||
| else: | ||
| hide writing_style_selector | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Determine feature support programmatically | ||
|
|
||
| Use `/v3/languages/products` to drive feature checks at runtime — without hardcoding which features are | ||
| target-only or source-and-target into your client. | ||
|
|
||
| ``` | ||
| GET /v3/languages/products | ||
| GET /v3/languages?product=translate_text | ||
|
|
||
| products = first response | ||
| languages = second response | ||
|
|
||
| product = products.find(p => p.name == "translate_text") | ||
| source = languages.find(l => l.lang == source_lang) | ||
| target = languages.find(l => l.lang == target_lang) | ||
|
|
||
| for feature in product.features: | ||
| supported = true | ||
| if feature.required_on_source and not source.features.includes(feature.name): | ||
| supported = false | ||
| if feature.required_on_target and not target.features.includes(feature.name): | ||
| supported = false | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Handling language pair exceptions | ||
|
|
||
| In rare cases, feature support for a specific pair differs from what the individual language objects indicate. | ||
| The `/v3/languages/exceptions` endpoint exposes these cases. When an exception exists for a pair, its `features` | ||
| array is authoritative — use it directly instead of intersecting the individual language `features` arrays. | ||
|
|
||
| The example below shows a full glossary pair check that accounts for exceptions: | ||
|
|
||
| ``` | ||
| GET /v3/languages?product=translate_text | ||
| GET /v3/languages/exceptions?product=translate_text | ||
|
|
||
| languages = first response | ||
| exceptions = second response | ||
|
|
||
| exception = exceptions.find(e => e.source_lang == source_lang && e.target_lang == target_lang) | ||
|
|
||
| if exception: | ||
| features = exception.features | ||
| else: | ||
| source = languages.find(l => l.lang == source_lang) | ||
| target = languages.find(l => l.lang == target_lang) | ||
| features = intersect(source.features, target.features) | ||
|
|
||
| glossary_allowed = features.includes("glossary") | ||
| ``` | ||
|
|
||
| The same pattern applies to any feature check — replace `"glossary"` with the feature you are checking. |
102 changes: 102 additions & 0 deletions
102
api-reference/api-reference/retrieve-languages/migrate-from-v2-languages.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| --- | ||
| title: 'Migrating from v2/languages' | ||
| description: "How to migrate from the v2/languages endpoint to the v3/languages endpoints." | ||
| --- | ||
|
|
||
| This page covers the differences between the `/v2/languages` endpoint and the v3 endpoints, and how to update your integration. | ||
|
|
||
| <Warning> | ||
| Only `GET` requests are supported on the v3 endpoints. Unlike `/v2/languages`, POST is not supported. | ||
| </Warning> | ||
|
|
||
| ## What changed | ||
|
|
||
| ### Single endpoint for source and target | ||
|
|
||
| v2 uses a single endpoint with a `type` query parameter to distinguish source from target: | ||
|
|
||
| ``` | ||
| GET /v2/languages?type=source | ||
| GET /v2/languages?type=target | ||
| ``` | ||
|
|
||
| v3 uses a single endpoint that returns all languages for a product, with each language indicating whether it is | ||
| usable as a source, a target, or both: | ||
|
|
||
| ``` | ||
| GET /v3/languages?product=translate_text | ||
| ``` | ||
|
|
||
| ### New product identifiers | ||
|
|
||
| v2 languages are implicitly tied to text and document translation. v3 introduces an explicit `product` parameter that applies across all DeepL API products: | ||
|
|
||
| | v2 | v3 `product` value | | ||
| |---|---| | ||
| | *(implicit, text/document translation only)* | `translate_text` | | ||
| | *(implicit, text/document translation only)* | `translate_document` | | ||
| | *(separate `/v2/glossary-language-pairs` endpoint)* | `glossary` | | ||
| | *(not supported)* | `voice` | | ||
| | *(not supported)* | `write` | | ||
|
|
||
| The v3 endpoints replace both `/v2/languages` and `/v2/glossary-language-pairs`. | ||
|
|
||
| ### Features instead of `supports_formality` | ||
|
|
||
| v2 target languages include a boolean `supports_formality` field. v3 replaces this with a `features` array that covers additional capabilities per product: | ||
|
|
||
| | v2 field | v3 equivalent | | ||
| |---|---| | ||
| | `"supports_formality": true` | `"features": ["formality"]` on the language object | | ||
|
|
||
| For example, querying languages for text translation: | ||
|
|
||
| ```sh | ||
| curl -X GET 'https://api.deepl.com/v3/languages?product=translate_text' \ | ||
| --header 'Authorization: DeepL-Auth-Key [yourAuthKey]' | ||
| ``` | ||
|
|
||
| ```json Example response (truncated) | ||
| [ | ||
| { | ||
| "lang": "de", | ||
| "name": "German", | ||
| "usable_as_source": true, | ||
| "usable_as_target": true, | ||
| "features": ["formality", "tag_handling", "glossary"] | ||
| }, | ||
| { | ||
| "lang": "en-US", | ||
| "name": "English (American)", | ||
| "usable_as_source": false, | ||
| "usable_as_target": true, | ||
| "features": ["tag_handling", "glossary"] | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| The response indicates German supports `formality`, but English (American) does not. | ||
|
|
||
| See the [overview](/api-reference/api-reference/retrieve-languages/retrieve-supported-languages-by-product-beta) for the full list of features per product. | ||
|
|
||
| ### Response field names | ||
|
|
||
| | v2 field | v3 field | | ||
| |----------------------|------------------------| | ||
| | `language` | `lang` | | ||
| | `name` | `name` *(unchanged)* | | ||
| | `supports_formality` | `features["formality]` | | ||
|
|
||
| ### Language code casing | ||
|
|
||
| v2 returned language codes in non-standard casing (e.g. `EN-US`, `ZH-HANT`). v3 returns codes compliant with BCP 47: lowercase base language (`en`, `de`), uppercase region subtag (`en-US`, `pt-BR`), and title-case script subtag (`zh-Hant`). | ||
|
|
||
| DeepL accepts language codes case-insensitively as input across all endpoints. However, if your integration stores or compares codes returned by `/v2/languages`, update those comparisons to be case-insensitive or to expect the new casing. | ||
|
|
||
| ## Migrating glossary language pair queries | ||
|
|
||
| If you currently use `/v2/glossary-language-pairs` to discover which language pairs are supported for glossaries, use one of the following: | ||
|
|
||
| - `GET /v3/languages?product=glossary` to check which languages support glossary management (i.e. creating a glossary for that language). Filter by `usable_as_source` and `usable_as_target` as needed. Any combination of a valid source and target language is a supported glossary language pair. | ||
| - `GET /v3/languages?product=translate_text` to check which languages support using a glossary during text translation. Languages that include `"glossary"` in their `features` array support the `glossary_id` parameter on the translate endpoint. | ||
| - Similarly, use `product=translate_document` to check glossary support for document translation. |
4 changes: 4 additions & 0 deletions
4
...nce/api-reference/retrieve-languages/retrieve-language-pair-exceptions-beta.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| openapi: get /v3/languages/exceptions | ||
| title: "Retrieve language pair exceptions [BETA]" | ||
| --- | ||
4 changes: 4 additions & 0 deletions
4
api-reference/api-reference/retrieve-languages/retrieve-languages-beta.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| openapi: get /v3/languages | ||
| title: "Retrieve languages [BETA]" | ||
| --- |
4 changes: 4 additions & 0 deletions
4
api-reference/api-reference/retrieve-languages/retrieve-products-beta.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| openapi: get /v3/languages/products | ||
| title: "Retrieve language products [BETA]" | ||
| --- |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want these beta's in the URLs? Unless you want to hide the URLs for the time being, you'll eventually need to redirect these to the ultimate URLs... but I also don't know your entire scheme here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I'll check. We want to limit discovery at first, so I'll remove the beta from the URLs and hide them in the sidebar.