Skip to content
Open
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
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"docs/learning-how-tos/examples-and-guides/translation-beginners-guide",
"docs/learning-how-tos/examples-and-guides/how-to-use-context-parameter",
"docs/learning-how-tos/examples-and-guides/translating-between-variants",
"docs/learning-how-tos/examples-and-guides/customizations-for-variants",
"docs/learning-how-tos/examples-and-guides/placeholder-tags",
"docs/best-practices/language-detection"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: "How to Apply Customizations to Variants"
description: "Learn how to apply glossaries and style rules when translating into language variants like FR-CA or EN-GB."
public: true
---

## Glossaries

### Creation — root codes only

Glossaries must be created using the root/base language code. Attempting to create a glossary with a variant code (e.g. `zh-Hant`, `pt-BR`, `fr-CA`) will fail. Use the base code instead:
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc states that creating a glossary with a variant code (e.g. zh-Hant, pt-BR) “will fail”. In the published OpenAPI description we only document that specifying a variant for EN/PT/ZH is not necessary, not that it is rejected. Consider rewording to avoid an incorrect guarantee (e.g. “use the base/root code; variants are not required / may not be accepted”).

Suggested change
Glossaries must be created using the root/base language code. Attempting to create a glossary with a variant code (e.g. `zh-Hant`, `pt-BR`, `fr-CA`) will fail. Use the base code instead:
Glossaries should be created using the root/base language code. Variant codes (e.g. `zh-Hant`, `pt-BR`, `fr-CA`) are not required for glossary creation and may not be accepted; use the base code instead:

Copilot uses AI. Check for mistakes.

| Use this | Not this |
|---|---|
| `zh` | `zh-Hant`, `zh-Hans` |
| `pt` | `pt-BR`, `pt-PT` |
| `fr` | `fr-CA`, `fr-CH` |
| `de` | `de-CH` |
| `it` | `it-CH` |
| `es` | `es-ES`, `es-419` |

### Application — variants are supported

Once a glossary is created with a root code, it can be applied when translating into any variant of that language. The `target_lang` in the `/translate` call can be a variant, and the root glossary will be picked up automatically.
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“the root glossary will be picked up automatically” is a bit misleading: the glossary is only applied if the request includes the glossary/glossary_id, but the dictionary selection will resolve from the root glossary to the target variant automatically. Suggest clarifying that you still need to pass the glossary ID.

Suggested change
Once a glossary is created with a root code, it can be applied when translating into any variant of that language. The `target_lang` in the `/translate` call can be a variant, and the root glossary will be picked up automatically.
Once a glossary is created with a root code, it can be applied when translating into any variant of that language. The `target_lang` in the `/translate` call can be a variant, but you must still pass the glossary ID in the request. When you do, DeepL will automatically resolve from the root glossary to the appropriate dictionary for the target variant.

Copilot uses AI. Check for mistakes.

**Example — creating a `zh` glossary, then applying it when translating into `zh-Hant`:**

```python
import deepl

translator = deepl.Translator("YOUR_AUTH_KEY")

# Step 1: Create glossary using root code
glossary = translator.create_glossary(
"My Chinese Glossary",
source_lang="EN",
target_lang="ZH", # root code — not ZH-HANS or ZH-HANT
entries={"product": "产品", "customer": "客户"}
)

# Step 2: Pass the glossary ID when translating into a variant
result = translator.translate_text(
"We value every customer.",
source_lang="EN",
target_lang="ZH-HANT", # variant target — glossary still applies
glossary=glossary.glossary_id # pass the ID of the root-code glossary
)

print(result.text)
# 我們重視每一位客戶。
```

The same pattern works for Portuguese:

```python
# Glossary created with root code "PT"
glossary = translator.create_glossary(
"Portuguese Glossary",
source_lang="EN",
target_lang="PT", # root code
entries={"invoice": "fatura"}
)

# Pass the same glossary ID to either variant
result_br = translator.translate_text(
"Please send the invoice.",
source_lang="EN",
target_lang="PT-BR",
glossary=glossary.glossary_id
)

result_pt = translator.translate_text(
"Please send the invoice.",
source_lang="EN",
target_lang="PT-PT",
glossary=glossary.glossary_id
)

print(result_br.text) # Favor enviar a fatura.
print(result_pt.text) # Por favor, envie a fatura.
```

---

## Style rules

### Creation — root codes only

Style rules cannot be created for variant codes — attempting to create one for `fr-CA`, `es-419`, or `de-CH` via the API returns a "language not supported" error. Use the root code only.

Style rules for creation are currently supported for: `en`, `de`, `fr`, `es`, `it`, `ja`, `ko`, `zh`. With the Q2 release, Tier 2/3 languages (`vi`, `nl`, `ar`, `pt`, etc.) are being added for root-code style rule creation.
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sentence about “With the Q2 release, Tier 2/3 languages … are being added” isn’t referenced elsewhere in the docs/changelog and is time-relative (will become stale quickly). Consider removing the release-timing claim or linking to an explicit changelog/announcement and using a specific date/version if available.

Suggested change
Style rules for creation are currently supported for: `en`, `de`, `fr`, `es`, `it`, `ja`, `ko`, `zh`. With the Q2 release, Tier 2/3 languages (`vi`, `nl`, `ar`, `pt`, etc.) are being added for root-code style rule creation.
Style rules for creation are currently supported for: `en`, `de`, `fr`, `es`, `it`, `ja`, `ko`, `zh`.

Copilot uses AI. Check for mistakes.

### Application — variants are supported

Once created under a root code, a style rule's `style_id` can be passed in a `/translate` call targeting any variant of that language:

```python
# Style rule created for "FR" root code
# Can be applied when translating into FR-CA, FR-CH, or FR-FR

result = translator.translate_text(
"Please review the attached document.",
source_lang="EN",
target_lang="FR-CA", # variant target
extra_params={"style_id": "your-style-rule-id"} # root FR style rule applies
)
```

<Note>
Variant codes are not selectable in the style rule creation UI — only root codes appear. You'll need to handle the mapping on your end, i.e. knowing which root style rule ID to pass for a given variant target.
</Note>

<Warning>
Some CAT tools may have their own logic that blocks passing a root language glossary or style rule when the target is a variant. This is a client-side implementation issue, not an API limitation — the DeepL API itself supports this pattern.
</Warning>

---

## Relevant links

**Supported languages for creation (root codes):**
- Glossaries: [Supported languages](/docs/getting-started/supported-languages) — filter by "Glossary"
- Style rules: [Style rules API reference](/api-reference/style-rules)

**Supported for application (translate call):**
- [/translate request reference](/api-reference/translate/request-translation) — see `glossary_id` and `style_id` parameters