UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

32 lines (30 loc) 1.15 kB
import { deepTransformNode } from "../interpreter/getContent/deepTransform.mjs"; import { translationPlugin } from "../interpreter/getContent/plugins.mjs"; //#region src/deepTransformPlugins/getLocalizedContent.ts /** * Transforms a node in a single pass, applying each plugin as needed. * In comparison to `getContent`, this function will only apply the translation plugin. * It will not transform enumerations, insertions, or other content types. * * @param node The node to transform. * @param locale The locale to use if your transformers need it (e.g. for translations). */ const getLocalizedContent = (node, locale, nodeProps, fallback) => { const plugins = [translationPlugin(locale, fallback), ...nodeProps.plugins ?? []]; return deepTransformNode(node, { ...nodeProps, plugins }); }; const getPerLocaleDictionary = (dictionary, locale, fallback) => ({ ...dictionary, locale, content: getLocalizedContent(dictionary.content, locale, { dictionaryKey: dictionary.key, keyPath: [], plugins: [] }, fallback) }); //#endregion export { getLocalizedContent, getPerLocaleDictionary }; //# sourceMappingURL=getLocalizedContent.mjs.map