@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
33 lines (31 loc) • 1.34 kB
JavaScript
const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
const require_interpreter_getContent_plugins = require('../interpreter/getContent/plugins.cjs');
//#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 = [require_interpreter_getContent_plugins.translationPlugin(locale, fallback), ...nodeProps.plugins ?? []];
return require_interpreter_getContent_deepTransform.deepTransformNode(node, {
...nodeProps,
plugins
});
};
const getPerLocaleDictionary = (dictionary, locale, fallback) => ({
...dictionary,
locale,
content: getLocalizedContent(dictionary.content, locale, {
dictionaryKey: dictionary.key,
keyPath: [],
plugins: []
}, fallback)
});
//#endregion
exports.getLocalizedContent = getLocalizedContent;
exports.getPerLocaleDictionary = getPerLocaleDictionary;
//# sourceMappingURL=getLocalizedContent.cjs.map