@intlayer/core 8.1.2 → 8.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +1 -212
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +1 -94
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs +1 -45
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs +1 -33
- package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMaskContent.cjs +1 -27
- package/dist/cjs/deepTransformPlugins/getMaskContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +1 -82
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs +1 -87
- package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs +1 -60
- package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs +1 -122
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/index.cjs +1 -32
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs +1 -106
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +1 -64
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -18
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +1 -55
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +1 -26
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -23
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs +1 -36
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/index.cjs +1 -27
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs +1 -69
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs +1 -30
- package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs +1 -48
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +1 -31
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +1 -39
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +1 -38
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
- package/dist/cjs/formatters/compact.cjs +1 -25
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs +1 -29
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs +1 -60
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/index.cjs +1 -18
- package/dist/cjs/formatters/list.cjs +1 -30
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs +1 -18
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs +1 -25
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs +1 -33
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs +1 -23
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/getStorageAttributes.cjs +1 -134
- package/dist/cjs/getStorageAttributes.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -300
- package/dist/cjs/interpreter/getCondition.cjs +1 -27
- package/dist/cjs/interpreter/getCondition.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs +1 -41
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs +1 -34
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/index.cjs +1 -14
- package/dist/cjs/interpreter/getContent/plugins.cjs +1 -161
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionary.cjs +1 -24
- package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getEnumeration.cjs +1 -72
- package/dist/cjs/interpreter/getEnumeration.cjs.map +1 -1
- package/dist/cjs/interpreter/getGender.cjs +1 -38
- package/dist/cjs/interpreter/getGender.cjs.map +1 -1
- package/dist/cjs/interpreter/getHTML.cjs +1 -121
- package/dist/cjs/interpreter/getHTML.cjs.map +1 -1
- package/dist/cjs/interpreter/getInsertion.cjs +1 -22
- package/dist/cjs/interpreter/getInsertion.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs +1 -40
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getNesting.cjs +1 -36
- package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs +1 -112
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/interpreter/index.cjs +1 -31
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs +1 -55
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs +1 -143
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getHTMLTextDir.cjs +1 -64
- package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs +1 -27
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs +1 -45
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleLang.cjs +1 -20
- package/dist/cjs/localization/getLocaleLang.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleName.cjs +1 -10
- package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +1 -82
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs +1 -63
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs +1 -55
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs +1 -63
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/localization/index.cjs +1 -39
- package/dist/cjs/localization/localeDetector.cjs +1 -133
- package/dist/cjs/localization/localeDetector.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs +1 -119
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/localization/localeResolver.cjs +1 -28
- package/dist/cjs/localization/localeResolver.cjs.map +1 -1
- package/dist/cjs/localization/rewriteUtils.cjs +1 -110
- package/dist/cjs/localization/rewriteUtils.cjs.map +1 -1
- package/dist/cjs/localization/validatePrefix.cjs +1 -54
- package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +10 -810
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/constants.cjs +1 -328
- package/dist/cjs/markdown/constants.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +1 -120
- package/dist/cjs/markdown/parser.cjs +1 -66
- package/dist/cjs/markdown/parser.cjs.map +1 -1
- package/dist/cjs/markdown/renderer.cjs +1 -61
- package/dist/cjs/markdown/renderer.cjs.map +1 -1
- package/dist/cjs/markdown/utils.cjs +6 -391
- package/dist/cjs/markdown/utils.cjs.map +1 -1
- package/dist/cjs/messageFormat/ICU.cjs +1 -319
- package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
- package/dist/cjs/messageFormat/i18next.cjs +1 -330
- package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
- package/dist/cjs/messageFormat/index.cjs +1 -11
- package/dist/cjs/messageFormat/verify-icu-format.cjs +2 -64
- package/dist/cjs/messageFormat/verify-icu-format.cjs.map +1 -1
- package/dist/cjs/messageFormat/vue-i18n.cjs +1 -166
- package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/condition.cjs +1 -26
- package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/index.cjs +1 -4
- package/dist/cjs/transpiler/enumeration/enumeration.cjs +1 -28
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/index.cjs +1 -4
- package/dist/cjs/transpiler/file/file.cjs +1 -52
- package/dist/cjs/transpiler/file/file.cjs.map +1 -1
- package/dist/cjs/transpiler/file/fileBrowser.cjs +1 -25
- package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
- package/dist/cjs/transpiler/file/index.cjs +1 -5
- package/dist/cjs/transpiler/gender/gender.cjs +1 -26
- package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
- package/dist/cjs/transpiler/gender/index.cjs +1 -4
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs +1 -44
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
- package/dist/cjs/transpiler/html/html.cjs +1 -37
- package/dist/cjs/transpiler/html/html.cjs.map +1 -1
- package/dist/cjs/transpiler/html/htmlTags.cjs +1 -116
- package/dist/cjs/transpiler/html/htmlTags.cjs.map +1 -1
- package/dist/cjs/transpiler/html/index.cjs +1 -6
- package/dist/cjs/transpiler/index.cjs +1 -24
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs +1 -11
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/index.cjs +1 -6
- package/dist/cjs/transpiler/insertion/insertion.cjs +1 -36
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs +2 -23
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/index.cjs +1 -6
- package/dist/cjs/transpiler/markdown/markdown.cjs +1 -54
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/nesting/index.cjs +1 -4
- package/dist/cjs/transpiler/nesting/nesting.cjs +1 -27
- package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/index.cjs +1 -4
- package/dist/cjs/transpiler/translation/translation.cjs +1 -29
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/utils/checkIsURLAbsolute.cjs +1 -7
- package/dist/cjs/utils/checkIsURLAbsolute.cjs.map +1 -1
- package/dist/cjs/utils/getCookie.cjs +1 -32
- package/dist/cjs/utils/getCookie.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +1 -0
- package/dist/cjs/utils/intl.cjs +1 -91
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/isSameKeyPath.cjs +1 -7
- package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -1
- package/dist/cjs/utils/isValidReactElement.cjs +1 -14
- package/dist/cjs/utils/isValidReactElement.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs +1 -140
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/cjs/utils/parseYaml.cjs +16 -322
- package/dist/cjs/utils/parseYaml.cjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs +1 -207
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs +1 -89
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs +1 -42
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs +1 -31
- package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMaskContent.mjs +1 -25
- package/dist/esm/deepTransformPlugins/getMaskContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs +1 -77
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs +1 -86
- package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs +1 -59
- package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getSplittedContent.mjs +1 -119
- package/dist/esm/deepTransformPlugins/getSplittedContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/index.mjs +1 -12
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs +1 -104
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +1 -62
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -16
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +1 -53
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +1 -24
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -21
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeType.mjs +1 -34
- package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/index.mjs +1 -14
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs +1 -66
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs +1 -28
- package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs +1 -45
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +1 -29
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +1 -37
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +1 -36
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
- package/dist/esm/formatters/compact.mjs +1 -22
- package/dist/esm/formatters/compact.mjs.map +1 -1
- package/dist/esm/formatters/currency.mjs +1 -26
- package/dist/esm/formatters/currency.mjs.map +1 -1
- package/dist/esm/formatters/date.mjs +1 -57
- package/dist/esm/formatters/date.mjs.map +1 -1
- package/dist/esm/formatters/index.mjs +1 -10
- package/dist/esm/formatters/list.mjs +1 -27
- package/dist/esm/formatters/list.mjs.map +1 -1
- package/dist/esm/formatters/number.mjs +1 -15
- package/dist/esm/formatters/number.mjs.map +1 -1
- package/dist/esm/formatters/percentage.mjs +1 -22
- package/dist/esm/formatters/percentage.mjs.map +1 -1
- package/dist/esm/formatters/relativeTime.mjs +1 -30
- package/dist/esm/formatters/relativeTime.mjs.map +1 -1
- package/dist/esm/formatters/units.mjs +1 -20
- package/dist/esm/formatters/units.mjs.map +1 -1
- package/dist/esm/getStorageAttributes.mjs +1 -132
- package/dist/esm/getStorageAttributes.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -82
- package/dist/esm/interpreter/getCondition.mjs +1 -25
- package/dist/esm/interpreter/getCondition.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/deepTransform.mjs +1 -39
- package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs +1 -31
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/index.mjs +1 -5
- package/dist/esm/interpreter/getContent/plugins.mjs +1 -153
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionary.mjs +1 -23
- package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getEnumeration.mjs +1 -69
- package/dist/esm/interpreter/getEnumeration.mjs.map +1 -1
- package/dist/esm/interpreter/getGender.mjs +1 -36
- package/dist/esm/interpreter/getGender.mjs.map +1 -1
- package/dist/esm/interpreter/getHTML.mjs +1 -119
- package/dist/esm/interpreter/getHTML.mjs.map +1 -1
- package/dist/esm/interpreter/getInsertion.mjs +1 -20
- package/dist/esm/interpreter/getInsertion.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.mjs +1 -36
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getNesting.mjs +1 -35
- package/dist/esm/interpreter/getNesting.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs +1 -110
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/interpreter/index.mjs +1 -13
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs +1 -53
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
- package/dist/esm/localization/getBrowserLocale.mjs +1 -138
- package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/localization/getHTMLTextDir.mjs +1 -62
- package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs +1 -24
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocaleFromPath.mjs +1 -42
- package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
- package/dist/esm/localization/getLocaleLang.mjs +1 -18
- package/dist/esm/localization/getLocaleLang.mjs.map +1 -1
- package/dist/esm/localization/getLocaleName.mjs +1 -9
- package/dist/esm/localization/getLocaleName.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +1 -79
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs +1 -60
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs +1 -52
- package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs +1 -60
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/localization/index.mjs +1 -17
- package/dist/esm/localization/localeDetector.mjs +1 -131
- package/dist/esm/localization/localeDetector.mjs.map +1 -1
- package/dist/esm/localization/localeMapper.mjs +1 -114
- package/dist/esm/localization/localeMapper.mjs.map +1 -1
- package/dist/esm/localization/localeResolver.mjs +1 -25
- package/dist/esm/localization/localeResolver.mjs.map +1 -1
- package/dist/esm/localization/rewriteUtils.mjs +1 -104
- package/dist/esm/localization/rewriteUtils.mjs.map +1 -1
- package/dist/esm/localization/validatePrefix.mjs +1 -51
- package/dist/esm/localization/validatePrefix.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +10 -786
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/constants.mjs +1 -247
- package/dist/esm/markdown/constants.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +1 -7
- package/dist/esm/markdown/parser.mjs +1 -65
- package/dist/esm/markdown/parser.mjs.map +1 -1
- package/dist/esm/markdown/renderer.mjs +1 -59
- package/dist/esm/markdown/renderer.mjs.map +1 -1
- package/dist/esm/markdown/utils.mjs +6 -361
- package/dist/esm/markdown/utils.mjs.map +1 -1
- package/dist/esm/messageFormat/ICU.mjs +1 -316
- package/dist/esm/messageFormat/ICU.mjs.map +1 -1
- package/dist/esm/messageFormat/i18next.mjs +1 -327
- package/dist/esm/messageFormat/i18next.mjs.map +1 -1
- package/dist/esm/messageFormat/index.mjs +1 -5
- package/dist/esm/messageFormat/verify-icu-format.mjs +2 -64
- package/dist/esm/messageFormat/verify-icu-format.mjs.map +1 -1
- package/dist/esm/messageFormat/vue-i18n.mjs +1 -163
- package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
- package/dist/esm/transpiler/condition/condition.mjs +1 -24
- package/dist/esm/transpiler/condition/condition.mjs.map +1 -1
- package/dist/esm/transpiler/condition/index.mjs +1 -3
- package/dist/esm/transpiler/enumeration/enumeration.mjs +1 -26
- package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/enumeration/index.mjs +1 -3
- package/dist/esm/transpiler/file/file.mjs +1 -49
- package/dist/esm/transpiler/file/file.mjs.map +1 -1
- package/dist/esm/transpiler/file/fileBrowser.mjs +1 -24
- package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -1
- package/dist/esm/transpiler/file/index.mjs +1 -3
- package/dist/esm/transpiler/gender/gender.mjs +1 -24
- package/dist/esm/transpiler/gender/gender.mjs.map +1 -1
- package/dist/esm/transpiler/gender/index.mjs +1 -3
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs +1 -43
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
- package/dist/esm/transpiler/html/html.mjs +1 -35
- package/dist/esm/transpiler/html/html.mjs.map +1 -1
- package/dist/esm/transpiler/html/htmlTags.mjs +1 -114
- package/dist/esm/transpiler/html/htmlTags.mjs.map +1 -1
- package/dist/esm/transpiler/html/index.mjs +1 -4
- package/dist/esm/transpiler/index.mjs +1 -13
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs +1 -9
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/index.mjs +1 -4
- package/dist/esm/transpiler/insertion/insertion.mjs +1 -34
- package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs +2 -22
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/index.mjs +1 -4
- package/dist/esm/transpiler/markdown/markdown.mjs +1 -52
- package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
- package/dist/esm/transpiler/nesting/index.mjs +1 -3
- package/dist/esm/transpiler/nesting/nesting.mjs +1 -25
- package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
- package/dist/esm/transpiler/translation/index.mjs +1 -3
- package/dist/esm/transpiler/translation/translation.mjs +1 -27
- package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
- package/dist/esm/utils/checkIsURLAbsolute.mjs +1 -5
- package/dist/esm/utils/checkIsURLAbsolute.mjs.map +1 -1
- package/dist/esm/utils/getCookie.mjs +1 -30
- package/dist/esm/utils/getCookie.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +1 -0
- package/dist/esm/utils/intl.mjs +1 -86
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/esm/utils/isSameKeyPath.mjs +1 -5
- package/dist/esm/utils/isSameKeyPath.mjs.map +1 -1
- package/dist/esm/utils/isValidReactElement.mjs +1 -12
- package/dist/esm/utils/isValidReactElement.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs +1 -135
- package/dist/esm/utils/localeStorage.mjs.map +1 -1
- package/dist/esm/utils/parseYaml.mjs +16 -320
- package/dist/esm/utils/parseYaml.mjs.map +1 -1
- package/dist/types/formatters/index.d.ts +2 -1
- package/dist/types/index.d.ts +8 -2
- package/dist/types/interpreter/getContent/plugins.d.ts +4 -4
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/localization/index.d.ts +2 -1
- package/dist/types/markdown/index.d.ts +4 -1
- package/dist/types/markdown/types.d.ts +1 -1
- package/dist/types/markdown/types.d.ts.map +1 -1
- package/dist/types/transpiler/translation/translation.d.ts +1 -1
- package/dist/types/utils/index.d.ts +8 -0
- package/package.json +65 -11
|
@@ -1,60 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/deepTransformPlugins/getReplacedValuesContent.ts
|
|
4
|
-
const replaceValuesPlugin = (value) => ({
|
|
5
|
-
id: "replace-values-plugin",
|
|
6
|
-
canHandle: (node) => typeof node === "string" || typeof node === "number" || typeof node === "boolean",
|
|
7
|
-
transform: () => value
|
|
8
|
-
});
|
|
9
|
-
const skipTypedNodePlugin = {
|
|
10
|
-
id: "skip-typed-node-plugin",
|
|
11
|
-
canHandle: (node) => typeof node === "object" && typeof node?.nodeType === "string",
|
|
12
|
-
transform: (node, props, deepTransformNode) => {
|
|
13
|
-
const nodeType = node.nodeType;
|
|
14
|
-
const result = structuredClone(node[nodeType]);
|
|
15
|
-
if (typeof result !== "object" || result === null) {
|
|
16
|
-
const transformedResult = deepTransformNode(result, {
|
|
17
|
-
...props,
|
|
18
|
-
children: result,
|
|
19
|
-
keyPath: [...props.keyPath, {
|
|
20
|
-
type: nodeType,
|
|
21
|
-
key: nodeType
|
|
22
|
-
}]
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
...node,
|
|
26
|
-
[nodeType]: transformedResult
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
for (const key in result) {
|
|
30
|
-
const childProps = {
|
|
31
|
-
...props,
|
|
32
|
-
children: result[key],
|
|
33
|
-
keyPath: [...props.keyPath, {
|
|
34
|
-
type: nodeType,
|
|
35
|
-
key
|
|
36
|
-
}]
|
|
37
|
-
};
|
|
38
|
-
result[key] = deepTransformNode(result[key], childProps);
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
...node,
|
|
42
|
-
[nodeType]: result
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const getReplacedValuesContent = (node, value, nodeProps) => {
|
|
47
|
-
const plugins = [
|
|
48
|
-
skipTypedNodePlugin,
|
|
49
|
-
replaceValuesPlugin(value),
|
|
50
|
-
...nodeProps.plugins ?? []
|
|
51
|
-
];
|
|
52
|
-
return deepTransformNode(JSON.parse(JSON.stringify(node)), {
|
|
53
|
-
...nodeProps,
|
|
54
|
-
plugins
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
export { getReplacedValuesContent };
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";const t=e=>({id:`replace-values-plugin`,canHandle:e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`,transform:()=>e}),n={id:`skip-typed-node-plugin`,canHandle:e=>typeof e==`object`&&typeof e?.nodeType==`string`,transform:(e,t,n)=>{let r=e.nodeType,i=structuredClone(e[r]);if(typeof i!=`object`||!i){let a=n(i,{...t,children:i,keyPath:[...t.keyPath,{type:r,key:r}]});return{...e,[r]:a}}for(let e in i){let a={...t,children:i[e],keyPath:[...t.keyPath,{type:r,key:e}]};i[e]=n(i[e],a)}return{...e,[r]:i}}},r=(r,i,a)=>{let o=[n,t(i),...a.plugins??[]];return e(JSON.parse(JSON.stringify(r)),{...a,plugins:o})};export{r as getReplacedValuesContent};
|
|
60
2
|
//# sourceMappingURL=getReplacedValuesContent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getReplacedValuesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getReplacedValuesContent.ts"],"sourcesContent":["import type {\n ContentNode,\n KeyPath,\n NodeType,\n TypedNode,\n} from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst replaceValuesPlugin = (value: string | number | boolean): Plugins => ({\n id: 'replace-values-plugin',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: () => value,\n});\n\nconst skipTypedNodePlugin: Plugins = {\n id: 'skip-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node: TypedNode, props, deepTransformNode) => {\n const nodeType = node.nodeType as NodeType;\n const result = structuredClone(\n node[nodeType as unknown as keyof TypedNode] as any\n );\n\n // If the result is a primitive value (string, number, boolean),\n // we need to transform it directly instead of iterating over its properties\n if (typeof result !== 'object' || result === null) {\n const transformedResult = deepTransformNode(result, {\n ...props,\n children: result,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformedResult,\n };\n }\n\n // For objects and arrays, iterate over their properties\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: result };\n },\n};\n\nexport const getReplacedValuesContent = (\n node: ContentNode,\n value: string | number | boolean,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n skipTypedNodePlugin,\n replaceValuesPlugin(value),\n ...(nodeProps.plugins ?? []),\n ];\n\n const JSONNode = JSON.parse(JSON.stringify(node));\n\n return deepTransformNode(JSONNode, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getReplacedValuesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getReplacedValuesContent.ts"],"sourcesContent":["import type {\n ContentNode,\n KeyPath,\n NodeType,\n TypedNode,\n} from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst replaceValuesPlugin = (value: string | number | boolean): Plugins => ({\n id: 'replace-values-plugin',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: () => value,\n});\n\nconst skipTypedNodePlugin: Plugins = {\n id: 'skip-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node: TypedNode, props, deepTransformNode) => {\n const nodeType = node.nodeType as NodeType;\n const result = structuredClone(\n node[nodeType as unknown as keyof TypedNode] as any\n );\n\n // If the result is a primitive value (string, number, boolean),\n // we need to transform it directly instead of iterating over its properties\n if (typeof result !== 'object' || result === null) {\n const transformedResult = deepTransformNode(result, {\n ...props,\n children: result,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformedResult,\n };\n }\n\n // For objects and arrays, iterate over their properties\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: result };\n },\n};\n\nexport const getReplacedValuesContent = (\n node: ContentNode,\n value: string | number | boolean,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n skipTypedNodePlugin,\n replaceValuesPlugin(value),\n ...(nodeProps.plugins ?? []),\n ];\n\n const JSONNode = JSON.parse(JSON.stringify(node));\n\n return deepTransformNode(JSONNode, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":"gFAYA,MAAM,EAAuB,IAA+C,CAC1E,GAAI,wBACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,UAClB,cAAiB,EAClB,EAEK,EAA+B,CACnC,GAAI,yBACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAO,GAAM,UAAa,SACxD,WAAY,EAAiB,EAAO,IAAsB,CACxD,IAAM,EAAW,EAAK,SAChB,EAAS,gBACb,EAAK,GACN,CAID,GAAI,OAAO,GAAW,WAAY,EAAiB,CACjD,IAAM,EAAoB,EAAkB,EAAQ,CAClD,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAU,IAAK,EAAU,CAClC,CACF,CAAC,CACF,MAAO,CACL,GAAG,GACF,GAAyC,EAC3C,CAIH,IAAK,IAAM,KAAO,EAAQ,CACxB,IAAM,EAAa,CACjB,GAAG,EACH,SAAU,EAAO,GACjB,QAAS,CAAC,GAAG,EAAM,QAAS,CAAE,KAAM,EAAU,MAAK,CAAY,CAChE,CACD,EAAO,GAAyC,EAC9C,EAAO,GACP,EACD,CAGH,MAAO,CAAE,GAAG,GAAO,GAAyC,EAAQ,EAEvE,CAEY,GACX,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EACA,EAAoB,EAAM,CAC1B,GAAI,EAAU,SAAW,EAAE,CAC5B,CAID,OAAO,EAFU,KAAK,MAAM,KAAK,UAAU,EAAK,CAAC,CAEd,CACjC,GAAG,EACH,UACD,CAAC"}
|
|
@@ -1,120 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/deepTransformPlugins/getSplittedContent.ts
|
|
4
|
-
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
-
const hasNodeType = (value) => isObject(value) && typeof value.nodeType === "string";
|
|
6
|
-
const mergeValues = (a, b) => {
|
|
7
|
-
if (a === void 0) return b;
|
|
8
|
-
if (b === void 0) return a;
|
|
9
|
-
if (Array.isArray(a) && Array.isArray(b)) return [...a, ...b];
|
|
10
|
-
if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {
|
|
11
|
-
const result = { ...a };
|
|
12
|
-
for (const key of Object.keys(b)) result[key] = mergeValues(result[key], b[key]);
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
return b;
|
|
16
|
-
};
|
|
17
|
-
const mergeSplitResults = (base, addition) => {
|
|
18
|
-
const result = { ...base };
|
|
19
|
-
result.common = mergeValues(base.common, addition.common);
|
|
20
|
-
const localeKeys = new Set([...Object.keys(base).filter((k) => k !== "common"), ...Object.keys(addition).filter((k) => k !== "common")]);
|
|
21
|
-
for (const key of localeKeys) result[key] = mergeValues(base[key], addition[key]);
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
const splitNode = (node) => {
|
|
25
|
-
if (isObject(node) && node?.nodeType === NodeType.Translation) {
|
|
26
|
-
const translations = node[NodeType.Translation];
|
|
27
|
-
const result = {};
|
|
28
|
-
for (const locale of Object.keys(translations)) {
|
|
29
|
-
const child = translations[locale];
|
|
30
|
-
const childSplit = splitNode(child);
|
|
31
|
-
const mergedForLocale = mergeValues(childSplit.common, void 0);
|
|
32
|
-
let recomposed;
|
|
33
|
-
for (const key of Object.keys(childSplit)) {
|
|
34
|
-
if (key === "common") continue;
|
|
35
|
-
recomposed = mergeValues(recomposed, childSplit[key]);
|
|
36
|
-
}
|
|
37
|
-
const finalLocaleNode = mergeValues(mergedForLocale, recomposed);
|
|
38
|
-
if (finalLocaleNode !== void 0) result[locale] = finalLocaleNode;
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
if (Array.isArray(node)) {
|
|
43
|
-
const commonArray = [];
|
|
44
|
-
const perLocaleArrays = {};
|
|
45
|
-
node.forEach((child) => {
|
|
46
|
-
const childSplit = splitNode(child);
|
|
47
|
-
if (childSplit.common !== void 0) commonArray.push(childSplit.common);
|
|
48
|
-
for (const key of Object.keys(childSplit)) {
|
|
49
|
-
if (key === "common") continue;
|
|
50
|
-
if (!perLocaleArrays[key]) perLocaleArrays[key] = [];
|
|
51
|
-
const value = childSplit[key];
|
|
52
|
-
if (value !== void 0) perLocaleArrays[key].push(value);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
const result = {};
|
|
56
|
-
if (commonArray.length > 0) result.common = commonArray;
|
|
57
|
-
for (const key of Object.keys(perLocaleArrays)) result[key] = perLocaleArrays[key];
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
if (isObject(node) && !hasNodeType(node)) {
|
|
61
|
-
let accumulated = {};
|
|
62
|
-
for (const key of Object.keys(node)) {
|
|
63
|
-
const childSplit = splitNode(node[key]);
|
|
64
|
-
if (childSplit.common !== void 0) accumulated = mergeSplitResults(accumulated, { common: { [key]: childSplit.common } });
|
|
65
|
-
for (const locale of Object.keys(childSplit)) {
|
|
66
|
-
if (locale === "common") continue;
|
|
67
|
-
accumulated = mergeSplitResults(accumulated, { [locale]: { [key]: childSplit[locale] } });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return accumulated;
|
|
71
|
-
}
|
|
72
|
-
return { common: node };
|
|
73
|
-
};
|
|
74
|
-
const getSplittedContent = (content) => {
|
|
75
|
-
const split = splitNode(content);
|
|
76
|
-
const output = {};
|
|
77
|
-
if (split.common !== void 0) output.common = split.common;
|
|
78
|
-
for (const key of Object.keys(split)) {
|
|
79
|
-
if (key === "common") continue;
|
|
80
|
-
const value = split[key];
|
|
81
|
-
if (value !== void 0) output[key] = value;
|
|
82
|
-
}
|
|
83
|
-
return output;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Splits the `content` field of a Dictionary into "common" and per-locale buckets.
|
|
87
|
-
*
|
|
88
|
-
* Given a dictionary like:
|
|
89
|
-
* ```js
|
|
90
|
-
* {
|
|
91
|
-
* key: "my-key",
|
|
92
|
-
* content: {
|
|
93
|
-
* commonContent: "common content",
|
|
94
|
-
* multilingualContent: t({
|
|
95
|
-
* en: "english content",
|
|
96
|
-
* fr: "french content",
|
|
97
|
-
* de: "german content",
|
|
98
|
-
* }),
|
|
99
|
-
* },
|
|
100
|
-
* }
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* It produces:
|
|
104
|
-
* ```js
|
|
105
|
-
* {
|
|
106
|
-
* common: { commonContent: "common content" },
|
|
107
|
-
* en: { multilingualContent: "english content" },
|
|
108
|
-
* fr: { multilingualContent: "french content" },
|
|
109
|
-
* de: { multilingualContent: "german content" },
|
|
110
|
-
* }
|
|
111
|
-
* ```
|
|
112
|
-
*
|
|
113
|
-
* @param dictionary - The input dictionary object with possible multilingual or common content.
|
|
114
|
-
* @returns An object mapping "common" and each locale to their corresponding content subtrees.
|
|
115
|
-
*/
|
|
116
|
-
const getSplittedDictionaryContent = (dictionary) => getSplittedContent(dictionary.content);
|
|
117
|
-
|
|
118
|
-
//#endregion
|
|
119
|
-
export { getSplittedContent, getSplittedDictionaryContent };
|
|
1
|
+
import{NodeType as e}from"@intlayer/types";const t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),n=e=>t(e)&&typeof e.nodeType==`string`,r=(e,i)=>{if(e===void 0)return i;if(i===void 0)return e;if(Array.isArray(e)&&Array.isArray(i))return[...e,...i];if(t(e)&&t(i)&&!n(e)&&!n(i)){let t={...e};for(let e of Object.keys(i))t[e]=r(t[e],i[e]);return t}return i},i=(e,t)=>{let n={...e};n.common=r(e.common,t.common);let i=new Set([...Object.keys(e).filter(e=>e!==`common`),...Object.keys(t).filter(e=>e!==`common`)]);for(let a of i)n[a]=r(e[a],t[a]);return n},a=o=>{if(t(o)&&o?.nodeType===e.Translation){let t=o[e.Translation],n={};for(let e of Object.keys(t)){let i=t[e],o=a(i),s=r(o.common,void 0),c;for(let e of Object.keys(o))e!==`common`&&(c=r(c,o[e]));let l=r(s,c);l!==void 0&&(n[e]=l)}return n}if(Array.isArray(o)){let e=[],t={};o.forEach(n=>{let r=a(n);r.common!==void 0&&e.push(r.common);for(let e of Object.keys(r)){if(e===`common`)continue;t[e]||(t[e]=[]);let n=r[e];n!==void 0&&t[e].push(n)}});let n={};e.length>0&&(n.common=e);for(let e of Object.keys(t))n[e]=t[e];return n}if(t(o)&&!n(o)){let e={};for(let t of Object.keys(o)){let n=a(o[t]);n.common!==void 0&&(e=i(e,{common:{[t]:n.common}}));for(let r of Object.keys(n))r!==`common`&&(e=i(e,{[r]:{[t]:n[r]}}))}return e}return{common:o}},o=e=>{let t=a(e),n={};t.common!==void 0&&(n.common=t.common);for(let e of Object.keys(t)){if(e===`common`)continue;let r=t[e];r!==void 0&&(n[e]=r)}return n},s=e=>o(e.content);export{o as getSplittedContent,s as getSplittedDictionaryContent};
|
|
120
2
|
//# sourceMappingURL=getSplittedContent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSplittedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getSplittedContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type DeclaredLocales,\n type Dictionary,\n NodeType,\n} from '@intlayer/types';\n\ntype SplittedContentOutput<T = ContentNode> = Record<DeclaredLocales, T> & {\n common: T;\n};\n\ntype SplitResult = Record<string, ContentNode | undefined> & {\n common?: ContentNode;\n};\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst hasNodeType = (value: unknown): value is { nodeType: string } =>\n isObject(value) && typeof (value as any).nodeType === 'string';\n\nconst mergeValues = (\n a: ContentNode | undefined,\n b: ContentNode | undefined\n): ContentNode | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n // Concatenate arrays when merging sibling results\n return [...a, ...b] as unknown as ContentNode;\n }\n\n if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {\n const result: Record<string, any> = { ...a };\n for (const key of Object.keys(b)) {\n result[key] = mergeValues(\n result[key] as unknown as ContentNode | undefined,\n (b as Record<string, any>)[key] as unknown as ContentNode | undefined\n );\n }\n return result as ContentNode;\n }\n\n // For primitives or differing structures, prefer b (more recent)\n return b;\n};\n\nconst mergeSplitResults = (\n base: SplitResult,\n addition: SplitResult\n): SplitResult => {\n const result: SplitResult = { ...base };\n\n // Merge common\n result.common = mergeValues(base.common, addition.common);\n\n // Merge each locale key present in either side\n const localeKeys = new Set<string>([\n ...Object.keys(base).filter((k) => k !== 'common'),\n ...Object.keys(addition).filter((k) => k !== 'common'),\n ]);\n\n for (const key of localeKeys) {\n // @ts-ignore: dynamic keys for locales\n result[key] = mergeValues(\n base[key] as ContentNode | undefined,\n addition[key] as ContentNode | undefined\n );\n }\n\n return result;\n};\n\nconst splitNode = (node: ContentNode): SplitResult => {\n // Translation node: allocate entirely to per-locale buckets\n if (isObject(node) && (node as any)?.nodeType === NodeType.Translation) {\n const translations = (node as any)[NodeType.Translation] as Record<\n string,\n ContentNode\n >;\n\n const result: SplitResult = {};\n for (const locale of Object.keys(translations)) {\n const child = translations[locale];\n const childSplit = splitNode(child);\n\n // The content under a translation belongs to the locale, not common\n // Merge common portion of the child (if any) into the locale as well\n const mergedForLocale = mergeValues(childSplit.common, undefined);\n\n // Compose locale content: prefer the fully rebuilt child by resolving deeper translations recursively\n // which are already split inside childSplit. We need to recompose a single node for this locale.\n // Recompose by merging all keys in childSplit except 'common' into a single node, then merge child's common.\n let recomposed: ContentNode | undefined;\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n recomposed = mergeValues(\n recomposed,\n childSplit[key] as ContentNode | undefined\n );\n }\n const finalLocaleNode = mergeValues(mergedForLocale, recomposed);\n\n if (finalLocaleNode !== undefined) {\n // @ts-ignore dynamic locale key\n result[locale] = finalLocaleNode;\n }\n }\n\n return result;\n }\n\n // Arrays: split each element and merge results index-wise\n if (Array.isArray(node)) {\n const commonArray: any[] = [];\n const perLocaleArrays: Record<string, any[]> = {};\n\n node.forEach((child) => {\n const childSplit = splitNode(child as ContentNode);\n\n if (childSplit.common !== undefined) {\n commonArray.push(childSplit.common);\n }\n\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n if (!perLocaleArrays[key]) perLocaleArrays[key] = [];\n const value = childSplit[key];\n if (value !== undefined) perLocaleArrays[key].push(value);\n }\n });\n\n const result: SplitResult = {};\n if (commonArray.length > 0)\n result.common = commonArray as unknown as ContentNode;\n for (const key of Object.keys(perLocaleArrays)) {\n // @ts-ignore dynamic locale key\n result[key] = perLocaleArrays[key] as unknown as ContentNode;\n }\n return result;\n }\n\n // Objects (non-typed): recursively split properties\n if (isObject(node) && !hasNodeType(node)) {\n let accumulated: SplitResult = {};\n\n for (const key of Object.keys(node)) {\n const childSplit = splitNode((node as any)[key] as ContentNode);\n\n // Assign property into common\n if (childSplit.common !== undefined) {\n accumulated = mergeSplitResults(accumulated, {\n common: { [key]: childSplit.common } as unknown as ContentNode,\n });\n }\n\n // Assign property into each locale bucket\n for (const locale of Object.keys(childSplit)) {\n if (locale === 'common') continue;\n accumulated = mergeSplitResults(accumulated, {\n // @ts-ignore dynamic locale key\n [locale]: { [key]: childSplit[locale] } as unknown as ContentNode,\n });\n }\n }\n\n return accumulated;\n }\n\n // Primitives or typed nodes (non-translation): entirely common\n return { common: node } as SplitResult;\n};\n\nexport const getSplittedContent = (\n content: ContentNode\n): SplittedContentOutput => {\n const split = splitNode(content);\n\n // Build final output with only defined sections\n const output: Record<string, ContentNode> = {};\n if (split.common !== undefined) {\n output.common = split.common;\n }\n for (const key of Object.keys(split)) {\n if (key === 'common') continue;\n const value = split[key] as ContentNode | undefined;\n if (value !== undefined) {\n output[key] = value;\n }\n }\n\n return output as unknown as SplittedContentOutput;\n};\n\n/**\n * Splits the `content` field of a Dictionary into \"common\" and per-locale buckets.\n *\n * Given a dictionary like:\n * ```js\n * {\n * key: \"my-key\",\n * content: {\n * commonContent: \"common content\",\n * multilingualContent: t({\n * en: \"english content\",\n * fr: \"french content\",\n * de: \"german content\",\n * }),\n * },\n * }\n * ```\n *\n * It produces:\n * ```js\n * {\n * common: { commonContent: \"common content\" },\n * en: { multilingualContent: \"english content\" },\n * fr: { multilingualContent: \"french content\" },\n * de: { multilingualContent: \"german content\" },\n * }\n * ```\n *\n * @param dictionary - The input dictionary object with possible multilingual or common content.\n * @returns An object mapping \"common\" and each locale to their corresponding content subtrees.\n */\nexport const getSplittedDictionaryContent = (\n dictionary: Dictionary\n): SplittedContentOutput<Dictionary['content']> =>\n getSplittedContent(dictionary.content);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getSplittedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getSplittedContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type DeclaredLocales,\n type Dictionary,\n NodeType,\n} from '@intlayer/types';\n\ntype SplittedContentOutput<T = ContentNode> = Record<DeclaredLocales, T> & {\n common: T;\n};\n\ntype SplitResult = Record<string, ContentNode | undefined> & {\n common?: ContentNode;\n};\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst hasNodeType = (value: unknown): value is { nodeType: string } =>\n isObject(value) && typeof (value as any).nodeType === 'string';\n\nconst mergeValues = (\n a: ContentNode | undefined,\n b: ContentNode | undefined\n): ContentNode | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n // Concatenate arrays when merging sibling results\n return [...a, ...b] as unknown as ContentNode;\n }\n\n if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {\n const result: Record<string, any> = { ...a };\n for (const key of Object.keys(b)) {\n result[key] = mergeValues(\n result[key] as unknown as ContentNode | undefined,\n (b as Record<string, any>)[key] as unknown as ContentNode | undefined\n );\n }\n return result as ContentNode;\n }\n\n // For primitives or differing structures, prefer b (more recent)\n return b;\n};\n\nconst mergeSplitResults = (\n base: SplitResult,\n addition: SplitResult\n): SplitResult => {\n const result: SplitResult = { ...base };\n\n // Merge common\n result.common = mergeValues(base.common, addition.common);\n\n // Merge each locale key present in either side\n const localeKeys = new Set<string>([\n ...Object.keys(base).filter((k) => k !== 'common'),\n ...Object.keys(addition).filter((k) => k !== 'common'),\n ]);\n\n for (const key of localeKeys) {\n // @ts-ignore: dynamic keys for locales\n result[key] = mergeValues(\n base[key] as ContentNode | undefined,\n addition[key] as ContentNode | undefined\n );\n }\n\n return result;\n};\n\nconst splitNode = (node: ContentNode): SplitResult => {\n // Translation node: allocate entirely to per-locale buckets\n if (isObject(node) && (node as any)?.nodeType === NodeType.Translation) {\n const translations = (node as any)[NodeType.Translation] as Record<\n string,\n ContentNode\n >;\n\n const result: SplitResult = {};\n for (const locale of Object.keys(translations)) {\n const child = translations[locale];\n const childSplit = splitNode(child);\n\n // The content under a translation belongs to the locale, not common\n // Merge common portion of the child (if any) into the locale as well\n const mergedForLocale = mergeValues(childSplit.common, undefined);\n\n // Compose locale content: prefer the fully rebuilt child by resolving deeper translations recursively\n // which are already split inside childSplit. We need to recompose a single node for this locale.\n // Recompose by merging all keys in childSplit except 'common' into a single node, then merge child's common.\n let recomposed: ContentNode | undefined;\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n recomposed = mergeValues(\n recomposed,\n childSplit[key] as ContentNode | undefined\n );\n }\n const finalLocaleNode = mergeValues(mergedForLocale, recomposed);\n\n if (finalLocaleNode !== undefined) {\n // @ts-ignore dynamic locale key\n result[locale] = finalLocaleNode;\n }\n }\n\n return result;\n }\n\n // Arrays: split each element and merge results index-wise\n if (Array.isArray(node)) {\n const commonArray: any[] = [];\n const perLocaleArrays: Record<string, any[]> = {};\n\n node.forEach((child) => {\n const childSplit = splitNode(child as ContentNode);\n\n if (childSplit.common !== undefined) {\n commonArray.push(childSplit.common);\n }\n\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n if (!perLocaleArrays[key]) perLocaleArrays[key] = [];\n const value = childSplit[key];\n if (value !== undefined) perLocaleArrays[key].push(value);\n }\n });\n\n const result: SplitResult = {};\n if (commonArray.length > 0)\n result.common = commonArray as unknown as ContentNode;\n for (const key of Object.keys(perLocaleArrays)) {\n // @ts-ignore dynamic locale key\n result[key] = perLocaleArrays[key] as unknown as ContentNode;\n }\n return result;\n }\n\n // Objects (non-typed): recursively split properties\n if (isObject(node) && !hasNodeType(node)) {\n let accumulated: SplitResult = {};\n\n for (const key of Object.keys(node)) {\n const childSplit = splitNode((node as any)[key] as ContentNode);\n\n // Assign property into common\n if (childSplit.common !== undefined) {\n accumulated = mergeSplitResults(accumulated, {\n common: { [key]: childSplit.common } as unknown as ContentNode,\n });\n }\n\n // Assign property into each locale bucket\n for (const locale of Object.keys(childSplit)) {\n if (locale === 'common') continue;\n accumulated = mergeSplitResults(accumulated, {\n // @ts-ignore dynamic locale key\n [locale]: { [key]: childSplit[locale] } as unknown as ContentNode,\n });\n }\n }\n\n return accumulated;\n }\n\n // Primitives or typed nodes (non-translation): entirely common\n return { common: node } as SplitResult;\n};\n\nexport const getSplittedContent = (\n content: ContentNode\n): SplittedContentOutput => {\n const split = splitNode(content);\n\n // Build final output with only defined sections\n const output: Record<string, ContentNode> = {};\n if (split.common !== undefined) {\n output.common = split.common;\n }\n for (const key of Object.keys(split)) {\n if (key === 'common') continue;\n const value = split[key] as ContentNode | undefined;\n if (value !== undefined) {\n output[key] = value;\n }\n }\n\n return output as unknown as SplittedContentOutput;\n};\n\n/**\n * Splits the `content` field of a Dictionary into \"common\" and per-locale buckets.\n *\n * Given a dictionary like:\n * ```js\n * {\n * key: \"my-key\",\n * content: {\n * commonContent: \"common content\",\n * multilingualContent: t({\n * en: \"english content\",\n * fr: \"french content\",\n * de: \"german content\",\n * }),\n * },\n * }\n * ```\n *\n * It produces:\n * ```js\n * {\n * common: { commonContent: \"common content\" },\n * en: { multilingualContent: \"english content\" },\n * fr: { multilingualContent: \"french content\" },\n * de: { multilingualContent: \"german content\" },\n * }\n * ```\n *\n * @param dictionary - The input dictionary object with possible multilingual or common content.\n * @returns An object mapping \"common\" and each locale to their corresponding content subtrees.\n */\nexport const getSplittedDictionaryContent = (\n dictionary: Dictionary\n): SplittedContentOutput<Dictionary['content']> =>\n getSplittedContent(dictionary.content);\n"],"mappings":"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"}
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { filterMissingTranslationsOnlyPlugin, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary } from "./getFilterMissingTranslationsContent.mjs";
|
|
3
|
-
import { filterTranslationsOnlyPlugin, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary } from "./getFilterTranslationsOnlyContent.mjs";
|
|
4
|
-
import { getLocalizedContent, getPerLocaleDictionary } from "./getLocalizedContent.mjs";
|
|
5
|
-
import { buildMaskPlugin, getMaskContent } from "./getMaskContent.mjs";
|
|
6
|
-
import { checkMissingLocalesPlugin, getMissingLocalesContent, getMissingLocalesContentFromDictionary } from "./getMissingLocalesContent.mjs";
|
|
7
|
-
import { getMultilingualDictionary } from "./getMultilingualDictionary.mjs";
|
|
8
|
-
import { getReplacedValuesContent } from "./getReplacedValuesContent.mjs";
|
|
9
|
-
import { getSplittedContent, getSplittedDictionaryContent } from "./getSplittedContent.mjs";
|
|
10
|
-
import { insertContentInDictionary } from "./insertContentInDictionary.mjs";
|
|
11
|
-
|
|
12
|
-
export { buildMaskPlugin, checkMissingLocalesPlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getLocalizedContent, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getPerLocaleDictionary, getReplacedValuesContent, getSplittedContent, getSplittedDictionaryContent, insertContentInDictionary };
|
|
1
|
+
import{getFilteredLocalesContent as e,getFilteredLocalesDictionary as t}from"./getFilteredLocalesContent.mjs";import{filterMissingTranslationsOnlyPlugin as n,getFilterMissingTranslationsContent as r,getFilterMissingTranslationsDictionary as i}from"./getFilterMissingTranslationsContent.mjs";import{filterTranslationsOnlyPlugin as a,getFilterTranslationsOnlyContent as o,getFilterTranslationsOnlyDictionary as s}from"./getFilterTranslationsOnlyContent.mjs";import{getLocalizedContent as c,getPerLocaleDictionary as l}from"./getLocalizedContent.mjs";import{buildMaskPlugin as u,getMaskContent as d}from"./getMaskContent.mjs";import{checkMissingLocalesPlugin as f,getMissingLocalesContent as p,getMissingLocalesContentFromDictionary as m}from"./getMissingLocalesContent.mjs";import{getMultilingualDictionary as h}from"./getMultilingualDictionary.mjs";import{getReplacedValuesContent as g}from"./getReplacedValuesContent.mjs";import{getSplittedContent as _,getSplittedDictionaryContent as v}from"./getSplittedContent.mjs";import{insertContentInDictionary as y}from"./insertContentInDictionary.mjs";export{u as buildMaskPlugin,f as checkMissingLocalesPlugin,n as filterMissingTranslationsOnlyPlugin,a as filterTranslationsOnlyPlugin,r as getFilterMissingTranslationsContent,i as getFilterMissingTranslationsDictionary,o as getFilterTranslationsOnlyContent,s as getFilterTranslationsOnlyDictionary,e as getFilteredLocalesContent,t as getFilteredLocalesDictionary,c as getLocalizedContent,d as getMaskContent,p as getMissingLocalesContent,m as getMissingLocalesContentFromDictionary,h as getMultilingualDictionary,l as getPerLocaleDictionary,g as getReplacedValuesContent,_ as getSplittedContent,v as getSplittedDictionaryContent,y as insertContentInDictionary};
|
|
@@ -1,105 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/deepTransformPlugins/insertContentInDictionary.ts
|
|
4
|
-
/**
|
|
5
|
-
* Deep merge helper that handles translation blocks
|
|
6
|
-
* @param target - The target object (dictionary content)
|
|
7
|
-
* @param source - The source object (new content to merge)
|
|
8
|
-
* @param locale - Optional locale to target specific translation
|
|
9
|
-
* @returns Merged content
|
|
10
|
-
*/
|
|
11
|
-
const deepMergeContent = (target, source, locale) => {
|
|
12
|
-
if (source === null || source === void 0) return target;
|
|
13
|
-
if (target === null || target === void 0) if (Array.isArray(source)) target = [];
|
|
14
|
-
else if (typeof source === "object") target = {};
|
|
15
|
-
else return source;
|
|
16
|
-
if (target && typeof target === "object" && target.nodeType === NodeType.Translation) if (locale) {
|
|
17
|
-
const existingLocaleContent = target.translation[locale];
|
|
18
|
-
let newLocaleContent;
|
|
19
|
-
if (typeof source === "object" && !Array.isArray(source)) newLocaleContent = deepMergeContent(existingLocaleContent, source, void 0);
|
|
20
|
-
else if (Array.isArray(source)) newLocaleContent = source;
|
|
21
|
-
else newLocaleContent = source;
|
|
22
|
-
return {
|
|
23
|
-
...target,
|
|
24
|
-
translation: {
|
|
25
|
-
...target.translation,
|
|
26
|
-
[locale]: newLocaleContent
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
} else if (typeof source === "object" && !Array.isArray(source) && source.nodeType === NodeType.Translation) return {
|
|
30
|
-
...target,
|
|
31
|
-
translation: {
|
|
32
|
-
...target.translation,
|
|
33
|
-
...source.translation
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
else return processNewContent(source, locale);
|
|
37
|
-
if (Array.isArray(source)) if (locale && Array.isArray(target)) {
|
|
38
|
-
const result = [];
|
|
39
|
-
const maxLength = Math.max(source.length, target.length);
|
|
40
|
-
for (let i = 0; i < maxLength; i++) if (i < source.length) if (i < target.length && target[i] !== void 0) result[i] = deepMergeContent(target[i], source[i], locale);
|
|
41
|
-
else result[i] = processNewContent(source[i], locale);
|
|
42
|
-
else result[i] = target[i];
|
|
43
|
-
return result;
|
|
44
|
-
} else return source.map((item) => {
|
|
45
|
-
if (item && typeof item === "object" && item.nodeType === NodeType.Translation) return item;
|
|
46
|
-
return processNewContent(item, locale);
|
|
47
|
-
});
|
|
48
|
-
if (typeof source === "object" && !Array.isArray(source)) {
|
|
49
|
-
if (typeof target !== "object" || Array.isArray(target)) target = {};
|
|
50
|
-
const result = { ...target };
|
|
51
|
-
for (const key in source) if (Object.hasOwn(source, key)) if (target[key] !== void 0) result[key] = deepMergeContent(target[key], source[key], locale);
|
|
52
|
-
else result[key] = processNewContent(source[key], locale);
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
return source;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Process new content that doesn't exist in target
|
|
59
|
-
* @param content - New content to process
|
|
60
|
-
* @param locale - Optional locale
|
|
61
|
-
* @returns Processed content
|
|
62
|
-
*/
|
|
63
|
-
const processNewContent = (content, locale) => {
|
|
64
|
-
if (content === null || content === void 0) return content;
|
|
65
|
-
if (content && typeof content === "object" && content.nodeType === NodeType.Translation) return content;
|
|
66
|
-
if (Array.isArray(content)) return content.map((item) => processNewContent(item, locale));
|
|
67
|
-
if (content && typeof content === "object") {
|
|
68
|
-
const result = {};
|
|
69
|
-
for (const key in content) if (Object.hasOwn(content, key)) result[key] = processNewContent(content[key], locale);
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
if (locale) return {
|
|
73
|
-
nodeType: NodeType.Translation,
|
|
74
|
-
translation: { [locale]: content }
|
|
75
|
-
};
|
|
76
|
-
else return content;
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Insert content into a dictionary with deep merge support
|
|
80
|
-
* Handles translation blocks and nested structures
|
|
81
|
-
*
|
|
82
|
-
* @param dictionary - The dictionary to insert content into
|
|
83
|
-
* @param content - The content to insert
|
|
84
|
-
* @param locale - Optional locale to target specific translation
|
|
85
|
-
* @returns Updated dictionary
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* // Without locale - deep merge all content
|
|
89
|
-
* insertContentInDictionary(dictionary, { title: 'New Title' })
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* // With locale - insert content for specific locale
|
|
93
|
-
* insertContentInDictionary(dictionary, { title: 'このページ' }, 'ja')
|
|
94
|
-
*/
|
|
95
|
-
const insertContentInDictionary = (dictionary, content, locale) => {
|
|
96
|
-
const mergedContent = deepMergeContent(Array.isArray(dictionary.content) ? [...dictionary.content] : { ...dictionary.content }, content, locale);
|
|
97
|
-
return {
|
|
98
|
-
...dictionary,
|
|
99
|
-
content: mergedContent
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
export { insertContentInDictionary };
|
|
1
|
+
import{NodeType as e}from"@intlayer/types";const t=(r,i,a)=>{if(i==null)return r;if(r==null)if(Array.isArray(i))r=[];else if(typeof i==`object`)r={};else return i;if(r&&typeof r==`object`&&r.nodeType===e.Translation)if(a){let e=r.translation[a],n;return n=typeof i==`object`&&!Array.isArray(i)?t(e,i,void 0):i,{...r,translation:{...r.translation,[a]:n}}}else if(typeof i==`object`&&!Array.isArray(i)&&i.nodeType===e.Translation)return{...r,translation:{...r.translation,...i.translation}};else return n(i,a);if(Array.isArray(i))if(a&&Array.isArray(r)){let e=[],o=Math.max(i.length,r.length);for(let s=0;s<o;s++)s<i.length?s<r.length&&r[s]!==void 0?e[s]=t(r[s],i[s],a):e[s]=n(i[s],a):e[s]=r[s];return e}else return i.map(t=>t&&typeof t==`object`&&t.nodeType===e.Translation?t:n(t,a));if(typeof i==`object`&&!Array.isArray(i)){(typeof r!=`object`||Array.isArray(r))&&(r={});let e={...r};for(let o in i)Object.hasOwn(i,o)&&(r[o]===void 0?e[o]=n(i[o],a):e[o]=t(r[o],i[o],a));return e}return i},n=(t,r)=>{if(t==null||t&&typeof t==`object`&&t.nodeType===e.Translation)return t;if(Array.isArray(t))return t.map(e=>n(e,r));if(t&&typeof t==`object`){let e={};for(let i in t)Object.hasOwn(t,i)&&(e[i]=n(t[i],r));return e}return r?{nodeType:e.Translation,translation:{[r]:t}}:t},r=(e,n,r)=>{let i=t(Array.isArray(e.content)?[...e.content]:{...e.content},n,r);return{...e,content:i}};export{r as insertContentInDictionary};
|
|
105
2
|
//# sourceMappingURL=insertContentInDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertContentInDictionary.mjs","names":[],"sources":["../../../src/deepTransformPlugins/insertContentInDictionary.ts"],"sourcesContent":["import { type Dictionary, type LocalesValues, NodeType } from '@intlayer/types';\n\n// {\n// {\n// title: 'このページ',\n// linkLabel: 'セクションへ移動',\n// collapseButton: { label: '折りたたむ' }\n// },\n// }\n// {\n// dictionary: {\n// key: 'aside-navigation',\n// content: {\n// title: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'في هذه الصفحة',\n// de: 'Auf dieser Seite',\n// en: 'In this page',\n// 'en-GB': 'On this page',\n// es: 'En esta página',\n// fr: 'Dans cette page',\n// hi: 'इस पृष्ठ में',\n// it: 'In questa pagina',\n// ko: '이 페이지에서',\n// pt: 'Nesta página',\n// ru: 'На этой странице',\n// tr: 'Bu sayfada',\n// zh: '在此页面'\n// }\n// },\n// linkLabel: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'اذهب إلى القسم',\n// de: 'Gehe zur Sektion',\n// en: 'Go to section',\n// 'en-GB': 'Go to section',\n// es: 'Ir a la sección',\n// fr: 'Aller à la section',\n// hi: 'सेक्शन पर जाएं',\n// it: 'Vai alla sezione',\n// ja: 'セクションへ行く',\n// ko: '섹션으로 이동',\n// pt: 'Ir para a seção',\n// ru: 'Перейти к разделу',\n// tr: 'Bölüme git',\n// zh: '转到节'\n// }\n// },\n// collapseButton: {\n// label: {\n// nodeType: 'translation',\n// translation: {\n// en: 'Collapse',\n// fr: 'Réduire',\n// es: 'Colapsar',\n// 'en-GB': 'Collapse',\n// de: 'Zuklappen',\n// ja: '折りたたむ',\n// ko: '접기',\n// zh: '折叠',\n// it: 'Comprimi',\n// pt: 'Recolher',\n// hi: 'संकुचित करें',\n// ar: 'اطوي التوسيع',\n// ru: 'Свернуть',\n// tr: 'Daralt'\n// }\n// }\n// }\n// },\n// localId: 'aside-navigation::local::src/components/AsideNavigation/asideNavigation.content.ts',\n// location: 'local',\n// filePath: 'src/components/AsideNavigation/asideNavigation.content.ts'\n// }\n// }\n\n/**\n * Deep merge helper that handles translation blocks\n * @param target - The target object (dictionary content)\n * @param source - The source object (new content to merge)\n * @param locale - Optional locale to target specific translation\n * @returns Merged content\n */\nconst deepMergeContent = (\n target: any,\n source: any,\n locale?: LocalesValues\n): any => {\n // If source is null or undefined, return target\n if (source === null || source === undefined) return target;\n\n // If target is null or undefined, initialize based on source type\n if (target === null || target === undefined) {\n if (Array.isArray(source)) {\n target = [];\n } else if (typeof source === 'object') {\n target = {};\n } else {\n return source;\n }\n }\n\n // Handle translation nodes FIRST (before arrays) to support arrays within translations\n if (\n target &&\n typeof target === 'object' &&\n target.nodeType === NodeType.Translation\n ) {\n // Target is a translation block\n if (locale) {\n // Update only the specific locale - create new object to preserve order\n const existingLocaleContent = target.translation[locale];\n let newLocaleContent: any;\n\n if (typeof source === 'object' && !Array.isArray(source)) {\n // Source is an object, need to deep merge for this locale\n newLocaleContent = deepMergeContent(\n existingLocaleContent,\n source,\n undefined // Don't pass locale down for nested content\n );\n } else if (Array.isArray(source)) {\n // Source is an array, set it directly for this locale\n newLocaleContent = source;\n } else {\n // Source is a primitive, directly set it\n newLocaleContent = source;\n }\n\n // Return new object with locale appended at the end (preserve insertion order)\n return {\n ...target,\n translation: {\n ...target.translation,\n [locale]: newLocaleContent,\n },\n };\n } else {\n // No locale specified, replace/merge the entire translation\n if (\n typeof source === 'object' &&\n !Array.isArray(source) &&\n source.nodeType === NodeType.Translation\n ) {\n // Source is also a translation node, merge translations\n return {\n ...target,\n translation: {\n ...target.translation,\n ...source.translation,\n },\n };\n } else {\n // Source is not a translation node, wrap it\n return processNewContent(source, locale);\n }\n }\n }\n\n // Handle arrays\n if (Array.isArray(source)) {\n if (locale && Array.isArray(target)) {\n // When locale is specified and target is also an array, merge element by element\n const result = [];\n const maxLength = Math.max(source.length, target.length);\n\n for (let i = 0; i < maxLength; i++) {\n if (i < source.length) {\n if (i < target.length && target[i] !== undefined) {\n // Both source and target have element at this index - merge them\n result[i] = deepMergeContent(target[i], source[i], locale);\n } else {\n // Only source has element at this index - process new content\n result[i] = processNewContent(source[i], locale);\n }\n } else {\n // Only target has element at this index - keep it\n result[i] = target[i];\n }\n }\n\n return result;\n } else {\n // No locale or target is not an array - replace entirely\n return source.map((item) => {\n // Process each item in case it needs locale wrapping\n if (\n item &&\n typeof item === 'object' &&\n item.nodeType === NodeType.Translation\n ) {\n return item;\n }\n return processNewContent(item, locale);\n });\n }\n }\n\n // Handle objects\n if (typeof source === 'object' && !Array.isArray(source)) {\n if (typeof target !== 'object' || Array.isArray(target)) {\n target = {};\n }\n\n // Create new object to preserve key order and avoid mutation\n const result: any = { ...target };\n\n for (const key in source) {\n if (Object.hasOwn(source, key)) {\n if (target[key] !== undefined) {\n result[key] = deepMergeContent(target[key], source[key], locale);\n } else {\n result[key] = processNewContent(source[key], locale);\n }\n }\n }\n\n return result;\n }\n\n // For primitives, just return the source\n return source;\n};\n\n/**\n * Process new content that doesn't exist in target\n * @param content - New content to process\n * @param locale - Optional locale\n * @returns Processed content\n */\nconst processNewContent = (content: any, locale?: LocalesValues): any => {\n // Handle null and undefined\n if (content === null || content === undefined) {\n return content;\n }\n\n // If content is already a translation node, return as-is\n if (\n content &&\n typeof content === 'object' &&\n content.nodeType === NodeType.Translation\n ) {\n return content;\n }\n\n // Handle arrays\n if (Array.isArray(content)) {\n return content.map((item) => processNewContent(item, locale));\n }\n\n // Handle objects\n if (content && typeof content === 'object') {\n const result: any = {};\n\n for (const key in content) {\n if (Object.hasOwn(content, key)) {\n result[key] = processNewContent(content[key], locale);\n }\n }\n return result;\n }\n\n // Handle primitives\n if (locale) {\n // Wrap in translation node with the specific locale\n return {\n nodeType: NodeType.Translation,\n translation: {\n [locale]: content,\n },\n };\n } else {\n // If no locale, just return the content as-is (don't wrap)\n return content;\n }\n};\n\n/**\n * Insert content into a dictionary with deep merge support\n * Handles translation blocks and nested structures\n *\n * @param dictionary - The dictionary to insert content into\n * @param content - The content to insert\n * @param locale - Optional locale to target specific translation\n * @returns Updated dictionary\n *\n * @example\n * // Without locale - deep merge all content\n * insertContentInDictionary(dictionary, { title: 'New Title' })\n *\n * @example\n * // With locale - insert content for specific locale\n * insertContentInDictionary(dictionary, { title: 'このページ' }, 'ja')\n */\nexport const insertContentInDictionary = (\n dictionary: Dictionary,\n content: Dictionary['content'],\n locale?: LocalesValues\n): Dictionary => {\n const mergedContent = deepMergeContent(\n Array.isArray(dictionary.content)\n ? [...dictionary.content]\n : { ...dictionary.content },\n content,\n locale\n );\n\n return {\n ...dictionary,\n content: mergedContent,\n };\n};\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"insertContentInDictionary.mjs","names":[],"sources":["../../../src/deepTransformPlugins/insertContentInDictionary.ts"],"sourcesContent":["import { type Dictionary, type LocalesValues, NodeType } from '@intlayer/types';\n\n// {\n// {\n// title: 'このページ',\n// linkLabel: 'セクションへ移動',\n// collapseButton: { label: '折りたたむ' }\n// },\n// }\n// {\n// dictionary: {\n// key: 'aside-navigation',\n// content: {\n// title: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'في هذه الصفحة',\n// de: 'Auf dieser Seite',\n// en: 'In this page',\n// 'en-GB': 'On this page',\n// es: 'En esta página',\n// fr: 'Dans cette page',\n// hi: 'इस पृष्ठ में',\n// it: 'In questa pagina',\n// ko: '이 페이지에서',\n// pt: 'Nesta página',\n// ru: 'На этой странице',\n// tr: 'Bu sayfada',\n// zh: '在此页面'\n// }\n// },\n// linkLabel: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'اذهب إلى القسم',\n// de: 'Gehe zur Sektion',\n// en: 'Go to section',\n// 'en-GB': 'Go to section',\n// es: 'Ir a la sección',\n// fr: 'Aller à la section',\n// hi: 'सेक्शन पर जाएं',\n// it: 'Vai alla sezione',\n// ja: 'セクションへ行く',\n// ko: '섹션으로 이동',\n// pt: 'Ir para a seção',\n// ru: 'Перейти к разделу',\n// tr: 'Bölüme git',\n// zh: '转到节'\n// }\n// },\n// collapseButton: {\n// label: {\n// nodeType: 'translation',\n// translation: {\n// en: 'Collapse',\n// fr: 'Réduire',\n// es: 'Colapsar',\n// 'en-GB': 'Collapse',\n// de: 'Zuklappen',\n// ja: '折りたたむ',\n// ko: '접기',\n// zh: '折叠',\n// it: 'Comprimi',\n// pt: 'Recolher',\n// hi: 'संकुचित करें',\n// ar: 'اطوي التوسيع',\n// ru: 'Свернуть',\n// tr: 'Daralt'\n// }\n// }\n// }\n// },\n// localId: 'aside-navigation::local::src/components/AsideNavigation/asideNavigation.content.ts',\n// location: 'local',\n// filePath: 'src/components/AsideNavigation/asideNavigation.content.ts'\n// }\n// }\n\n/**\n * Deep merge helper that handles translation blocks\n * @param target - The target object (dictionary content)\n * @param source - The source object (new content to merge)\n * @param locale - Optional locale to target specific translation\n * @returns Merged content\n */\nconst deepMergeContent = (\n target: any,\n source: any,\n locale?: LocalesValues\n): any => {\n // If source is null or undefined, return target\n if (source === null || source === undefined) return target;\n\n // If target is null or undefined, initialize based on source type\n if (target === null || target === undefined) {\n if (Array.isArray(source)) {\n target = [];\n } else if (typeof source === 'object') {\n target = {};\n } else {\n return source;\n }\n }\n\n // Handle translation nodes FIRST (before arrays) to support arrays within translations\n if (\n target &&\n typeof target === 'object' &&\n target.nodeType === NodeType.Translation\n ) {\n // Target is a translation block\n if (locale) {\n // Update only the specific locale - create new object to preserve order\n const existingLocaleContent = target.translation[locale];\n let newLocaleContent: any;\n\n if (typeof source === 'object' && !Array.isArray(source)) {\n // Source is an object, need to deep merge for this locale\n newLocaleContent = deepMergeContent(\n existingLocaleContent,\n source,\n undefined // Don't pass locale down for nested content\n );\n } else if (Array.isArray(source)) {\n // Source is an array, set it directly for this locale\n newLocaleContent = source;\n } else {\n // Source is a primitive, directly set it\n newLocaleContent = source;\n }\n\n // Return new object with locale appended at the end (preserve insertion order)\n return {\n ...target,\n translation: {\n ...target.translation,\n [locale]: newLocaleContent,\n },\n };\n } else {\n // No locale specified, replace/merge the entire translation\n if (\n typeof source === 'object' &&\n !Array.isArray(source) &&\n source.nodeType === NodeType.Translation\n ) {\n // Source is also a translation node, merge translations\n return {\n ...target,\n translation: {\n ...target.translation,\n ...source.translation,\n },\n };\n } else {\n // Source is not a translation node, wrap it\n return processNewContent(source, locale);\n }\n }\n }\n\n // Handle arrays\n if (Array.isArray(source)) {\n if (locale && Array.isArray(target)) {\n // When locale is specified and target is also an array, merge element by element\n const result = [];\n const maxLength = Math.max(source.length, target.length);\n\n for (let i = 0; i < maxLength; i++) {\n if (i < source.length) {\n if (i < target.length && target[i] !== undefined) {\n // Both source and target have element at this index - merge them\n result[i] = deepMergeContent(target[i], source[i], locale);\n } else {\n // Only source has element at this index - process new content\n result[i] = processNewContent(source[i], locale);\n }\n } else {\n // Only target has element at this index - keep it\n result[i] = target[i];\n }\n }\n\n return result;\n } else {\n // No locale or target is not an array - replace entirely\n return source.map((item) => {\n // Process each item in case it needs locale wrapping\n if (\n item &&\n typeof item === 'object' &&\n item.nodeType === NodeType.Translation\n ) {\n return item;\n }\n return processNewContent(item, locale);\n });\n }\n }\n\n // Handle objects\n if (typeof source === 'object' && !Array.isArray(source)) {\n if (typeof target !== 'object' || Array.isArray(target)) {\n target = {};\n }\n\n // Create new object to preserve key order and avoid mutation\n const result: any = { ...target };\n\n for (const key in source) {\n if (Object.hasOwn(source, key)) {\n if (target[key] !== undefined) {\n result[key] = deepMergeContent(target[key], source[key], locale);\n } else {\n result[key] = processNewContent(source[key], locale);\n }\n }\n }\n\n return result;\n }\n\n // For primitives, just return the source\n return source;\n};\n\n/**\n * Process new content that doesn't exist in target\n * @param content - New content to process\n * @param locale - Optional locale\n * @returns Processed content\n */\nconst processNewContent = (content: any, locale?: LocalesValues): any => {\n // Handle null and undefined\n if (content === null || content === undefined) {\n return content;\n }\n\n // If content is already a translation node, return as-is\n if (\n content &&\n typeof content === 'object' &&\n content.nodeType === NodeType.Translation\n ) {\n return content;\n }\n\n // Handle arrays\n if (Array.isArray(content)) {\n return content.map((item) => processNewContent(item, locale));\n }\n\n // Handle objects\n if (content && typeof content === 'object') {\n const result: any = {};\n\n for (const key in content) {\n if (Object.hasOwn(content, key)) {\n result[key] = processNewContent(content[key], locale);\n }\n }\n return result;\n }\n\n // Handle primitives\n if (locale) {\n // Wrap in translation node with the specific locale\n return {\n nodeType: NodeType.Translation,\n translation: {\n [locale]: content,\n },\n };\n } else {\n // If no locale, just return the content as-is (don't wrap)\n return content;\n }\n};\n\n/**\n * Insert content into a dictionary with deep merge support\n * Handles translation blocks and nested structures\n *\n * @param dictionary - The dictionary to insert content into\n * @param content - The content to insert\n * @param locale - Optional locale to target specific translation\n * @returns Updated dictionary\n *\n * @example\n * // Without locale - deep merge all content\n * insertContentInDictionary(dictionary, { title: 'New Title' })\n *\n * @example\n * // With locale - insert content for specific locale\n * insertContentInDictionary(dictionary, { title: 'このページ' }, 'ja')\n */\nexport const insertContentInDictionary = (\n dictionary: Dictionary,\n content: Dictionary['content'],\n locale?: LocalesValues\n): Dictionary => {\n const mergedContent = deepMergeContent(\n Array.isArray(dictionary.content)\n ? [...dictionary.content]\n : { ...dictionary.content },\n content,\n locale\n );\n\n return {\n ...dictionary,\n content: mergedContent,\n };\n};\n"],"mappings":"2CAqFA,MAAM,GACJ,EACA,EACA,IACQ,CAER,GAAI,GAAW,KAA8B,OAAO,EAGpD,GAAI,GAAW,KACb,GAAI,MAAM,QAAQ,EAAO,CACvB,EAAS,EAAE,SACF,OAAO,GAAW,SAC3B,EAAS,EAAE,MAEX,OAAO,EAKX,GACE,GACA,OAAO,GAAW,UAClB,EAAO,WAAa,EAAS,YAG7B,GAAI,EAAQ,CAEV,IAAM,EAAwB,EAAO,YAAY,GAC7C,EAkBJ,MAhBA,CAYE,EAZE,OAAO,GAAW,UAAY,CAAC,MAAM,QAAQ,EAAO,CAEnC,EACjB,EACA,EACA,IAAA,GACD,CAGkB,EAOd,CACL,GAAG,EACH,YAAa,CACX,GAAG,EAAO,aACT,GAAS,EACX,CACF,SAIC,OAAO,GAAW,UAClB,CAAC,MAAM,QAAQ,EAAO,EACtB,EAAO,WAAa,EAAS,YAG7B,MAAO,CACL,GAAG,EACH,YAAa,CACX,GAAG,EAAO,YACV,GAAG,EAAO,YACX,CACF,MAGD,OAAO,EAAkB,EAAQ,EAAO,CAM9C,GAAI,MAAM,QAAQ,EAAO,CACvB,GAAI,GAAU,MAAM,QAAQ,EAAO,CAAE,CAEnC,IAAM,EAAS,EAAE,CACX,EAAY,KAAK,IAAI,EAAO,OAAQ,EAAO,OAAO,CAExD,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,IACzB,EAAI,EAAO,OACT,EAAI,EAAO,QAAU,EAAO,KAAO,IAAA,GAErC,EAAO,GAAK,EAAiB,EAAO,GAAI,EAAO,GAAI,EAAO,CAG1D,EAAO,GAAK,EAAkB,EAAO,GAAI,EAAO,CAIlD,EAAO,GAAK,EAAO,GAIvB,OAAO,OAGP,OAAO,EAAO,IAAK,GAGf,GACA,OAAO,GAAS,UAChB,EAAK,WAAa,EAAS,YAEpB,EAEF,EAAkB,EAAM,EAAO,CACtC,CAKN,GAAI,OAAO,GAAW,UAAY,CAAC,MAAM,QAAQ,EAAO,CAAE,EACpD,OAAO,GAAW,UAAY,MAAM,QAAQ,EAAO,IACrD,EAAS,EAAE,EAIb,IAAM,EAAc,CAAE,GAAG,EAAQ,CAEjC,IAAK,IAAM,KAAO,EACZ,OAAO,OAAO,EAAQ,EAAI,GACxB,EAAO,KAAS,IAAA,GAGlB,EAAO,GAAO,EAAkB,EAAO,GAAM,EAAO,CAFpD,EAAO,GAAO,EAAiB,EAAO,GAAM,EAAO,GAAM,EAAO,EAOtE,OAAO,EAIT,OAAO,GASH,GAAqB,EAAc,IAAgC,CAOvE,GALI,GAAY,MAMd,GACA,OAAO,GAAY,UACnB,EAAQ,WAAa,EAAS,YAE9B,OAAO,EAIT,GAAI,MAAM,QAAQ,EAAQ,CACxB,OAAO,EAAQ,IAAK,GAAS,EAAkB,EAAM,EAAO,CAAC,CAI/D,GAAI,GAAW,OAAO,GAAY,SAAU,CAC1C,IAAM,EAAc,EAAE,CAEtB,IAAK,IAAM,KAAO,EACZ,OAAO,OAAO,EAAS,EAAI,GAC7B,EAAO,GAAO,EAAkB,EAAQ,GAAM,EAAO,EAGzD,OAAO,EAcP,OAVE,EAEK,CACL,SAAU,EAAS,YACnB,YAAa,EACV,GAAS,EACX,CACF,CAGM,GAqBE,GACX,EACA,EACA,IACe,CACf,IAAM,EAAgB,EACpB,MAAM,QAAQ,EAAW,QAAQ,CAC7B,CAAC,GAAG,EAAW,QAAQ,CACvB,CAAE,GAAG,EAAW,QAAS,CAC7B,EACA,EACD,CAED,MAAO,CACL,GAAG,EACH,QAAS,EACV"}
|
|
@@ -1,63 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/dictionaryManipulator/editDictionaryByKeyPath.ts
|
|
4
|
-
const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
|
|
5
|
-
let currentValue = dictionaryContent;
|
|
6
|
-
let parentValue = null;
|
|
7
|
-
let lastKeys = [];
|
|
8
|
-
if (keyPath.length === 0) return newValue;
|
|
9
|
-
try {
|
|
10
|
-
for (let i = 0; i < keyPath.length; i++) {
|
|
11
|
-
const keyObj = keyPath[i];
|
|
12
|
-
parentValue = currentValue;
|
|
13
|
-
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
|
|
14
|
-
lastKeys = [keyObj.key];
|
|
15
|
-
if (!currentValue[keyObj.key] || typeof currentValue[keyObj.key] !== "object") currentValue[keyObj.key] = {};
|
|
16
|
-
currentValue = currentValue[keyObj.key];
|
|
17
|
-
}
|
|
18
|
-
if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Enumeration) {
|
|
19
|
-
lastKeys = [keyObj.type, keyObj.key];
|
|
20
|
-
if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") currentValue[keyObj.type] = {};
|
|
21
|
-
if (!currentValue[keyObj.type][keyObj.key] || typeof currentValue[keyObj.type][keyObj.key] !== "object") currentValue[keyObj.type][keyObj.key] = {};
|
|
22
|
-
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
23
|
-
}
|
|
24
|
-
if (keyObj.type === NodeType.Enumeration || keyObj.type === NodeType.Condition) {
|
|
25
|
-
if (keyObj.type !== NodeType.Enumeration) {
|
|
26
|
-
lastKeys = [keyObj.type, keyObj.key];
|
|
27
|
-
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.HTML || keyObj.type === NodeType.Insertion) {
|
|
31
|
-
lastKeys = [keyObj.type];
|
|
32
|
-
if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") currentValue[keyObj.type] = "";
|
|
33
|
-
currentValue = currentValue[keyObj.type];
|
|
34
|
-
}
|
|
35
|
-
if (keyObj.type === NodeType.File) {
|
|
36
|
-
lastKeys = ["content"];
|
|
37
|
-
currentValue = currentValue.content;
|
|
38
|
-
}
|
|
39
|
-
if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {
|
|
40
|
-
let target = parentValue;
|
|
41
|
-
for (const key of lastKeys.slice(0, -1)) target = target[key];
|
|
42
|
-
const finalKey = lastKeys[lastKeys.length - 1];
|
|
43
|
-
if (typeof newValue === "undefined") if (Array.isArray(target)) {
|
|
44
|
-
const index = Number(finalKey);
|
|
45
|
-
if (!isNaN(index) && index >= 0 && index < target.length) target.splice(index, 1);
|
|
46
|
-
} else delete target[finalKey];
|
|
47
|
-
else target[finalKey] = newValue;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return dictionaryContent;
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.error("Cannot edit dictionary by key path", {
|
|
53
|
-
dictionaryContent,
|
|
54
|
-
keyPath,
|
|
55
|
-
newValue
|
|
56
|
-
}, error);
|
|
57
|
-
return dictionaryContent;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
export { editDictionaryByKeyPath };
|
|
1
|
+
import{NodeType as e}from"@intlayer/types";const t=(t,n,r)=>{let i=t,a=null,o=[];if(n.length===0)return r;try{for(let t=0;t<n.length;t++){let s=n[t];if(a=i,(s.type===e.Object||s.type===e.Array)&&(o=[s.key],(!i[s.key]||typeof i[s.key]!=`object`)&&(i[s.key]={}),i=i[s.key]),(s.type===e.Translation||s.type===e.Enumeration)&&(o=[s.type,s.key],(!i[s.type]||typeof i[s.type]!=`object`)&&(i[s.type]={}),(!i[s.type][s.key]||typeof i[s.type][s.key]!=`object`)&&(i[s.type][s.key]={}),i=i[s.type][s.key]),(s.type===e.Enumeration||s.type===e.Condition)&&s.type!==e.Enumeration&&(o=[s.type,s.key],i=i[s.type][s.key]),(s.type===e.Markdown||s.type===e.HTML||s.type===e.Insertion)&&(o=[s.type],(!i[s.type]||typeof i[s.type]!=`object`)&&(i[s.type]=``),i=i[s.type]),s.type===e.File&&(o=[`content`],i=i.content),t===n.length-1&&a&&o.length>0){let e=a;for(let t of o.slice(0,-1))e=e[t];let t=o[o.length-1];if(r===void 0)if(Array.isArray(e)){let n=Number(t);!isNaN(n)&&n>=0&&n<e.length&&e.splice(n,1)}else delete e[t];else e[t]=r}}return t}catch(e){return console.error(`Cannot edit dictionary by key path`,{dictionaryContent:t,keyPath:n,newValue:r},e),t}};export{t as editDictionaryByKeyPath};
|
|
63
2
|
//# sourceMappingURL=editDictionaryByKeyPath.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editDictionaryByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n // Note: Logic above already handles Enumeration, ensure no duplication in your actual file\n // or keep the specific block if your logic differs.\n // The important part is below in the final update block.\n\n // Assuming this block runs for Condition/Gender/etc:\n if (keyObj.type !== NodeType.Enumeration) {\n lastKeys = [keyObj.type, keyObj.key];\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.HTML ||\n keyObj.type === NodeType.Insertion\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeType.File) {\n lastKeys = ['content'];\n currentValue = currentValue.content;\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n\n // Drill down to the container holding the value to be changed\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n\n const finalKey = lastKeys[lastKeys.length - 1];\n\n if (typeof newValue === 'undefined') {\n // Use splice for arrays to re-index the list, use delete for objects\n if (Array.isArray(target)) {\n const index = Number(finalKey);\n if (!isNaN(index) && index >= 0 && index < target.length) {\n target.splice(index, 1);\n }\n } else {\n delete target[finalKey];\n }\n } else {\n target[finalKey] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"editDictionaryByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n // Note: Logic above already handles Enumeration, ensure no duplication in your actual file\n // or keep the specific block if your logic differs.\n // The important part is below in the final update block.\n\n // Assuming this block runs for Condition/Gender/etc:\n if (keyObj.type !== NodeType.Enumeration) {\n lastKeys = [keyObj.type, keyObj.key];\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.HTML ||\n keyObj.type === NodeType.Insertion\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeType.File) {\n lastKeys = ['content'];\n currentValue = currentValue.content;\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n\n // Drill down to the container holding the value to be changed\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n\n const finalKey = lastKeys[lastKeys.length - 1];\n\n if (typeof newValue === 'undefined') {\n // Use splice for arrays to re-index the list, use delete for objects\n if (Array.isArray(target)) {\n const index = Number(finalKey);\n if (!isNaN(index) && index >= 0 && index < target.length) {\n target.splice(index, 1);\n }\n } else {\n delete target[finalKey];\n }\n } else {\n target[finalKey] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":"2CAIA,MAAa,GACX,EACA,EACA,IACgB,CAChB,IAAI,EAAoB,EACpB,EAAmB,KACnB,EAA0B,EAAE,CAEhC,GAAI,EAAQ,SAAW,EACrB,OAAO,EAGT,GAAI,CACF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAM,EAAS,EAAQ,GAsEvB,GArEA,EAAc,GAEV,EAAO,OAAS,EAAS,QAAU,EAAO,OAAS,EAAS,SAC9D,EAAW,CAAC,EAAO,IAAI,EAErB,CAAC,EAAa,EAAO,MACrB,OAAO,EAAa,EAAO,MAAS,YAEpC,EAAa,EAAO,KAAO,EAAE,EAE/B,EAAe,EAAa,EAAO,OAInC,EAAO,OAAS,EAAS,aACzB,EAAO,OAAS,EAAS,eAEzB,EAAW,CAAC,EAAO,KAAM,EAAO,IAAI,EAElC,CAAC,EAAa,EAAO,OACrB,OAAO,EAAa,EAAO,OAAU,YAErC,EAAa,EAAO,MAAQ,EAAE,GAG9B,CAAC,EAAa,EAAO,MAAM,EAAO,MAClC,OAAO,EAAa,EAAO,MAAM,EAAO,MAAS,YAEjD,EAAa,EAAO,MAAM,EAAO,KAAO,EAAE,EAE5C,EAAe,EAAa,EAAO,MAAM,EAAO,OAIhD,EAAO,OAAS,EAAS,aACzB,EAAO,OAAS,EAAS,YAOrB,EAAO,OAAS,EAAS,cAC3B,EAAW,CAAC,EAAO,KAAM,EAAO,IAAI,CACpC,EAAe,EAAa,EAAO,MAAM,EAAO,OAKlD,EAAO,OAAS,EAAS,UACzB,EAAO,OAAS,EAAS,MACzB,EAAO,OAAS,EAAS,aAEzB,EAAW,CAAC,EAAO,KAAK,EAEtB,CAAC,EAAa,EAAO,OACrB,OAAO,EAAa,EAAO,OAAU,YAErC,EAAa,EAAO,MAAQ,IAE9B,EAAe,EAAa,EAAO,OAGjC,EAAO,OAAS,EAAS,OAC3B,EAAW,CAAC,UAAU,CACtB,EAAe,EAAa,SAI1B,IAAM,EAAQ,OAAS,GAAK,GAAe,EAAS,OAAS,EAAG,CAClE,IAAI,EAAS,EAGb,IAAK,IAAM,KAAO,EAAS,MAAM,EAAG,GAAG,CACrC,EAAS,EAAO,GAGlB,IAAM,EAAW,EAAS,EAAS,OAAS,GAE5C,GAAW,IAAa,OAEtB,GAAI,MAAM,QAAQ,EAAO,CAAE,CACzB,IAAM,EAAQ,OAAO,EAAS,CAC1B,CAAC,MAAM,EAAM,EAAI,GAAS,GAAK,EAAQ,EAAO,QAChD,EAAO,OAAO,EAAO,EAAE,MAGzB,OAAO,EAAO,QAGhB,EAAO,GAAY,GAKzB,OAAO,QACA,EAAO,CAMd,OALA,QAAQ,MACN,qCACA,CAAE,oBAAmB,UAAS,WAAU,CACxC,EACD,CACM"}
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/dictionaryManipulator/getContentNodeByKeyPath.ts
|
|
4
|
-
const getContentNodeByKeyPath = (dictionaryContent, keyPath, fallbackLocale) => {
|
|
5
|
-
let currentValue = structuredClone(dictionaryContent);
|
|
6
|
-
for (const keyObj of keyPath) {
|
|
7
|
-
if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];
|
|
8
|
-
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) currentValue = currentValue?.[keyObj.key];
|
|
9
|
-
if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Condition || keyObj.type === NodeType.Enumeration) currentValue = currentValue?.[keyObj.type]?.[keyObj.key];
|
|
10
|
-
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.HTML || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) currentValue = currentValue?.[keyObj.type];
|
|
11
|
-
}
|
|
12
|
-
return currentValue;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { getContentNodeByKeyPath };
|
|
1
|
+
import{NodeType as e}from"@intlayer/types";const t=(t,n,r)=>{let i=structuredClone(t);for(let t of n)r&&i?.nodeType===e.Translation&&(i=i?.[e.Translation]?.[r]),(t.type===e.Object||t.type===e.Array)&&(i=i?.[t.key]),(t.type===e.Translation||t.type===e.Condition||t.type===e.Enumeration)&&(i=i?.[t.type]?.[t.key]),(t.type===e.Markdown||t.type===e.HTML||t.type===e.Insertion||t.type===e.File)&&(i=i?.[t.type]);return i};export{t as getContentNodeByKeyPath};
|
|
17
2
|
//# sourceMappingURL=getContentNodeByKeyPath.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import {\n type ContentNode,\n type KeyPath,\n type Locale,\n NodeType,\n} from '@intlayer/types';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: Locale\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Condition ||\n keyObj.type === NodeType.Enumeration\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.HTML ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import {\n type ContentNode,\n type KeyPath,\n type Locale,\n NodeType,\n} from '@intlayer/types';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: Locale\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Condition ||\n keyObj.type === NodeType.Enumeration\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.HTML ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":"2CAOA,MAAa,GACX,EACA,EACA,IACgB,CAChB,IAAI,EAAoB,gBAAgB,EAAkB,CAE1D,IAAK,IAAM,KAAU,EAEf,GAAkB,GAAc,WAAa,EAAS,cACxD,EAAe,IAAe,EAAS,eAAe,KAGpD,EAAO,OAAS,EAAS,QAAU,EAAO,OAAS,EAAS,SAC9D,EAAe,IAAe,EAAO,OAIrC,EAAO,OAAS,EAAS,aACzB,EAAO,OAAS,EAAS,WACzB,EAAO,OAAS,EAAS,eAEzB,EAAe,IAAe,EAAO,QAAQ,EAAO,OAIpD,EAAO,OAAS,EAAS,UACzB,EAAO,OAAS,EAAS,MACzB,EAAO,OAAS,EAAS,WACzB,EAAO,OAAS,EAAS,QAEzB,EAAe,IAAe,EAAO,OAIzC,OAAO"}
|