@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
17 lines (15 loc) • 1 kB
JavaScript
import { NodeType } from "@intlayer/types";
//#region src/dictionaryManipulator/getContentNodeByKeyPath.ts
const getContentNodeByKeyPath = (dictionaryContent, keyPath, fallbackLocale) => {
let currentValue = structuredClone(dictionaryContent);
for (const keyObj of keyPath) {
if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) currentValue = currentValue?.[keyObj.key];
if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Condition || keyObj.type === NodeType.Enumeration) currentValue = currentValue?.[keyObj.type]?.[keyObj.key];
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) currentValue = currentValue?.[keyObj.type];
}
return currentValue;
};
//#endregion
export { getContentNodeByKeyPath };
//# sourceMappingURL=getContentNodeByKeyPath.mjs.map