translate.nth()

The translate.nth() function translates element at $n index in $list with a global dictionary and/or $dictionary.

Global dictionary is in use on $dictionary-global set to true, or by setting $global argument to true.

// Sass.
@use 'sass:list';

// Functions.
@use '../translator.dictionary.function';
@use 'translate.string.function';

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

// The `translator.translate-nth()` or `translate.nth()` function.
@function nth($list, $n, $key: null, $dictionary: (), $global: null) {
  @if type-of($list) == list {
    $dictionary: translator.dictionary($key, $dictionary, $global);
    $nth: list.nth($list, $n);
    $translation: dictionary.translation($nth, $dictionary);
    @if type-of($nth) == list {
      @if $translation {
        @return list.set-nth($list, $n, $translation);
      } @else {
        @for $i from 1 through list.length($nth) {
          $translation: dictionary.translation(list.nth($nth, $i), $dictionary);
          @if $translation {
            $nth: list.set-nth($nth, $i, $translation);
          }
        }
        @return list.set-nth($list, $n, $nth);
      }
    }
    @return if($translation, list.set-nth($list, $n, $translation), $list);
  }
  @return $list;
}
https://github.com/angular-package/sass/blob/main/translator/translate/_translate.nth.function.scss

Parameters

$list

A list in which element at given $n index is translated.

$n

An index of $list to translate.

$key: null

A key of the dictionary retrieved from a global and/or given $dictionary.

$dictionary: ()

The dictionary that is used to translate $n element in $list.

$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

Last updated

Was this helpful?