# Translations

Also known as `contents`, translations is a convenient way how to make applications multi-lingual. Upon opening an application, the full contents object is loaded and used for all textual content visible to the customer.

## Available variables

The following variables are available in all content strings (starting from FW v5.13.0):

* `input` - all collected (and defaulted, prefilled) customer input
* `flags` - custom booleans set by the framework
* `quote` - all data returned by the `quote` request
* `policy` - all data returned by the `policy` request
* `claim` - all data returned by the `claim` request (FNOL mode)
* `lead` - lead data including `first_name`, `last_name`, `email`, and `quote`
* `asset.{ref}` - all the asset URLs available on the item level
* `document.{request}.{ref}.{"url"|"name"}` - all the dynamic documents generated by request
* `route` - name of the currently active screen and route params
* `dataset.{field_name}.{property}` - loaded dataset item data (see [dataset section](#dataset-variables) below)
* `query_string` - all data from query string
* `active_policy` - active policy data (used in FNOL mode)
* `renewal` - policy renewal data
* `form` - form state (e.g., `form.has_errors`)
* `context` - repeater context (e.g., `context.repeater_index`, `context.repeater_index_human`)

### Hardcoded Fields

Some fields are "hardcoded" and exist at the root level of `input`, not under `input.data`:

* `first_name` - Customer first name
* `last_name` - Customer last name
* `email` - Customer email

Reference these WITHOUT the `data.` prefix:

```js
// Correct
"{input.first_name}"
"{input.last_name}"
"{input.email}"

// Wrong - these are NOT under data
"{input.data.first_name}"
```

All other customer-created fields should use the `data.` prefix:

```js
"{input.data.custom_field}"
```

### Dataset Variables

When a field has the `in_dataset` validation rule and a value is selected, the dataset item is loaded and accessible via `dataset.{field_name}`.

**Structure:**

```ts
{
  [field_name: string]: {
    id: string;           // Dataset item ID (dai_...)
    dataset_id: string;   // Dataset ID (dat_...)
    [key: string]: any;   // Custom fields from the dataset
  };
}
```

**Usage:**

```
dataset.{field_name}.{property}
```

Where `{field_name}` is the form field containing the dataset item ID, and `{property}` is any field from the dataset item.

**Examples:**

```js
// If field "data.company" has a dataset item with name, code, address fields:
"Company: {dataset.data.company.name}"
"Code: {dataset.data.company.code}"
"Address: {dataset.data.company.address}"

// Nested properties work too:
"City: {dataset.data.company.address.city}"
```

### Usage Examples

```js
"My name is {input.first_name}"
"I'm born in {input.data.dob}"
"Selected company: {dataset.data.company.name}"
"Company code: {dataset.data.company.code}"
"Offer document: [{document.lead.offer.name}]({document.lead.offer.url})"
"The price is: {quote.gross_payment_amount, asCurrency}"
```

## Available transformers

Not always data is collected from the customers in exactly the same way as displayed back to the customer. For example, when monetary values are collected, they are converted to values in cents (1 Eur = `100`). When displaying this value back to the customer, the value needs to be converted back to the original (`100` = 1 Eur). This and more is achieved with transformers.

### asCurrency

When monetary values are collected they are stored as value in cents (1 Eur = `100`). In order to display these values in a human-readable way, the `asCurrency` filter needs to be used. By default the [global price format](https://docs.kasko.io/kasko-frontend-documentation/core-concepts/configuration/configuring-price-format) is used.

```js
"Content string: {quote.gross_payment_amount, asCurrency}"
// -> "Content string: EUR 1 234,56"
```

The price format can also be overwritten locally by providing it as arguments:

```js
"{quote.gross_payment_amount, asCurrency} | {quote.gross_payment_amount, asCurrency, (amount, 1.2-2, '.', '`')(currencySymbol)}"
// -> "EUR 1 234,56 | 1`234.56€"
```

For a more detailed explanation see the [price format guide](https://docs.kasko.io/kasko-frontend-documentation/core-concepts/configuration/configuring-price-format).

### date

Sometimes the date value collected from the customer needs to be transformed before displaying via content strings. This can be achieved with `date` transformer.

By default is uses the globally defined date format (or if it's not set, then the default one in the KASKO framework).

```js
"Content string: {input.data.dob, date}"
// -> "Content string: 27/12/1994"
```

Custom format can also be configured by passing in an additional argument.

```js
"Content string: {input.data.dob, date, YYYY-MM-DD}"
// -> "Content string: 1994-12-27"
```

For full information about the available formats, see the [date format guide](https://docs.kasko.io/kasko-frontend-documentation/core-concepts/configuration/configuring-date-format).

### asNumber

When you need to format numeric values with specific decimal places and separators, use the `asNumber` transformer.

```js
"Content string: {input.data.count, asNumber}"
// -> "Content string: 1,234"
```

Custom format can also be configured by providing it as arguments (similar to `asCurrency`):

```js
"{input.data.value, asNumber, (1.2-2, '.', ' ')}"
// -> "1 234.56"
```

The format follows the pattern: `(minIntegerDigits.minFractionDigits-maxFractionDigits, 'decimalSeparator', 'thousandsSeparator')`
