|
| 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