// Sass.
@use 'sass:list';
@use 'sass:meta';
// Variables.
@use 'dictionary.variables' as variables;
// Modules.
@use '../../map';
// Functions.
@use 'dictionary.is-global.function';
// The `translator.dictionary-pick()` or `dictionary.pick()` function.
@function pick($key, $dictionary: (), $global: null) {
$dictionary: if(
meta.type-of($dictionary) == list and list.length($dictionary) > 0,
map.retrieve(pick, $dictionary...),
$dictionary
);
@if dictionary.is-global($global) {
$dictionary: if(
$key,
map.deep-merge(
map.pick(variables.$dictionary, $key...),
if(meta.type-of($dictionary) == map, map.pick($dictionary, $key...), ())
),
map.deep-merge(variables.$dictionary, $dictionary)
);
} @else if $key {
$dictionary: map.pick($dictionary, $key...);
}
@return $dictionary;
}
The return value is a dictionary consisting of the global dictionary(if in use) and given $dictionary
from the associated $key
.
// Use.
@use '@angular-package/sass/translator';
// Examples.
$-dictionary: (
general: (word: słowo, (wrapper, wrap): owijka, technology: (action: akcja)),
class: (prefix: spectre-prefix, suffix: spectre-suffix, calendars: (calendar: cal), labels: (label: lab)),
prefix: spectre,
suffix: end,
separator: '--',
var: (prefix: spectre, suffix: end)
);
// Examples.
// Pick the global dictionary.
@debug translator.pick(null); // (word: translation)
// Deactivate picking from the global dictionary.
@debug translator.pick(null, $global: false); // ()
// Pick dictionary from the `$-dictionary` variable.
@debug translator.pick(null, $-dictionary); // (word: translation, general: (word: słowo, (wrapper, wrap): owijka, technology: (action: akcja)), class: (prefix: spectre-prefix, suffix: spectre-suffix, calendars: (calendar: cal), labels: (label: lab)), prefix: spectre, suffix: end, separator: "--", var: (prefix: spectre, suffix: end))
// Pick dictionary from the `$-dictionary` variable by using string key.
@debug translator.pick(general, $-dictionary); // (general: (word: słowo, (wrapper, wrap): owijka, technology: (action: akcja)))
// Pick dictionary from the `$-dictionary` variable by using deep key.
@debug translator.pick(((class, calendars),), $-dictionary class); // (calendars: (calendar: cal))
@debug translator.pick([(class, calendars)], $-dictionary); // (calendars: (calendar: cal))
// Pick dictionary from the `$-dictionary` with not existing key.
@debug translator.pick(no-field, $-dictionary); // (no-field: null)
// Pick dictionary from the `$-dictionary` variable and `$global` false.
@debug translator.pick(null, $-dictionary, $global: false); // (general: (word: słowo, (wrapper, wrap): owijka, technology: (action: akcja)), class: (prefix: spectre-prefix, suffix: spectre-suffix, calendars: (calendar: cal), labels: (label: lab)), prefix: spectre, suffix: end, separator: "--", var: (prefix: spectre, suffix: end))
@debug translator.pick(general, $-dictionary, $global: false); // (general: (word: słowo, (wrapper, wrap): owijka, technology: (action: akcja)))
@debug translator.pick(no-field, $-dictionary, $global: false); // (no-field: null)
// Pick dictionary by using multiple keys and deep key.
@debug translator.pick((general, var, (class, calendars)), $-dictionary); // (general: (word: słowo, (wrapper, wrap): owijka, technology: (action: akcja)), var: (prefix: spectre, suffix: end), calendars: (calendar: cal))
// Custom dictionary.
@debug translator.pick(class, $-dictionary); // (class: (prefix: spectre-prefix, suffix: spectre-suffix, calendars: (calendar: cal), labels: (label: lab)))
@debug translator.pick((prefix,), $-dictionary); // (prefix: spectre)
// Custom dictionary + pick key
@debug translator.pick(null, $-dictionary ((class, calendars),), $global: false); // (calendars: (calendar: cal))