Home > widget-integration > FilterTranslationService > getNestedTranslation

FilterTranslationService.getNestedTranslation() method

Traverses a nested object structure to retrieve a translation value.

Splits the key by dots and traverses the translations object step by step. Returns the default label if any part of the path doesn't exist or if the final value is not a string.

Signature:

getNestedTranslation(key: string, translations: Record<string, any>, defaultLabel: string): string;

Parameters

Parameter

Type

Description

key

string

Dot-separated key path (e.g., 'filter.options.color')

translations

Record<string, any>

The translations object to search within

defaultLabel

string

Fallback value if key path doesn't resolve to a string

Returns:

string

The translated string if found, otherwise the default label

Remarks

This is a utility method used by translateByKey. It safely handles missing keys and invalid object structures by returning the default label.

Example

const result = this.getNestedTranslation(
  'filter.color',
  { filter: { color: 'Couleur' } },
  'Color'
);
// Returns: "Couleur"