@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
18 lines (16 loc) • 1.28 kB
JavaScript
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
let __intlayer_types = require("@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 === __intlayer_types.NodeType.Translation) currentValue = currentValue?.[__intlayer_types.NodeType.Translation]?.[fallbackLocale];
if (keyObj.type === __intlayer_types.NodeType.Object || keyObj.type === __intlayer_types.NodeType.Array) currentValue = currentValue?.[keyObj.key];
if (keyObj.type === __intlayer_types.NodeType.Translation || keyObj.type === __intlayer_types.NodeType.Condition || keyObj.type === __intlayer_types.NodeType.Enumeration) currentValue = currentValue?.[keyObj.type]?.[keyObj.key];
if (keyObj.type === __intlayer_types.NodeType.Markdown || keyObj.type === __intlayer_types.NodeType.Insertion || keyObj.type === __intlayer_types.NodeType.File) currentValue = currentValue?.[keyObj.type];
}
return currentValue;
};
//#endregion
exports.getContentNodeByKeyPath = getContentNodeByKeyPath;
//# sourceMappingURL=getContentNodeByKeyPath.cjs.map