translate.map()
The translate.map()
function translates flatten $map
with a global dictionary and/or $dictionary
.
// 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;
}
https://github.com/angular-package/sass/blob/main/translator/translate/_translate.map.function.scss
Parameters
$map
$map
A list in which element at given $n
index is translated.
$n
$n
An index of $list
to translate.
$key: null
$key: null
A key of the dictionary retrieved from a global and/or given $dictionary
.
$dictionary: ()
$dictionary: ()
The dictionary that is used to translate $n
element in $list
.
$global: null
$global: null
A bool
value indicates whether to use a global dictionary. Default, null
, then $dictionary-global
is checked.
Return
The return value is the list with a translated $n
element of $list
.
Examples
// 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)
Last updated
Was this helpful?