UNPKG

@carbon/ibm-products

Version:
29 lines (27 loc) 1.24 kB
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { ConditionBuilderContext } from "../ConditionBuilderContext/ConditionBuilderProvider.js"; import { translationsObject } from "../ConditionBuilderContext/translationObject.js"; import { useContext } from "react"; //#region src/components/ConditionBuilder/utils/useTranslations.js /** * Copyright IBM Corp. 2021, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const useTranslations = (translationKeys, alterTranslationKeyMap) => { const { translateWithId } = useContext(ConditionBuilderContext); return translationKeys.map((translationKey) => { if (alterTranslationKeyMap?.[translationKey]) translationKey = alterTranslationKeyMap[translationKey]; if (translateWithId?.(translationKey) && translateWithId?.(translationKey) !== translationKey) return translateWithId(translationKey); else if (translationsObject[translationKey]) return translationsObject[translationKey]; else return translationKey; }); }; //#endregion export { useTranslations };