---
title: "transloco"
description: "The preset for Transloco. It reads the transloco pipe, directive and structural directive with read scopes, and the translate function."
canonical_url: "https://x18n.dev/presets/transloco"
---
# transloco

> The preset for Transloco. It reads the transloco pipe, directive and structural directive with read scopes, and the translate function.

The `transloco` preset supports [Transloco](https://jsverse.gitbook.io/transloco) in Angular projects.

## Detection

The preset applies when the project depends on `@jsverse/transloco` or `@ngneat/transloco`.

```ts [x18n.config.ts]
import { defineConfig } from '@x18n/core'

export default defineConfig({
  presets: ['transloco'],
})
```

## Locale files

If your config has no `resources`, the preset uses `src/assets/i18n/{locale}.json` and `src/assets/i18n/{namespaces}/{locale}.json`.

A scope folder is a key prefix in camelCase, as Transloco names it: the preset sets `namespace.fromPath` to `camel`, so `src/assets/i18n/todos-page/en.json` holds the keys `todosPage.*`. For a scope with an alias, add a resource with a fixed namespace: `{ pattern: 'src/assets/i18n/todos-page/{locale}.json', namespace: 'todos' }`.

## Supported syntax

In HTML templates, the preset reads the `transloco` pipe, the `transloco` attribute directive, and `t(...)` calls. The `prefix` option of the structural directive `*transloco`, or `read` as it was called before, is a key prefix, and so is `prefix` on `<ng-template transloco>`. It applies to the `t(...)` calls inside that element, and the nearest one wins:

<!-- eslint-skip -->

```html [src/app/a.html]
<h1>{{ 'title' | transloco }}</h1>
<p transloco="intro"></p>
<div *transloco="let t; prefix: 'admin'">
  <p>{{ t('users') }}</p>
</div>
```

These usages are `title`, `intro` and `admin.users`.

In TS and JS files, these names count as translate calls: `translate`, `translocoService.translate`, `transloco.translate`, `translocoService.selectTranslate` and `transloco.selectTranslate`.

## Placeholders

Double braces: `{{name}}`.

## Hard strings in templates

The preset adds the `html` scanner, so extraction finds hard-coded text and text attributes (`title`, `placeholder`, `aria-label`, ...) in `.html` templates. It skips:

- interpolations (`{{ user.name }}`) and ICU messages (`{count, plural, ...}`),
- bindings, events, references and structural directives: `[alt]`, `(click)`, `#ref`, `*ngIf`, `let-item`,
- the parameters of control-flow blocks such as `@if (...)`, `@for (...)`, `@switch`, `@case` and `@defer`, and `@let` declarations; the content of the blocks is scanned,
- elements whose content is translated already: `transloco` and `[transloco]`, Angular's `i18n` (and the attributes named in `i18n-*`), and `translate="no"`,
- `<script>` and `<style>`.

`<!-- x18n-ignore -->`, `<!-- x18n-ignore-start -->` ... `<!-- x18n-ignore-end -->` and `<!-- x18n-ignore-file -->` comments skip text as in other files.

## Extraction templates

| Kinds                      | Template                          | Imports                                          |
| -------------------------- | --------------------------------- | ------------------------------------------------ |
| `html-text`                | `{{ '{key}' \| transloco }}`      |                                                  |
| `html-attribute`           | `[{attr}]="'{key}' \| transloco"` |                                                  |
| `js-string`, `js-template` | `translate('{key}'{args})`        | `import { translate } from '@jsverse/transloco'` |


## Sitemap

See the full [sitemap](https://x18n.dev/sitemap.md) for all pages.
