# translate.map()

The `translate.map()` function translates flatten [`$map`](#usdmap) with a global dictionary and/or [`$dictionary`](#usddictionary).

{% hint style="info" %}
Global dictionary is in use on [`$dictionary-global`](https://docs.angular-package.dev/sass/dictionary/dictionary.variables#usddictionary-global-true) set to `true`, or by setting [`$global`](#usdglobal-null) argument to `true`.
{% endhint %}

{% code lineNumbers="true" %}

```scss
// Sass.
@use 'sass:map';
@use 'sass:meta';

// Modules.
@use '../dictionary';

// Functions.
@use 'translate.list.function' as *;
@use 'translate.string.function' as *;

// The `translator.translate-map()` or `translate.map()` function.
@function map($map, $key: null, $dictionary: (), $global: null) {
  @if type-of($map) == map {
    @each $map-key, $value in $map {
      $map: if(
        meta.type-of($value) == string,
        map.set($map, $map-key, string($value, $key, $dictionary, $global)),
        if(
          meta.type-of($value) == list,
          map.set($map, $map-key, list($value, $key, $dictionary, $global)),
          $map
        )
      );
    }
  }
  @return $map;
}
```

{% endcode %}

{% embed url="<https://github.com/angular-package/sass/blob/main/translator/translate/_translate.map.function.scss>" %}

### Parameters

#### `$map`

A list in which element at given [`$n`](#usdn) index is translated.

#### `$n`

An index of [`$list`](#usdlist) to translate.

#### `$key: null`

A key of the dictionary retrieved from a global and/or given [`$dictionary`](#usddictionary).

#### `$dictionary: ()`

The dictionary that is used to translate [`$n`](#usdn) element in [`$list`](#usdlist).

#### `$global: null`

A `bool` value indicates whether to use a global dictionary. Default, `null`, then [`$dictionary-global`](https://docs.angular-package.dev/sass/translator-v0.1.0/dictionary/dictionary.variables) is checked.

### Return

The return value is the list with a translated [`$n`](#usdn) element of [`$list`](#usdlist).

## Examples

```scss
// Use.
@use '@angular-package/sass/translator';

// Examples.
$-dictionary-example: dictionary.merge(null, (
  (extra large, 'extra large', extra-large): xl,
  (extra small, 'extra small', extra-small): xs,
  border: b,
  class: (prefix: class-prefix, separator: class-separator, suffix: class-suffix, calendars: (calendar: cal), labels: (label: lab)),
  color: c,
  general: (word: słowo, (wrapper, wrap): owijka, (technology, technologia): tech, color: c),
  large: lg,
  medium: md,
  outline: o,
  prefix: spectre,
  small: sm,
  suffix: end,
));

// String.
@debug translator.translate-map((word: wrapper), general, $-dictionary-example); // (word: owijka)
@debug translator.translate-map((word: wrapper), null, $-dictionary-example general); // (word: owijka)
@debug translator.translate-map((limit: first), null, ((first, start): 1, (last, length, end): 50)); // (limit: 1)

// List.
@debug translator.translate-map((word: basic (wrapper, wrap) color), null, $-dictionary-example general); // (word: basic (owijka, owijka) c)
@debug translator.translate-map((word: basic (wrapper, wrap) color), general, $-dictionary-example); // (word: basic (owijka, owijka) c)

// Different dictionary.
@debug translator.translate-map((calendar: calendar), $dictionary: ($-dictionary-example, (class, calendars))); // (calendar: cal)
@debug translator.translate-map((calendar: calendar), (class, calendars), $-dictionary-example); // (calendar: cal)

```
