@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilterMissingTranslationsContent.mjs","names":["tCore"],"sources":["../../../src/deepTransformPlugins/getFilterMissingTranslationsContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport { type TranslationContent, t as tCore } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/**\n * Get all keys from an object, recursively\n */\nconst getObjectKeys = (obj: any): Set<string> => {\n const keys = new Set<string>();\n\n if (typeof obj !== 'object' || obj === null) {\n return keys;\n }\n\n for (const key in obj) {\n keys.add(key);\n }\n\n return keys;\n};\n\n/**\n * Check if two objects have the same structure (same keys)\n */\nconst hasSameStructure = (obj1: any, obj2: any): boolean => {\n if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {\n return typeof obj1 === typeof obj2;\n }\n\n if (obj1 === null || obj2 === null) {\n return obj1 === obj2;\n }\n\n if (Array.isArray(obj1) !== Array.isArray(obj2)) {\n return false;\n }\n\n const keys1 = getObjectKeys(obj1);\n const keys2 = getObjectKeys(obj2);\n\n if (keys1.size !== keys2.size) {\n return false;\n }\n\n for (const key of keys1) {\n if (!keys2.has(key)) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Check if all locales in a translation node have the same structure (recursively)\n * Returns an object with locales that have missing keys\n */\nconst checkTranslationStructureConsistency = (\n translationNode: Record<string, any>\n): { hasInconsistency: boolean; localesWithMissingKeys: Set<string> } => {\n const locales = Object.keys(translationNode);\n const localesWithMissingKeys = new Set<string>();\n\n if (locales.length <= 1) {\n return { hasInconsistency: false, localesWithMissingKeys };\n }\n\n // Helper function to check structure recursively\n const checkStructureRecursive = (\n path: string,\n localeValues: Map<string, any>\n ): Set<string> => {\n const localesWithIssues = new Set<string>();\n\n // Get all unique keys across all locale values at this path\n const allKeys = new Set<string>();\n const objectLocales = new Map<string, any>();\n\n for (const [locale, value] of localeValues.entries()) {\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value)\n ) {\n objectLocales.set(locale, value);\n const keys = getObjectKeys(value);\n for (const key of keys) {\n allKeys.add(key);\n }\n }\n }\n\n // If no objects at this level, no inconsistency\n if (objectLocales.size === 0) {\n return localesWithIssues;\n }\n\n // Check if each locale has all the keys at this level\n for (const [locale, value] of objectLocales.entries()) {\n const keys = getObjectKeys(value);\n if (keys.size !== allKeys.size) {\n localesWithIssues.add(locale);\n }\n }\n\n // Recursively check nested objects\n for (const key of allKeys) {\n const nestedValues = new Map<string, any>();\n for (const [locale, value] of objectLocales.entries()) {\n if (value[key] !== undefined) {\n nestedValues.set(locale, value[key]);\n }\n }\n\n if (nestedValues.size > 1) {\n const nestedIssues = checkStructureRecursive(\n path ? `${path}.${key}` : key,\n nestedValues\n );\n for (const locale of nestedIssues) {\n localesWithIssues.add(locale);\n }\n }\n }\n\n return localesWithIssues;\n };\n\n // Start recursive check from root\n const rootValues = new Map<string, any>();\n for (const locale of locales) {\n rootValues.set(locale, translationNode[locale]);\n }\n\n const issuesFound = checkStructureRecursive('', rootValues);\n const hasInconsistency = issuesFound.size > 0;\n\n for (const locale of issuesFound) {\n localesWithMissingKeys.add(locale);\n }\n\n return { hasInconsistency, localesWithMissingKeys };\n};\n\n/**\n * Check if array elements have consistent structures\n */\nconst checkArrayStructureConsistency = (arr: any[]): boolean => {\n if (arr.length <= 1) {\n return true;\n }\n\n const firstElement = arr[0];\n\n for (let i = 1; i < arr.length; i++) {\n if (!hasSameStructure(firstElement, arr[i])) {\n return false;\n }\n }\n\n return true;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterMissingTranslationsOnlyPlugin = (\n localeToCheck: LocalesValues\n): Plugins => ({\n id: 'filter-missing-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n const hasLocaleTranslation = Object.keys(result).includes(localeToCheck);\n\n // Check for structural inconsistencies across locales\n const { hasInconsistency, localesWithMissingKeys } =\n checkTranslationStructureConsistency(result);\n\n // If there's a structural inconsistency and the locale being checked\n // has missing keys, treat it as a missing translation\n const hasStructuralIssue =\n hasInconsistency && localesWithMissingKeys.has(localeToCheck);\n\n if (hasLocaleTranslation && !hasStructuralIssue) {\n return undefined; // Return undefined to remove the node\n }\n\n // Transform nested content\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) =>\n plugin.id !== 'filter-missing-translations-only-plugin'\n ),\n ],\n }\n );\n }\n\n // Return the base locale content as a translation node\n // If base locale is missing, use any available locale as fallback\n const baseLocale = configuration?.internationalization?.defaultLocale;\n const availableLocales = Object.keys(result);\n\n if (availableLocales.length === 0) {\n return undefined; // No translations available\n }\n\n // Try to get the base locale first, then any available locale as fallback\n const fallbackLocale = availableLocales.includes(baseLocale)\n ? baseLocale\n : availableLocales[0];\n\n const fallbackValue = getTranslation(result, baseLocale, fallbackLocale);\n\n // Return the translation node structure with only the fallback locale\n return tCore({ [fallbackLocale]: fallbackValue });\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, include only children that are related to translations\n // - Keep children that contain translation nodes (directly or nested)\n // - Keep arrays (they may mix translated and non-translated values)\n // - Exclude primitive values (string/number/boolean/null/undefined) at object level\n const result: Record<string, any> = {};\n let hasMissingTranslations = false;\n const arrayKeysIncluded: string[] = [];\n const primitiveSiblingsToAppend: any[] = [];\n\n for (const key in node as any) {\n const originalChild = (node as any)[key];\n const childProps = {\n ...props,\n children: originalChild,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n const transformedChild = deepTransformNode(originalChild, childProps);\n\n const isPrimitiveSibling =\n originalChild === null ||\n (typeof originalChild !== 'object' &&\n typeof originalChild !== 'function');\n\n if (isPrimitiveSibling) {\n // Defer primitives; they may be appended to an array sibling later\n if (originalChild !== undefined) {\n primitiveSiblingsToAppend.push(originalChild);\n }\n continue;\n }\n\n const includeChild =\n transformedChild !== undefined &&\n (hasTranslationNodes(originalChild) || Array.isArray(originalChild));\n\n if (includeChild) {\n result[key] = transformedChild;\n hasMissingTranslations = true;\n if (Array.isArray(transformedChild)) {\n arrayKeysIncluded.push(key);\n }\n }\n }\n\n // If any array child is present, append primitive siblings into the first array\n if (\n arrayKeysIncluded.length > 0 &&\n primitiveSiblingsToAppend.length > 0\n ) {\n const targetArrayKey = arrayKeysIncluded[0];\n // Ensure array exists in result (it should, but be defensive)\n if (Array.isArray(result[targetArrayKey])) {\n result[targetArrayKey] = [\n ...result[targetArrayKey],\n ...primitiveSiblingsToAppend,\n ];\n hasMissingTranslations = true;\n }\n }\n\n // Only return the object if it has missing translations-related content\n return hasMissingTranslations ? result : undefined;\n } else if (Array.isArray(node)) {\n // Check if array elements have consistent structures\n const hasConsistentStructure = checkArrayStructureConsistency(node);\n\n // For arrays, only include items that have missing translations\n const result = node\n .map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n })\n .filter((item) => item !== null && item !== undefined);\n\n // If there's structural inconsistency in the array, include it\n // even if it has no missing translations, to flag the issue\n if (!hasConsistentStructure && result.length === 0) {\n // Return a marker to indicate structural inconsistency\n return node; // Return original array to show the issue\n }\n\n // Only return the array if it has items with missing translations\n return result.length > 0 ? result : undefined;\n }\n\n return node; // Return non-translation content as is\n },\n});\n\n/**\n * For each translation node, it compare is both localeToCheck and baseLocale are present.\n *\n * If yes, it should remove the node from the content.\n * If no, it should keep the node\n *\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * locale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\nexport const getFilterMissingTranslationsContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n localeToCheck: L,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n filterMissingTranslationsOnlyPlugin(localeToCheck),\n ...(nodeProps.plugins ?? []),\n ];\n\n const result = deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n // Stringify the result to remove the undefined values\n if (result === undefined) {\n // No missing translations found\n return {} as DeepTransformContent<T>;\n }\n return JSON.parse(JSON.stringify(result));\n};\n\nexport const getFilterMissingTranslationsDictionary = (\n dictionary: Dictionary,\n localeToCheck: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterMissingTranslationsContent(\n dictionary.content,\n localeToCheck,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n ),\n});\n"],"mappings":";;;;;;;;;;AAmBA,MAAM,uBAAuB,SAAuB;AAClD,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;AAGT,KAAI,MAAM,aAAa,SAAS,YAC9B,QAAO;AAGT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,oBAAoB;AAGvC,QAAO,OAAO,OAAO,KAAK,CAAC,KAAK,oBAAoB;;;;;AAMtD,MAAM,iBAAiB,QAA0B;CAC/C,MAAM,uBAAO,IAAI,KAAa;AAE9B,KAAI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B,SAAS,KAC3B,0BAA0B,SAAS,GACnC;IACA,MAAM,iBAAiB,kBAAkB;AAEzC,QAAI,MAAM,QAAQ,OAAO,gBAAgB,EAAE;AACzC,YAAO,kBAAkB,CACvB,GAAG,OAAO,iBACV,GAAG,0BACJ;AACD,8BAAyB;;;AAK7B,UAAO,yBAAyB,SAAS;aAChC,MAAM,QAAQ,KAAK,EAAE;GAE9B,MAAM,yBAAyB,+BAA+B,KAAK;GAGnE,MAAM,SAAS,KACZ,KAAK,OAAO,UAAU;AASrB,WAAO,kBAAkB,OARN;KACjB,GAAG;KACH,UAAU;KACV,SAAS,CACP,GAAG,MAAM,SACT;MAAE,MAAM,SAAS;MAAO,KAAK;MAAO,CACrC;KACF,CAC0C;KAC3C,CACD,QAAQ,SAAS,SAAS,QAAQ,SAAS,OAAU;AAIxD,OAAI,CAAC,0BAA0B,OAAO,WAAW,EAE/C,QAAO;AAIT,UAAO,OAAO,SAAS,IAAI,SAAS;;AAGtC,SAAO;;CAEV;;;;;;;;;;;;;;;AAgBD,MAAa,uCAIX,MACA,eACA,cACG;CACH,MAAM,UAAqB,CACzB,oCAAoC,cAAc,EAClD,GAAI,UAAU,WAAW,EAAE,CAC5B;CAED,MAAM,SAAS,kBAAkB,MAAM;EACrC,GAAG;EACH;EACD,CAAC;AAGF,KAAI,WAAW,OAEb,QAAO,EAAE;AAEX,QAAO,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC;;AAG3C,MAAa,0CACX,YACA,mBACI;CACJ,GAAG;CACH,SAAS,oCACP,WAAW,SACX,eACA;EACE,eAAe,WAAW;EAC1B,SAAS,EAAE;EACX,SAAS,EAAE;EACZ,CACF;CACF"}
|
|
1
|
+
{"version":3,"file":"getFilterMissingTranslationsContent.mjs","names":["tCore"],"sources":["../../../src/deepTransformPlugins/getFilterMissingTranslationsContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport { type TranslationContent, t as tCore } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/**\n * Get all keys from an object, recursively\n */\nconst getObjectKeys = (obj: any): Set<string> => {\n const keys = new Set<string>();\n\n if (typeof obj !== 'object' || obj === null) {\n return keys;\n }\n\n for (const key in obj) {\n keys.add(key);\n }\n\n return keys;\n};\n\n/**\n * Check if two objects have the same structure (same keys)\n */\nconst hasSameStructure = (obj1: any, obj2: any): boolean => {\n if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {\n return typeof obj1 === typeof obj2;\n }\n\n if (obj1 === null || obj2 === null) {\n return obj1 === obj2;\n }\n\n if (Array.isArray(obj1) !== Array.isArray(obj2)) {\n return false;\n }\n\n const keys1 = getObjectKeys(obj1);\n const keys2 = getObjectKeys(obj2);\n\n if (keys1.size !== keys2.size) {\n return false;\n }\n\n for (const key of keys1) {\n if (!keys2.has(key)) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Check if all locales in a translation node have the same structure (recursively)\n * Returns an object with locales that have missing keys\n */\nconst checkTranslationStructureConsistency = (\n translationNode: Record<string, any>\n): { hasInconsistency: boolean; localesWithMissingKeys: Set<string> } => {\n const locales = Object.keys(translationNode);\n const localesWithMissingKeys = new Set<string>();\n\n if (locales.length <= 1) {\n return { hasInconsistency: false, localesWithMissingKeys };\n }\n\n // Helper function to check structure recursively\n const checkStructureRecursive = (\n path: string,\n localeValues: Map<string, any>\n ): Set<string> => {\n const localesWithIssues = new Set<string>();\n\n // Get all unique keys across all locale values at this path\n const allKeys = new Set<string>();\n const objectLocales = new Map<string, any>();\n\n for (const [locale, value] of localeValues.entries()) {\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value)\n ) {\n objectLocales.set(locale, value);\n const keys = getObjectKeys(value);\n for (const key of keys) {\n allKeys.add(key);\n }\n }\n }\n\n // If no objects at this level, no inconsistency\n if (objectLocales.size === 0) {\n return localesWithIssues;\n }\n\n // Check if each locale has all the keys at this level\n for (const [locale, value] of objectLocales.entries()) {\n const keys = getObjectKeys(value);\n if (keys.size !== allKeys.size) {\n localesWithIssues.add(locale);\n }\n }\n\n // Recursively check nested objects\n for (const key of allKeys) {\n const nestedValues = new Map<string, any>();\n for (const [locale, value] of objectLocales.entries()) {\n if (value[key] !== undefined) {\n nestedValues.set(locale, value[key]);\n }\n }\n\n if (nestedValues.size > 1) {\n const nestedIssues = checkStructureRecursive(\n path ? `${path}.${key}` : key,\n nestedValues\n );\n for (const locale of nestedIssues) {\n localesWithIssues.add(locale);\n }\n }\n }\n\n return localesWithIssues;\n };\n\n // Start recursive check from root\n const rootValues = new Map<string, any>();\n for (const locale of locales) {\n rootValues.set(locale, translationNode[locale]);\n }\n\n const issuesFound = checkStructureRecursive('', rootValues);\n const hasInconsistency = issuesFound.size > 0;\n\n for (const locale of issuesFound) {\n localesWithMissingKeys.add(locale);\n }\n\n return { hasInconsistency, localesWithMissingKeys };\n};\n\n/**\n * Check if array elements have consistent structures\n */\nconst checkArrayStructureConsistency = (arr: any[]): boolean => {\n if (arr.length <= 1) {\n return true;\n }\n\n const firstElement = arr[0];\n\n for (let i = 1; i < arr.length; i++) {\n if (!hasSameStructure(firstElement, arr[i])) {\n return false;\n }\n }\n\n return true;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterMissingTranslationsOnlyPlugin = (\n localeToCheck: LocalesValues\n): Plugins => ({\n id: 'filter-missing-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n const hasLocaleTranslation = Object.keys(result).includes(localeToCheck);\n\n // Check for structural inconsistencies across locales\n const { hasInconsistency, localesWithMissingKeys } =\n checkTranslationStructureConsistency(result);\n\n // If there's a structural inconsistency and the locale being checked\n // has missing keys, treat it as a missing translation\n const hasStructuralIssue =\n hasInconsistency && localesWithMissingKeys.has(localeToCheck);\n\n if (hasLocaleTranslation && !hasStructuralIssue) {\n return undefined; // Return undefined to remove the node\n }\n\n // Transform nested content\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) =>\n plugin.id !== 'filter-missing-translations-only-plugin'\n ),\n ],\n }\n );\n }\n\n // Return the base locale content as a translation node\n // If base locale is missing, use any available locale as fallback\n const baseLocale = configuration?.internationalization?.defaultLocale;\n const availableLocales = Object.keys(result);\n\n if (availableLocales.length === 0) {\n return undefined; // No translations available\n }\n\n // Try to get the base locale first, then any available locale as fallback\n const fallbackLocale = availableLocales.includes(baseLocale)\n ? baseLocale\n : availableLocales[0];\n\n const fallbackValue = getTranslation(result, baseLocale, fallbackLocale);\n\n // Return the translation node structure with only the fallback locale\n return tCore({ [fallbackLocale]: fallbackValue });\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, include only children that are related to translations\n // - Keep children that contain translation nodes (directly or nested)\n // - Keep arrays (they may mix translated and non-translated values)\n // - Exclude primitive values (string/number/boolean/null/undefined) at object level\n const result: Record<string, any> = {};\n let hasMissingTranslations = false;\n const arrayKeysIncluded: string[] = [];\n const primitiveSiblingsToAppend: any[] = [];\n\n for (const key in node as any) {\n const originalChild = (node as any)[key];\n const childProps = {\n ...props,\n children: originalChild,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n const transformedChild = deepTransformNode(originalChild, childProps);\n\n const isPrimitiveSibling =\n originalChild === null ||\n (typeof originalChild !== 'object' &&\n typeof originalChild !== 'function');\n\n if (isPrimitiveSibling) {\n // Defer primitives; they may be appended to an array sibling later\n if (originalChild !== undefined) {\n primitiveSiblingsToAppend.push(originalChild);\n }\n continue;\n }\n\n const includeChild =\n transformedChild !== undefined &&\n (hasTranslationNodes(originalChild) || Array.isArray(originalChild));\n\n if (includeChild) {\n result[key] = transformedChild;\n hasMissingTranslations = true;\n if (Array.isArray(transformedChild)) {\n arrayKeysIncluded.push(key);\n }\n }\n }\n\n // If any array child is present, append primitive siblings into the first array\n if (\n arrayKeysIncluded.length > 0 &&\n primitiveSiblingsToAppend.length > 0\n ) {\n const targetArrayKey = arrayKeysIncluded[0];\n // Ensure array exists in result (it should, but be defensive)\n if (Array.isArray(result[targetArrayKey])) {\n result[targetArrayKey] = [\n ...result[targetArrayKey],\n ...primitiveSiblingsToAppend,\n ];\n hasMissingTranslations = true;\n }\n }\n\n // Only return the object if it has missing translations-related content\n return hasMissingTranslations ? result : undefined;\n } else if (Array.isArray(node)) {\n // Check if array elements have consistent structures\n const hasConsistentStructure = checkArrayStructureConsistency(node);\n\n // For arrays, only include items that have missing translations\n const result = node\n .map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n })\n .filter((item) => item !== null && item !== undefined);\n\n // If there's structural inconsistency in the array, include it\n // even if it has no missing translations, to flag the issue\n if (!hasConsistentStructure && result.length === 0) {\n // Return a marker to indicate structural inconsistency\n return node; // Return original array to show the issue\n }\n\n // Only return the array if it has items with missing translations\n return result.length > 0 ? result : undefined;\n }\n\n return node; // Return non-translation content as is\n },\n});\n\n/**\n * For each translation node, it compare is both localeToCheck and baseLocale are present.\n *\n * If yes, it should remove the node from the content.\n * If no, it should keep the node\n *\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * locale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\nexport const getFilterMissingTranslationsContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n localeToCheck: L,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n filterMissingTranslationsOnlyPlugin(localeToCheck),\n ...(nodeProps.plugins ?? []),\n ];\n\n const result = deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n // Stringify the result to remove the undefined values\n if (result === undefined) {\n // No missing translations found\n return {} as DeepTransformContent<T>;\n }\n return JSON.parse(JSON.stringify(result));\n};\n\nexport const getFilterMissingTranslationsDictionary = (\n dictionary: Dictionary,\n localeToCheck: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterMissingTranslationsContent(\n dictionary.content,\n localeToCheck,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n ),\n});\n"],"mappings":"kSAmBA,MAAM,EAAuB,GACvB,OAAO,GAAS,WAAY,EACvB,GAGL,GAAM,WAAa,EAAS,YACvB,GAGL,MAAM,QAAQ,EAAK,CACd,EAAK,KAAK,EAAoB,CAGhC,OAAO,OAAO,EAAK,CAAC,KAAK,EAAoB,CAMhD,EAAiB,GAA0B,CAC/C,IAAM,EAAO,IAAI,IAEjB,GAAI,OAAO,GAAQ,WAAY,EAC7B,OAAO,EAGT,IAAK,IAAM,KAAO,EAChB,EAAK,IAAI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O,IAAK,EAAO,CACrC,CACF,CAC0C,CAC3C,CACD,OAAQ,GAAS,GAAS,KAA2B,CAUxD,MANI,CAAC,GAA0B,EAAO,SAAW,EAExC,EAIF,EAAO,OAAS,EAAI,EAAS,IAAA,GAGtC,OAAO,GAEV,EAgBY,GAIX,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAAoC,EAAc,CAClD,GAAI,EAAU,SAAW,EAAE,CAC5B,CAEK,EAAS,EAAkB,EAAM,CACrC,GAAG,EACH,UACD,CAAC,CAOF,OAJI,IAAW,IAAA,GAEN,EAAE,CAEJ,KAAK,MAAM,KAAK,UAAU,EAAO,CAAC,EAG9B,GACX,EACA,KACI,CACJ,GAAG,EACH,QAAS,EACP,EAAW,QACX,EACA,CACE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACX,QAAS,EAAE,CACZ,CACF,CACF"}
|
|
@@ -1,90 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getTranslation } from "../interpreter/getTranslation.mjs";
|
|
3
|
-
import { NodeType } from "@intlayer/types";
|
|
4
|
-
import configuration from "@intlayer/config/built";
|
|
5
|
-
|
|
6
|
-
//#region src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts
|
|
7
|
-
/**
|
|
8
|
-
* Helper function to check if a node or its children contain translation nodes
|
|
9
|
-
*/
|
|
10
|
-
const hasTranslationNodes = (node) => {
|
|
11
|
-
if (typeof node !== "object" || node === null) return false;
|
|
12
|
-
if (node?.nodeType === NodeType.Translation) return true;
|
|
13
|
-
if (Array.isArray(node)) return node.some(hasTranslationNodes);
|
|
14
|
-
return Object.values(node).some(hasTranslationNodes);
|
|
15
|
-
};
|
|
16
|
-
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
17
|
-
const filterTranslationsOnlyPlugin = (locale, fallback) => ({
|
|
18
|
-
id: "filter-translations-only-plugin",
|
|
19
|
-
canHandle: (node) => {
|
|
20
|
-
return typeof node === "object" && node !== null;
|
|
21
|
-
},
|
|
22
|
-
transform: (node, props, deepTransformNode) => {
|
|
23
|
-
if (typeof node === "object" && node?.nodeType === NodeType.Translation) {
|
|
24
|
-
const result = structuredClone(node[NodeType.Translation]);
|
|
25
|
-
for (const key in result) {
|
|
26
|
-
const childProps = {
|
|
27
|
-
...props,
|
|
28
|
-
children: result[key],
|
|
29
|
-
keyPath: [...props.keyPath, {
|
|
30
|
-
type: NodeType.Translation,
|
|
31
|
-
key
|
|
32
|
-
}]
|
|
33
|
-
};
|
|
34
|
-
result[key] = deepTransformNode(result[key], {
|
|
35
|
-
...childProps,
|
|
36
|
-
plugins: [...(props.plugins ?? []).filter((plugin) => plugin.id !== "filter-translations-only-plugin")]
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return getTranslation(result, locale, fallback);
|
|
40
|
-
} else if (typeof node === "object" && node !== null && !Array.isArray(node) && !node?.nodeType) {
|
|
41
|
-
const result = {};
|
|
42
|
-
for (const key in node) if (hasTranslationNodes(node[key])) {
|
|
43
|
-
const childProps = {
|
|
44
|
-
...props,
|
|
45
|
-
children: node[key],
|
|
46
|
-
keyPath: [...props.keyPath, {
|
|
47
|
-
type: NodeType.Object,
|
|
48
|
-
key
|
|
49
|
-
}]
|
|
50
|
-
};
|
|
51
|
-
result[key] = deepTransformNode(node[key], childProps);
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
} else if (Array.isArray(node)) return node.map((child, index) => {
|
|
55
|
-
return deepTransformNode(child, {
|
|
56
|
-
...props,
|
|
57
|
-
children: child,
|
|
58
|
-
keyPath: [...props.keyPath, {
|
|
59
|
-
type: NodeType.Array,
|
|
60
|
-
key: index
|
|
61
|
-
}]
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
return "to remove from the object";
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
/**
|
|
68
|
-
* Return the content of a node with only the translation plugin.
|
|
69
|
-
*
|
|
70
|
-
* @param node The node to transform.
|
|
71
|
-
* @param locale The locale to use if your transformers need it (e.g. for translations).
|
|
72
|
-
*/
|
|
73
|
-
const getFilterTranslationsOnlyContent = (node, locale = configuration?.internationalization?.defaultLocale, nodeProps, fallback) => {
|
|
74
|
-
const plugins = [filterTranslationsOnlyPlugin(locale, fallback), ...nodeProps.plugins ?? []];
|
|
75
|
-
return deepTransformNode(node, {
|
|
76
|
-
...nodeProps,
|
|
77
|
-
plugins
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
const getFilterTranslationsOnlyDictionary = (dictionary, locale = configuration?.internationalization?.defaultLocale, fallback) => ({
|
|
81
|
-
...dictionary,
|
|
82
|
-
content: getFilterTranslationsOnlyContent(dictionary.content, locale, {
|
|
83
|
-
dictionaryKey: dictionary.key,
|
|
84
|
-
keyPath: []
|
|
85
|
-
}, fallback)
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
//#endregion
|
|
89
|
-
export { filterTranslationsOnlyPlugin, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary };
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{getTranslation as t}from"../interpreter/getTranslation.mjs";import{NodeType as n}from"@intlayer/types";import r from"@intlayer/config/built";const i=e=>typeof e!=`object`||!e?!1:e?.nodeType===n.Translation?!0:Array.isArray(e)?e.some(i):Object.values(e).some(i),a=(e,r)=>({id:`filter-translations-only-plugin`,canHandle:e=>typeof e==`object`&&!!e,transform:(a,o,s)=>{if(typeof a==`object`&&a?.nodeType===n.Translation){let i=structuredClone(a[n.Translation]);for(let e in i){let t={...o,children:i[e],keyPath:[...o.keyPath,{type:n.Translation,key:e}]};i[e]=s(i[e],{...t,plugins:[...(o.plugins??[]).filter(e=>e.id!==`filter-translations-only-plugin`)]})}return t(i,e,r)}else if(typeof a==`object`&&a&&!Array.isArray(a)&&!a?.nodeType){let e={};for(let t in a)if(i(a[t])){let r={...o,children:a[t],keyPath:[...o.keyPath,{type:n.Object,key:t}]};e[t]=s(a[t],r)}return e}else if(Array.isArray(a))return a.map((e,t)=>s(e,{...o,children:e,keyPath:[...o.keyPath,{type:n.Array,key:t}]}));return`to remove from the object`}}),o=(t,n=r?.internationalization?.defaultLocale,i,o)=>{let s=[a(n,o),...i.plugins??[]];return e(t,{...i,plugins:s})},s=(e,t=r?.internationalization?.defaultLocale,n)=>({...e,content:o(e.content,t,{dictionaryKey:e.key,keyPath:[]},n)});export{a as filterTranslationsOnlyPlugin,o as getFilterTranslationsOnlyContent,s as getFilterTranslationsOnlyDictionary};
|
|
90
2
|
//# sourceMappingURL=getFilterTranslationsOnlyContent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilterTranslationsOnlyContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterTranslationsOnlyPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'filter-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'filter-translations-only-plugin'\n ),\n ],\n }\n );\n }\n return getTranslation(result, locale, fallback);\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, filter out properties that don't contain translations\n const result: Record<string, any> = {};\n for (const key in node as any) {\n if (hasTranslationNodes(node[key as unknown as keyof typeof node])) {\n const childProps = {\n ...props,\n children: node[key as unknown as keyof typeof node],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n node[key as unknown as keyof typeof node],\n childProps\n );\n }\n }\n return result;\n } else if (Array.isArray(node)) {\n // For arrays, keep all items but transform them\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n return 'to remove from the object';\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getFilterTranslationsOnlyContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L = configuration?.internationalization?.defaultLocale as L,\n nodeProps: NodeProps,\n fallback?: LocalesValues\n) => {\n const plugins: Plugins[] = [\n filterTranslationsOnlyPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getFilterTranslationsOnlyDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues = configuration?.internationalization\n ?.defaultLocale as LocalesValues,\n fallback?: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterTranslationsOnlyContent(\n dictionary.content,\n locale,\n { dictionaryKey: dictionary.key, keyPath: [] },\n fallback\n ),\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getFilterTranslationsOnlyContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterTranslationsOnlyPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'filter-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'filter-translations-only-plugin'\n ),\n ],\n }\n );\n }\n return getTranslation(result, locale, fallback);\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, filter out properties that don't contain translations\n const result: Record<string, any> = {};\n for (const key in node as any) {\n if (hasTranslationNodes(node[key as unknown as keyof typeof node])) {\n const childProps = {\n ...props,\n children: node[key as unknown as keyof typeof node],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n node[key as unknown as keyof typeof node],\n childProps\n );\n }\n }\n return result;\n } else if (Array.isArray(node)) {\n // For arrays, keep all items but transform them\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n return 'to remove from the object';\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getFilterTranslationsOnlyContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L = configuration?.internationalization?.defaultLocale as L,\n nodeProps: NodeProps,\n fallback?: LocalesValues\n) => {\n const plugins: Plugins[] = [\n filterTranslationsOnlyPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getFilterTranslationsOnlyDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues = configuration?.internationalization\n ?.defaultLocale as LocalesValues,\n fallback?: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterTranslationsOnlyContent(\n dictionary.content,\n locale,\n { diction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KAAM,EAAS,MAAO,IAAK,EAAO,CACrC,CACF,CAC0C,CAC3C,CAGJ,MAAO,6BAEV,EAQY,GAIX,EACA,EAAY,GAAe,sBAAsB,cACjD,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAA6B,EAAQ,EAAS,CAC9C,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAGS,GACX,EACA,EAAwB,GAAe,sBACnC,cACJ,KACI,CACJ,GAAG,EACH,QAAS,EACP,EAAW,QACX,EACA,CAAE,cAAe,EAAW,IAAK,QAAS,EAAE,CAAE,CAC9C,EACD,CACF"}
|
|
@@ -1,43 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { NodeType } from "@intlayer/types";
|
|
3
|
-
|
|
4
|
-
//#region src/deepTransformPlugins/getFilteredLocalesContent.ts
|
|
5
|
-
const filterTranslationsPlugin = (locales) => ({
|
|
6
|
-
id: "filter-translations-plugin",
|
|
7
|
-
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
|
|
8
|
-
transform: (node, props, deepTransformNode) => {
|
|
9
|
-
const translationMap = node.translation;
|
|
10
|
-
const filteredTranslationMap = Object.fromEntries(Object.entries(translationMap).filter(([key]) => locales.includes(key)));
|
|
11
|
-
return {
|
|
12
|
-
...node,
|
|
13
|
-
translation: deepTransformNode(filteredTranslationMap, {
|
|
14
|
-
...props,
|
|
15
|
-
keyPath: [...props.keyPath, {
|
|
16
|
-
type: NodeType.Object,
|
|
17
|
-
key: NodeType.Translation
|
|
18
|
-
}]
|
|
19
|
-
})
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const getFilteredLocalesContent = (node, locales, nodeProps) => {
|
|
24
|
-
const plugins = [filterTranslationsPlugin(Array.isArray(locales) ? locales : [locales]), ...nodeProps.plugins ?? []];
|
|
25
|
-
return deepTransformNode(node, {
|
|
26
|
-
...nodeProps,
|
|
27
|
-
plugins
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
const getFilteredLocalesDictionary = (dictionary, locale) => {
|
|
31
|
-
const localesArray = Array.isArray(locale) ? locale : [locale];
|
|
32
|
-
return {
|
|
33
|
-
...dictionary,
|
|
34
|
-
content: getFilteredLocalesContent(dictionary.content, localesArray, {
|
|
35
|
-
dictionaryKey: dictionary.key,
|
|
36
|
-
keyPath: []
|
|
37
|
-
})
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
export { getFilteredLocalesContent, getFilteredLocalesDictionary };
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{NodeType as t}from"@intlayer/types";const n=e=>({id:`filter-translations-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===t.Translation,transform:(n,r,i)=>{let a=n.translation,o=Object.fromEntries(Object.entries(a).filter(([t])=>e.includes(t)));return{...n,translation:i(o,{...r,keyPath:[...r.keyPath,{type:t.Object,key:t.Translation}]})}}}),r=(t,r,i)=>{let a=[n(Array.isArray(r)?r:[r]),...i.plugins??[]];return e(t,{...i,plugins:a})},i=(e,t)=>{let n=Array.isArray(t)?t:[t];return{...e,content:r(e.content,n,{dictionaryKey:e.key,keyPath:[]})}};export{r as getFilteredLocalesContent,i as getFilteredLocalesDictionary};
|
|
43
2
|
//# sourceMappingURL=getFilteredLocalesContent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilteredLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type Dictionary,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst filterTranslationsPlugin = (locales: LocalesValues[]): Plugins => ({\n id: 'filter-translations-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node, props, deepTransformNode) => {\n const translationMap = node.translation as Record<LocalesValues, string>;\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as LocalesValues)\n )\n );\n\n return {\n ...node,\n translation: deepTransformNode(filteredTranslationMap, {\n ...props,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key: NodeType.Translation },\n ],\n }),\n };\n },\n});\n\nexport const getFilteredLocalesContent = (\n node: ContentNode,\n locales: LocalesValues | LocalesValues[],\n nodeProps: NodeProps\n) => {\n const localesArray = Array.isArray(locales) ? locales : [locales];\n\n const plugins: Plugins[] = [\n filterTranslationsPlugin(localesArray),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n });\n};\n\n/*\n * Remove all unneeded translation from translation node\n *\n * locale: fr\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ fr: 'Bonjour' })\n *\n * locales: [fr, en]\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ en: 'Hello', fr: 'Bonjour' })\n */\nexport const getFilteredLocalesDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues | LocalesValues[]\n) => {\n const localesArray = Array.isArray(locale) ? locale : [locale];\n\n return {\n ...dictionary,\n content: getFilteredLocalesContent(dictionary.content, localesArray, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n }),\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getFilteredLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type Dictionary,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst filterTranslationsPlugin = (locales: LocalesValues[]): Plugins => ({\n id: 'filter-translations-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node, props, deepTransformNode) => {\n const translationMap = node.translation as Record<LocalesValues, string>;\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as LocalesValues)\n )\n );\n\n return {\n ...node,\n translation: deepTransformNode(filteredTranslationMap, {\n ...props,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key: NodeType.Translation },\n ],\n }),\n };\n },\n});\n\nexport const getFilteredLocalesContent = (\n node: ContentNode,\n locales: LocalesValues | LocalesValues[],\n nodeProps: NodeProps\n) => {\n const localesArray = Array.isArray(locales) ? locales : [locales];\n\n const plugins: Plugins[] = [\n filterTranslationsPlugin(localesArray),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n });\n};\n\n/*\n * Remove all unneeded translation from translation node\n *\n * locale: fr\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ fr: 'Bonjour' })\n *\n * locales: [fr, en]\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ en: 'Hello', fr: 'Bonjour' })\n */\nexport const getFilteredLocalesDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues | LocalesValues[]\n) => {\n const localesArray = Array.isArray(locale) ? locale : [locale];\n\n return {\n ...dictionary,\n content: getFilteredLocalesContent(dictionary.content, localesArray, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n }),\n };\n};\n"],"mappings":"2HAYA,MAAM,EAA4B,IAAuC,CACvE,GAAI,6BACJ,UAAY,GACV,OAAO,GAAS,UAAY,GAAM,WAAa,EAAS,YAC1D,WAAY,EAAM,EAAO,IAAsB,CAC7C,IAAM,EAAiB,EAAK,YAEtB,EAAyB,OAAO,YACpC,OAAO,QAAQ,EAAe,CAAC,QAAQ,CAAC,KACtC,EAAQ,SAAS,EAAqB,CACvC,CACF,CAED,MAAO,CACL,GAAG,EACH,YAAa,EAAkB,EAAwB,CACrD,GAAG,EACH,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,OAAQ,IAAK,EAAS,YAAa,CACrD,CACF,CAAC,CACH,EAEJ,EAEY,GACX,EACA,EACA,IACG,CAGH,IAAM,EAAqB,CACzB,EAHmB,MAAM,QAAQ,EAAQ,CAAG,EAAU,CAAC,EAAQ,CAGzB,CACtC,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAYS,GACX,EACA,IACG,CACH,IAAM,EAAe,MAAM,QAAQ,EAAO,CAAG,EAAS,CAAC,EAAO,CAE9D,MAAO,CACL,GAAG,EACH,QAAS,EAA0B,EAAW,QAAS,EAAc,CACnE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACZ,CAAC,CACH"}
|
|
@@ -1,32 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { translationPlugin } from "../interpreter/getContent/plugins.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/deepTransformPlugins/getLocalizedContent.ts
|
|
5
|
-
/**
|
|
6
|
-
* Transforms a node in a single pass, applying each plugin as needed.
|
|
7
|
-
* In comparison to `getContent`, this function will only apply the translation plugin.
|
|
8
|
-
* It will not transform enumerations, insertions, or other content types.
|
|
9
|
-
*
|
|
10
|
-
* @param node The node to transform.
|
|
11
|
-
* @param locale The locale to use if your transformers need it (e.g. for translations).
|
|
12
|
-
*/
|
|
13
|
-
const getLocalizedContent = (node, locale, nodeProps, fallback) => {
|
|
14
|
-
const plugins = [translationPlugin(locale, fallback), ...nodeProps.plugins ?? []];
|
|
15
|
-
return deepTransformNode(node, {
|
|
16
|
-
...nodeProps,
|
|
17
|
-
plugins
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
const getPerLocaleDictionary = (dictionary, locale, fallback) => ({
|
|
21
|
-
...dictionary,
|
|
22
|
-
locale,
|
|
23
|
-
content: getLocalizedContent(dictionary.content, locale, {
|
|
24
|
-
dictionaryKey: dictionary.key,
|
|
25
|
-
keyPath: [],
|
|
26
|
-
plugins: []
|
|
27
|
-
}, fallback)
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
export { getLocalizedContent, getPerLocaleDictionary };
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{translationPlugin as t}from"../interpreter/getContent/plugins.mjs";const n=(n,r,i,a)=>{let o=[t(r,a),...i.plugins??[]];return e(n,{...i,plugins:o})},r=(e,t,r)=>({...e,locale:t,content:n(e.content,t,{dictionaryKey:e.key,keyPath:[],plugins:[]},r)});export{n as getLocalizedContent,r as getPerLocaleDictionary};
|
|
32
2
|
//# sourceMappingURL=getLocalizedContent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocalizedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getLocalizedContent.ts"],"sourcesContent":["import type {\n ContentNode,\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n translationPlugin,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n * In comparison to `getContent`, this function will only apply the translation plugin.\n * It will not transform enumerations, insertions, or other content types.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getLocalizedContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L,\n nodeProps: NodeProps,\n fallback?: LocalesValues // fallback mean that if field is not translated, it will use the default locale\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getPerLocaleDictionary = <\n T extends Dictionary,\n L extends LocalesValues,\n>(\n dictionary: T,\n locale: L,\n fallback?: LocalesValues\n): Dictionary => ({\n ...dictionary,\n locale,\n content: getLocalizedContent(\n dictionary.content,\n locale,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n },\n fallback\n ),\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getLocalizedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getLocalizedContent.ts"],"sourcesContent":["import type {\n ContentNode,\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n translationPlugin,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n * In comparison to `getContent`, this function will only apply the translation plugin.\n * It will not transform enumerations, insertions, or other content types.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getLocalizedContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L,\n nodeProps: NodeProps,\n fallback?: LocalesValues // fallback mean that if field is not translated, it will use the default locale\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getPerLocaleDictionary = <\n T extends Dictionary,\n L extends LocalesValues,\n>(\n dictionary: T,\n locale: L,\n fallback?: LocalesValues\n): Dictionary => ({\n ...dictionary,\n locale,\n content: getLocalizedContent(\n dictionary.content,\n locale,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n },\n fallback\n ),\n});\n"],"mappings":"0JAsBA,MAAa,GAIX,EACA,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAAkB,EAAQ,EAAS,CACnC,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAGS,GAIX,EACA,EACA,KACgB,CAChB,GAAG,EACH,SACA,QAAS,EACP,EAAW,QACX,EACA,CACE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACX,QAAS,EAAE,CACZ,CACD,EACD,CACF"}
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/deepTransformPlugins/getMaskContent.ts
|
|
4
|
-
const passTypedNodePlugin = {
|
|
5
|
-
id: "pass-typed-node-plugin",
|
|
6
|
-
canHandle: (node) => typeof node === "object" && typeof node?.nodeType === "string",
|
|
7
|
-
transform: (node, props, deepTransformNode) => deepTransformNode(node[node.nodeType], props)
|
|
8
|
-
};
|
|
9
|
-
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
10
|
-
const buildMaskPlugin = {
|
|
11
|
-
id: "build-mask-plugin",
|
|
12
|
-
canHandle: (node) => typeof node === "string" || typeof node === "number",
|
|
13
|
-
transform: () => true
|
|
14
|
-
};
|
|
15
|
-
const getMaskContent = (source) => ({
|
|
16
|
-
...source,
|
|
17
|
-
content: deepTransformNode(source.content, {
|
|
18
|
-
dictionaryKey: source.key,
|
|
19
|
-
keyPath: [],
|
|
20
|
-
plugins: [passTypedNodePlugin, buildMaskPlugin]
|
|
21
|
-
})
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { buildMaskPlugin, getMaskContent };
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";const t={id:`pass-typed-node-plugin`,canHandle:e=>typeof e==`object`&&typeof e?.nodeType==`string`,transform:(e,t,n)=>n(e[e.nodeType],t)},n={id:`build-mask-plugin`,canHandle:e=>typeof e==`string`||typeof e==`number`,transform:()=>!0},r=r=>({...r,content:e(r.content,{dictionaryKey:r.key,keyPath:[],plugins:[t,n]})});export{n as buildMaskPlugin,r as getMaskContent};
|
|
26
2
|
//# sourceMappingURL=getMaskContent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMaskContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMaskContent.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\nimport { deepTransformNode, type Plugins } from '../interpreter';\n\nconst passTypedNodePlugin: Plugins = {\n id: 'pass-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node, props, deepTransformNode) =>\n deepTransformNode(node[node.nodeType], props),\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const buildMaskPlugin: Plugins = {\n id: 'build-mask-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: () => true,\n};\n\nexport const getMaskContent = (source: Dictionary): any => ({\n ...source,\n content: deepTransformNode(source.content, {\n dictionaryKey: source.key,\n keyPath: [],\n plugins: [passTypedNodePlugin, buildMaskPlugin],\n }),\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMaskContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMaskContent.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\nimport { deepTransformNode, type Plugins } from '../interpreter';\n\nconst passTypedNodePlugin: Plugins = {\n id: 'pass-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node, props, deepTransformNode) =>\n deepTransformNode(node[node.nodeType], props),\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const buildMaskPlugin: Plugins = {\n id: 'build-mask-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: () => true,\n};\n\nexport const getMaskContent = (source: Dictionary): any => ({\n ...source,\n content: deepTransformNode(source.content, {\n dictionaryKey: source.key,\n keyPath: [],\n plugins: [passTypedNodePlugin, buildMaskPlugin],\n }),\n});\n"],"mappings":"gFAGA,MAAM,EAA+B,CACnC,GAAI,yBACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAO,GAAM,UAAa,SACxD,WAAY,EAAM,EAAO,IACvB,EAAkB,EAAK,EAAK,UAAW,EAAM,CAChD,CAGY,EAA2B,CACtC,GAAI,oBACJ,UAAY,GAAS,OAAO,GAAS,UAAY,OAAO,GAAS,SACjE,cAAiB,GAClB,CAEY,EAAkB,IAA6B,CAC1D,GAAG,EACH,QAAS,EAAkB,EAAO,QAAS,CACzC,cAAe,EAAO,IACtB,QAAS,EAAE,CACX,QAAS,CAAC,EAAqB,EAAgB,CAChD,CAAC,CACH"}
|
|
@@ -1,78 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { NodeType } from "@intlayer/types";
|
|
3
|
-
import configuration from "@intlayer/config/built";
|
|
4
|
-
|
|
5
|
-
//#region src/deepTransformPlugins/getMissingLocalesContent.ts
|
|
6
|
-
const getDeepKeyPaths = (obj, prefix = []) => {
|
|
7
|
-
if (typeof obj !== "object" || obj === null) return [];
|
|
8
|
-
if (Array.isArray(obj)) return [];
|
|
9
|
-
return Object.keys(obj).flatMap((key) => {
|
|
10
|
-
const newPath = [...prefix, key];
|
|
11
|
-
return [newPath, ...getDeepKeyPaths(obj[key], newPath)];
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
const hasDeepKeyPath = (obj, keyPath) => {
|
|
15
|
-
let current = obj;
|
|
16
|
-
for (const key of keyPath) {
|
|
17
|
-
if (current === void 0 || current === null || typeof current !== "object") return false;
|
|
18
|
-
if (!(key in current)) return false;
|
|
19
|
-
current = current[key];
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
};
|
|
23
|
-
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
24
|
-
const checkMissingLocalesPlugin = (locales, onMissingLocale) => ({
|
|
25
|
-
id: "check-missing-locales-plugin",
|
|
26
|
-
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
|
|
27
|
-
transform: (node, props, deepTransformNode) => {
|
|
28
|
-
const translations = node[NodeType.Translation];
|
|
29
|
-
const allKeys = /* @__PURE__ */ new Set();
|
|
30
|
-
for (const locale of locales) if (translations[locale]) getDeepKeyPaths(translations[locale]).forEach((path) => {
|
|
31
|
-
allKeys.add(JSON.stringify(path));
|
|
32
|
-
});
|
|
33
|
-
for (const locale of locales) {
|
|
34
|
-
if (!translations[locale]) {
|
|
35
|
-
onMissingLocale(locale);
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
for (const pathStr of allKeys) {
|
|
39
|
-
const path = JSON.parse(pathStr);
|
|
40
|
-
if (!hasDeepKeyPath(translations[locale], path)) {
|
|
41
|
-
onMissingLocale(locale);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
for (const key in translations) {
|
|
47
|
-
const child = translations[key];
|
|
48
|
-
deepTransformNode(child, {
|
|
49
|
-
...props,
|
|
50
|
-
children: child
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return node;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
/**
|
|
57
|
-
* Return the content of a node with only the translation plugin.
|
|
58
|
-
*
|
|
59
|
-
* @param node The node to transform.
|
|
60
|
-
* @param locales The locales to check for missing translations.
|
|
61
|
-
*/
|
|
62
|
-
const getMissingLocalesContent = (node, locales = configuration?.internationalization?.locales, nodeProps) => {
|
|
63
|
-
const missingLocales = /* @__PURE__ */ new Set();
|
|
64
|
-
const plugins = [checkMissingLocalesPlugin(locales, (locale) => missingLocales.add(locale)), ...nodeProps.plugins ?? []];
|
|
65
|
-
deepTransformNode(node, {
|
|
66
|
-
...nodeProps,
|
|
67
|
-
plugins
|
|
68
|
-
});
|
|
69
|
-
return Array.from(missingLocales);
|
|
70
|
-
};
|
|
71
|
-
const getMissingLocalesContentFromDictionary = (dictionary, locales = configuration?.internationalization?.locales) => getMissingLocalesContent(dictionary.content, locales, {
|
|
72
|
-
dictionaryKey: dictionary.key,
|
|
73
|
-
keyPath: []
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
//#endregion
|
|
77
|
-
export { checkMissingLocalesPlugin, getMissingLocalesContent, getMissingLocalesContentFromDictionary };
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{NodeType as t}from"@intlayer/types";import n from"@intlayer/config/built";const r=(e,t=[])=>typeof e!=`object`||!e||Array.isArray(e)?[]:Object.keys(e).flatMap(n=>{let i=[...t,n];return[i,...r(e[n],i)]}),i=(e,t)=>{let n=e;for(let e of t){if(typeof n!=`object`||!n||!(e in n))return!1;n=n[e]}return!0},a=(e,n)=>({id:`check-missing-locales-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===t.Translation,transform:(a,o,s)=>{let c=a[t.Translation],l=new Set;for(let t of e)c[t]&&r(c[t]).forEach(e=>{l.add(JSON.stringify(e))});for(let t of e){if(!c[t]){n(t);continue}for(let e of l){let r=JSON.parse(e);if(!i(c[t],r)){n(t);break}}}for(let e in c){let t=c[e];s(t,{...o,children:t})}return a}}),o=(t,r=n?.internationalization?.locales,i)=>{let o=new Set,s=[a(r,e=>o.add(e)),...i.plugins??[]];return e(t,{...i,plugins:s}),Array.from(o)},s=(e,t=n?.internationalization?.locales)=>o(e.content,t,{dictionaryKey:e.key,keyPath:[]});export{a as checkMissingLocalesPlugin,o as getMissingLocalesContent,s as getMissingLocalesContentFromDictionary};
|
|
78
2
|
//# sourceMappingURL=getMissingLocalesContent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMissingLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n type ContentNode,\n type Locale,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport type { DeepTransformContent, NodeProps, Plugins } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\nconst getDeepKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null) {\n return [];\n }\n\n // Skip array indices - arrays of different lengths shouldn't trigger missing translations\n // Each locale can have arrays with different numbers of elements (e.g., keywords)\n if (Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n return [newPath, ...getDeepKeyPaths(obj[key], newPath)];\n });\n};\n\nconst hasDeepKeyPath = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n\n return true;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locale[],\n onMissingLocale: (locale: Locale) => void\n): Plugins => ({\n id: 'check-missing-locales-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const translations = node[NodeType.Translation] as Record<string, any>;\n const allKeys = new Set<string>();\n\n for (const locale of locales) {\n if (translations[locale]) {\n getDeepKeyPaths(translations[locale]).forEach((path) => {\n allKeys.add(JSON.stringify(path));\n });\n }\n }\n\n for (const locale of locales) {\n if (!translations[locale]) {\n onMissingLocale(locale);\n continue;\n }\n\n for (const pathStr of allKeys) {\n const path = JSON.parse(pathStr);\n if (!hasDeepKeyPath(translations[locale], path)) {\n onMissingLocale(locale);\n break;\n }\n }\n }\n\n // Continue traversal inside the translation values, but avoid re-applying this plugin on the same node\n for (const key in translations) {\n const child = translations[key];\n deepTransformNode(child, {\n ...props,\n children: child,\n });\n }\n\n // Return the original node; the return value is ignored by the caller\n return node;\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locales The locales to check for missing translations.\n */\nexport const getMissingLocalesContent = <T extends ContentNode>(\n node: T,\n locales: LocalesValues[] = configuration?.internationalization?.locales,\n nodeProps: NodeProps\n): Locale[] => {\n const missingLocales = new Set<Locale>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locale[], (locale) =>\n missingLocales.add(locale)\n ),\n ...(nodeProps.plugins ?? []),\n ];\n\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n return Array.from(missingLocales);\n};\n\nexport const getMissingLocalesContentFromDictionary = (\n dictionary: Dictionary,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n) =>\n getMissingLocalesContent(dictionary.content, locales, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMissingLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n type ContentNode,\n type Locale,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport type { DeepTransformContent, NodeProps, Plugins } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\nconst getDeepKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null) {\n return [];\n }\n\n // Skip array indices - arrays of different lengths shouldn't trigger missing translations\n // Each locale can have arrays with different numbers of elements (e.g., keywords)\n if (Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n return [newPath, ...getDeepKeyPaths(obj[key], newPath)];\n });\n};\n\nconst hasDeepKeyPath = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n\n return true;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locale[],\n onMissingLocale: (locale: Locale) => void\n): Plugins => ({\n id: 'check-missing-locales-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const translations = node[NodeType.Translation] as Record<string, any>;\n const allKeys = new Set<string>();\n\n for (const locale of locales) {\n if (translations[locale]) {\n getDeepKeyPaths(translations[locale]).forEach((path) => {\n allKeys.add(JSON.stringify(path));\n });\n }\n }\n\n for (const locale of locales) {\n if (!translations[locale]) {\n onMissingLocale(locale);\n continue;\n }\n\n for (const pathStr of allKeys) {\n const path = JSON.parse(pathStr);\n if (!hasDeepKeyPath(translations[locale], path)) {\n onMissingLocale(locale);\n break;\n }\n }\n }\n\n // Continue traversal inside the translation values, but avoid re-applying this plugin on the same node\n for (const key in translations) {\n const child = translations[key];\n deepTransformNode(child, {\n ...props,\n children: child,\n });\n }\n\n // Return the original node; the return value is ignored by the caller\n return node;\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locales The locales to check for missing translations.\n */\nexport const getMissingLocalesContent = <T extends ContentNode>(\n node: T,\n locales: LocalesValues[] = configuration?.internationalization?.locales,\n nodeProps: NodeProps\n): Locale[] => {\n const missingLocales = new Set<Locale>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locale[], (locale) =>\n missingLocales.add(locale)\n ),\n ...(nodeProps.plugins ?? []),\n ];\n\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n return Array.from(missingLocales);\n};\n\nexport const getMissingLocalesContentFromDictionary = (\n dictionary: Dictionary,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n) =>\n getMissingLocalesContent(dictionary.content, locales, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":"iKAYA,MAAM,GAAmB,EAAU,EAAmB,EAAE,GAClD,OAAO,GAAQ,WAAY,GAM3B,MAAM,QAAQ,EAAI,CACb,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e,EAGtB,GACX,EACA,EAA2B,GAAe,sBAAsB,UAEhE,EAAyB,EAAW,QAAS,EAAS,CACpD,cAAe,EAAW,IAC1B,QAAS,EAAE,CACZ,CAAC"}
|
|
@@ -1,87 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t as translation } from "../transpiler/translation/translation.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/deepTransformPlugins/getMultilingualDictionary.ts
|
|
5
|
-
/**
|
|
6
|
-
* Transform a per-locale dictionary into a multilingual dictionary.
|
|
7
|
-
*
|
|
8
|
-
* Example:
|
|
9
|
-
* ```json
|
|
10
|
-
* {
|
|
11
|
-
* "key": "about-page",
|
|
12
|
-
* "locale": "en",
|
|
13
|
-
* "content": {
|
|
14
|
-
* "myContent": "English content"
|
|
15
|
-
* }
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* ```json
|
|
20
|
-
* {
|
|
21
|
-
* "key": "about-page",
|
|
22
|
-
* "content": {
|
|
23
|
-
* "myContent": t({
|
|
24
|
-
* "en": "English content",
|
|
25
|
-
* })
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const getMultilingualDictionary = (dictionary) => {
|
|
31
|
-
if (!dictionary.locale) return dictionary;
|
|
32
|
-
const locale = dictionary.locale;
|
|
33
|
-
const transformedContent = deepTransformNode(JSON.parse(JSON.stringify(dictionary.content)), {
|
|
34
|
-
dictionaryKey: dictionary.key,
|
|
35
|
-
keyPath: [],
|
|
36
|
-
plugins: [{
|
|
37
|
-
id: "traverse-typed-node-plugin",
|
|
38
|
-
canHandle: (node) => typeof node === "object" && typeof node?.nodeType === "string",
|
|
39
|
-
transform: (node, props, transformFn) => {
|
|
40
|
-
const nodeType = node.nodeType;
|
|
41
|
-
const inner = structuredClone(node[nodeType]);
|
|
42
|
-
if (typeof inner !== "object" || inner === null) {
|
|
43
|
-
const transformed = transformFn(inner, {
|
|
44
|
-
...props,
|
|
45
|
-
children: inner,
|
|
46
|
-
keyPath: [...props.keyPath, {
|
|
47
|
-
type: nodeType,
|
|
48
|
-
key: nodeType
|
|
49
|
-
}]
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
...node,
|
|
53
|
-
[nodeType]: transformed
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
for (const key in inner) {
|
|
57
|
-
const childProps = {
|
|
58
|
-
...props,
|
|
59
|
-
children: inner[key],
|
|
60
|
-
keyPath: [...props.keyPath, {
|
|
61
|
-
type: nodeType,
|
|
62
|
-
key
|
|
63
|
-
}]
|
|
64
|
-
};
|
|
65
|
-
inner[key] = transformFn(inner[key], childProps);
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
...node,
|
|
69
|
-
[nodeType]: inner
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}, {
|
|
73
|
-
id: "wrap-primitive-in-translation",
|
|
74
|
-
canHandle: (node) => typeof node === "string" || typeof node === "number" || typeof node === "boolean",
|
|
75
|
-
transform: (node) => translation({ [locale]: node })
|
|
76
|
-
}]
|
|
77
|
-
});
|
|
78
|
-
const { locale: _omitLocale, ...rest } = dictionary;
|
|
79
|
-
return {
|
|
80
|
-
...rest,
|
|
81
|
-
content: transformedContent
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
//#endregion
|
|
86
|
-
export { getMultilingualDictionary };
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{t}from"../transpiler/translation/translation.mjs";const n=n=>{if(!n.locale)return n;let r=n.locale,i=e(JSON.parse(JSON.stringify(n.content)),{dictionaryKey:n.key,keyPath:[],plugins:[{id:`traverse-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}}},{id:`wrap-primitive-in-translation`,canHandle:e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`,transform:e=>t({[r]:e})}]}),{locale:a,...o}=n;return{...o,content:i}};export{n as getMultilingualDictionary};
|
|
87
2
|
//# sourceMappingURL=getMultilingualDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMultilingualDictionary.mjs","names":["t"],"sources":["../../../src/deepTransformPlugins/getMultilingualDictionary.ts"],"sourcesContent":["import type { Dictionary, KeyPath, NodeType, TypedNode } from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { t } from '../transpiler';\n\n/**\n * Transform a per-locale dictionary into a multilingual dictionary.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"locale\": \"en\",\n * \"content\": {\n * \"myContent\": \"English content\"\n * }\n * }\n * ```\n *\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"content\": {\n * \"myContent\": t({\n * \"en\": \"English content\",\n * })\n * }\n * }\n * ```\n */\nexport const getMultilingualDictionary = (\n dictionary: Dictionary\n): Dictionary => {\n if (!dictionary.locale) {\n return dictionary;\n }\n\n const locale = dictionary.locale;\n\n const wrapPrimitiveInTranslationPlugin: Plugins = {\n id: 'wrap-primitive-in-translation',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: (node) => t({ [locale]: node } as Record<string, unknown>),\n };\n\n const traverseTypedNodePlugin: Plugins = {\n id: 'traverse-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof (node as any)?.nodeType === 'string',\n transform: (node: TypedNode, props, transformFn) => {\n const nodeType = (node as any).nodeType as NodeType;\n const inner = structuredClone(\n (node as any)[nodeType as unknown as keyof TypedNode] as any\n );\n\n if (typeof inner !== 'object' || inner === null) {\n const transformed = transformFn(inner, {\n ...props,\n children: inner,\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]: transformed,\n };\n }\n\n for (const key in inner) {\n const childProps: NodeProps = {\n ...props,\n children: inner[key as unknown as keyof typeof inner],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n inner[key as unknown as keyof typeof inner] = transformFn(\n inner[key as unknown as keyof typeof inner],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: inner };\n },\n };\n\n const transformedContent = deepTransformNode(\n JSON.parse(JSON.stringify(dictionary.content)),\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [traverseTypedNodePlugin, wrapPrimitiveInTranslationPlugin],\n }\n );\n\n const { locale: _omitLocale, ...rest } = dictionary as any;\n return {\n ...rest,\n content: transformedContent,\n } as Dictionary;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMultilingualDictionary.mjs","names":["t"],"sources":["../../../src/deepTransformPlugins/getMultilingualDictionary.ts"],"sourcesContent":["import type { Dictionary, KeyPath, NodeType, TypedNode } from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { t } from '../transpiler';\n\n/**\n * Transform a per-locale dictionary into a multilingual dictionary.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"locale\": \"en\",\n * \"content\": {\n * \"myContent\": \"English content\"\n * }\n * }\n * ```\n *\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"content\": {\n * \"myContent\": t({\n * \"en\": \"English content\",\n * })\n * }\n * }\n * ```\n */\nexport const getMultilingualDictionary = (\n dictionary: Dictionary\n): Dictionary => {\n if (!dictionary.locale) {\n return dictionary;\n }\n\n const locale = dictionary.locale;\n\n const wrapPrimitiveInTranslationPlugin: Plugins = {\n id: 'wrap-primitive-in-translation',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: (node) => t({ [locale]: node } as Record<string, unknown>),\n };\n\n const traverseTypedNodePlugin: Plugins = {\n id: 'traverse-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof (node as any)?.nodeType === 'string',\n transform: (node: TypedNode, props, transformFn) => {\n const nodeType = (node as any).nodeType as NodeType;\n const inner = structuredClone(\n (node as any)[nodeType as unknown as keyof TypedNode] as any\n );\n\n if (typeof inner !== 'object' || inner === null) {\n const transformed = transformFn(inner, {\n ...props,\n children: inner,\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]: transformed,\n };\n }\n\n for (const key in inner) {\n const childProps: NodeProps = {\n ...props,\n children: inner[key as unknown as keyof typeof inner],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n inner[key as unknown as keyof typeof inner] = transformFn(\n inner[key as unknown as keyof typeof inner],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: inner };\n },\n };\n\n const transformedContent = deepTransformNode(\n JSON.parse(JSON.stringify(dictionary.content)),\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [traverseTypedNodePlugin, wrapPrimitiveInTranslationPlugin],\n }\n );\n\n const { locale: _omitLocale, ...rest } = dictionary as any;\n return {\n ...rest,\n content: transformedContent,\n } as Dictionary;\n};\n"],"mappings":"yIAiCA,MAAa,EACX,GACe,CACf,GAAI,CAAC,EAAW,OACd,OAAO,EAGT,IAAM,EAAS,EAAW,OAoDpB,EAAqB,EACzB,KAAK,MAAM,KAAK,UAAU,EAAW,QAAQ,CAAC,CAC9C,CACE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACX,QAAS,CA9C4B,CACvC,GAAI,6BACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAQ,GAAc,UAAa,SACjE,WAAY,EAAiB,EAAO,IAAgB,CAClD,IAAM,EAAY,EAAa,SACzB,EAAQ,gBACX,EAAa,GACf,CAED,GAAI,OAAO,GAAU,WAAY,EAAgB,CAC/C,IAAM,EAAc,EAAY,EAAO,CACrC,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAU,IAAK,EAAU,CAClC,CACF,CAAC,CACF,MAAO,CACL,GAAG,GACF,GAAyC,EAC3C,CAGH,IAAK,IAAM,KAAO,EAAO,CACvB,IAAM,EAAwB,CAC5B,GAAG,EACH,SAAU,EAAM,GAChB,QAAS,CAAC,GAAG,EAAM,QAAS,CAAE,KAAM,EAAU,MAAK,CAAY,CAChE,CACD,EAAM,GAAwC,EAC5C,EAAM,GACN,EACD,CAGH,MAAO,CAAE,GAAG,GAAO,GAAyC,EAAO,EAEtE,CAhDiD,CAChD,GAAI,gCACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,UAClB,UAAY,GAASA,EAAE,EAAG,GAAS,EAAM,CAA4B,CACtE,CAgDuE,CACrE,CACF,CAEK,CAAE,OAAQ,EAAa,GAAG,GAAS,EACzC,MAAO,CACL,GAAG,EACH,QAAS,EACV"}
|