Skip to content

Commit 4bfca97

Browse files
Parvati-DeepLCopilotshirgoldbird
authored
Added guide for translating between language variants (#217)
* Add guide for translating between language variants * Update docs/learning-how-tos/examples-and-guides/translating-between-variants.mdx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * translate-between-variants updated example to json * rewrite variants guide with diataxis-style subagent * added disclaimers * updated per claude subagent readme * updated to include Shir's commit and disclaimer --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Shir Goldberg <3937986+shirgoldbird@users.noreply.github.com>
1 parent 5303f30 commit 4bfca97

4 files changed

Lines changed: 138 additions & 3 deletions

File tree

api-reference/translate.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Note that we do not include examples for our client libraries in every single se
169169
<Info>
170170
Please note that the Translate API is intended to be used for translation between different languages, but requests with the same source and target language are still counted toward billing.
171171

172-
If trying to convert between variants of the same language (e.g. `EN-US` to `EN-GB`), please consider using the [/write/rephrase](/api-reference/improve-text) API instead. Please see [here](/docs/getting-started/supported-languages#text-improvement-languages-deepl-api-for-write) for supported target languages for this use case. Translating between variants of the same language will result in no change to the text.
172+
If trying to convert between variants of the same language (e.g. `EN-US` to `EN-GB`), please refer to [this guide](/docs/learning-how-tos/examples-and-guides/translating-between-variants). Translating between variants of the same language will result in no change to the text.
173173
</Info>
174174

175175
### Request Body Descriptions

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
"docs/learning-how-tos/examples-and-guides/placeholder-tags",
6969
"docs/learning-how-tos/examples-and-guides/first-things-to-try-with-the-deepl-api",
7070
"docs/learning-how-tos/examples-and-guides/glossaries-in-the-real-world",
71-
"docs/learning-how-tos/examples-and-guides/deepl-mcp-server-how-to-build-and-use-translation-in-llm-applications"
71+
"docs/learning-how-tos/examples-and-guides/deepl-mcp-server-how-to-build-and-use-translation-in-llm-applications",
72+
"docs/learning-how-tos/examples-and-guides/translating-between-variants"
7273
]
7374
}
7475
]

docs/getting-started/supported-languages.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public: true
55
---
66

77
<Info>
8-
If trying to convert between variants of the same language (e.g. `EN-US` to `EN-GB`), please consider using the [/write/rephrase](/api-reference/improve-text) API. Please see [here](#text-improvement-languages-deepl-api-for-write) for supported target languages for this use case.
8+
If trying to convert between variants of the same language (e.g. `EN-US` to `EN-GB`), please refer to [this guide](/docs/learning-how-tos/examples-and-guides/translating-between-variants).
99
</Info>
1010

1111
### Translation source languages
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: "Translating Between Language Variants"
3+
description: "Learn how to translate between language variants, like British English and US English, using the DeepL API."
4+
public: true
5+
---
6+
7+
**This guide shows you:**
8+
- How to translate between language variants (e.g., `en-US` to `en-GB`, `pt-PT` to `pt-BR`)
9+
- Which method to choose: Write API, style rules, or custom instructions
10+
- An example workflow for converting American English to British English
11+
12+
---
13+
14+
## Methods for translating between variants
15+
16+
You can use the DeepL API to translate between variants of the same language using 3 methods:
17+
18+
### 1. DeepL Write API
19+
20+
Use the [/write/rephrase](/api-reference/improve-text) endpoint to rephrase text into the target language variant.
21+
22+
**When to use this:**
23+
- You're translating shorter texts (headlines, product names, brief descriptions)
24+
- You want high-quality rephrasing alongside variant translation
25+
26+
```bash Example cURL request
27+
curl -X POST 'https://api.deepl.com/v2/write/rephrase' \
28+
--header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \
29+
--header 'Content-Type: application/json' \
30+
--data '{
31+
"text": ["Check out the new fall colors!"],
32+
"target_lang": "en-GB"
33+
}'
34+
```
35+
36+
```json Example response
37+
{
38+
"improvements": [
39+
{
40+
"text": "Check out the new autumn colours!",
41+
"detected_source_language": "en",
42+
"target_language": "en-GB"
43+
}
44+
]
45+
}
46+
```
47+
48+
<Warning>
49+
For longer texts, the Write API may rephrase and enhance content beyond simple variant conversion. If you need to maintain the exact structure while only updating locale-specific spelling and grammar, use another method.
50+
51+
Please note that currently, the methods outlined below are not fully supported for this use case and may not always perform as intended. We encourage you to conduct your own evaluations.
52+
</Warning>
53+
54+
### 2. Style rules with custom instructions
55+
56+
Create a reusable [style rule](/api-reference/style-rules) with attached `custom_instructions` describing the desired variant translation.
57+
58+
**When to use this:**
59+
- You need to maintain the text's content between variants as precisely as possible
60+
- You need consistent variant transformations across many translation requests
61+
- You want to reuse the same variant rules without repeating the custom instructions
62+
63+
```bash Example cURL request
64+
curl -X POST 'https://api.deepl.com/v2/translate' \
65+
--header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \
66+
--header 'Content-Type: application/json' \
67+
--data '{
68+
"text": ["I went to the pharmacy."],
69+
"target_lang": "en-GB",
70+
"style_id": "your-style-rule-id"
71+
}'
72+
```
73+
74+
```json Example response
75+
{
76+
"translations": [
77+
{
78+
"detected_source_language": "EN",
79+
"text": "I went to the chemist's."
80+
}
81+
]
82+
}
83+
```
84+
85+
<Info>
86+
Glossaries and style rules are unique to each of DeepL's global data centers and are not shared between them.
87+
88+
Clients using the `api-us.deepl.com` endpoint will not be able to access glossaries or style rules created in the UI at this time.
89+
</Info>
90+
91+
### 3. Per-request custom instructions
92+
93+
Add [custom_instructions](/api-reference/translate/request-translation#body-custom-instructions) describing the desired variant translation directly into your `/translate` requests.
94+
95+
**When to use this:**
96+
- You need to maintain the text's content between variants as precisely as possible
97+
- You need ad-hoc, one-off translations with specific variant requirements
98+
- You don't want to manage separate style rules
99+
100+
```bash Example cURL request
101+
curl -X POST 'https://api.deepl.com/v2/translate' \
102+
--header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \
103+
--header 'Content-Type: application/json' \
104+
--data '{
105+
"text": ["I went to the pharmacy."],
106+
"target_lang": "en-GB",
107+
"custom_instructions": ["translate to British English"]
108+
}'
109+
```
110+
111+
```json Example response
112+
{
113+
"translations": [
114+
{
115+
"detected_source_language": "EN",
116+
"text": "I went to the chemist's."
117+
}
118+
]
119+
}
120+
```
121+
122+
You can specify up to 10 custom instructions per request, each with a maximum of 300 characters.
123+
124+
---
125+
126+
## Next steps
127+
128+
Now that you understand how to translate between language variants:
129+
130+
- **Try it yourself:** Test out style rules and custom instructions in the [text translation API playground](/api-reference/translate)
131+
- **Learn about the Write API:** Explore the [/write/rephrase endpoint](/api-reference/improve-text) for high-quality variant translation and rephrasing
132+
- **Manage reusable rules:** Learn how to create [style rules](/api-reference/style-rules) for systematic variant transformations
133+
- **Improve translation quality:** Understand how [the context parameter](/docs/best-practices/working-with-context) can enhance ambiguous translations
134+

0 commit comments

Comments
 (0)