# Dynamic translation

- Entry point: `@koobiq/components/dynamic-translation`
- NgModule: `KbqDynamicTranslationModule`
- API: https://koobiq.io/api/dynamic-translation.md
- Page: https://koobiq.io/en/components/dynamic-translation/overview

## Overview

`KbqDynamicTranslation` — component for embedding custom components into translatable strings.

The string arrives already translated: translating it is the application's job. The strings the library
renders itself are a separate matter, covered by the [Localization](https://koobiq.io/en/main/localization.md) guide.

[**Example: Dynamic translation overview example** (`dynamic-translation-overview`)](https://koobiq.io/examples/dynamic-translation-overview.md)

### Adding a component

Components are embedded into strings using special syntax: `[[<slotName>:<context>]]`, where `slotName` is the key of the registered component, and `context` is the data passed to the component.

```html
<!-- Slot with string passing -->
<kbq-dynamic-translation text="[[myLinkSlot:Open link]]">
    <a *kbqDynamicTranslationSlot="'myLinkSlot'; let context">{{ context }}</a>
</kbq-dynamic-translation>

<!-- Slot with list passing -->
<kbq-dynamic-translation text="[[myListSlot:(first,second,third)]]">
    <ul *kbqDynamicTranslationSlot="'myListSlot'; let context">
        @for (item of context; track $index) {
            <li>{{ item }}</li>
        }
    </ul>
</kbq-dynamic-translation>
```

### Key features

- Embedding components ([links](https://koobiq.io/en/components/link.md), [buttons](https://koobiq.io/en/components/button.md), [dropdowns](https://koobiq.io/en/components/dropdown.md), etc.) into localized strings.
- Separation of interface logic from localization texts.
- Support for multiple slots in a single string.

### When to use

- When you need to dynamically change the composition and context of embedded components depending on localization.
- If you need to add interactive elements ([links](https://koobiq.io/en/components/link.md), [buttons](https://koobiq.io/en/components/button.md), [dropdowns](https://koobiq.io/en/components/dropdown.md), etc.) directly into translatable text.
- For highlighting parts of text with special styles.

## Examples

### Dynamic component creation

[**Example: Dynamic-translation with dynamic component creation** (`dynamic-translation-with-dynamic-component-creation`)](https://koobiq.io/examples/dynamic-translation-with-dynamic-component-creation.md)
