@intlayer/core 8.2.4 → 8.3.0-canary.0
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/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs +1 -1
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMaskContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +1 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs +1 -1
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs +1 -1
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/getStorageAttributes.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs +1 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getHTMLTextDir.cjs +1 -1
- package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleLang.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/localization/localeDetector.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs +1 -1
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/localization/localeResolver.cjs.map +1 -1
- package/dist/cjs/localization/rewriteUtils.cjs.map +1 -1
- package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
- package/dist/cjs/messageFormat/ICU.cjs +1 -1
- package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
- package/dist/cjs/messageFormat/i18next.cjs +1 -1
- package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
- package/dist/cjs/messageFormat/vue-i18n.cjs +1 -1
- package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/condition.cjs +1 -1
- package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/enumeration.cjs +1 -1
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/file/file.cjs +1 -1
- package/dist/cjs/transpiler/file/file.cjs.map +1 -1
- package/dist/cjs/transpiler/file/fileBrowser.cjs +1 -1
- package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
- package/dist/cjs/transpiler/gender/gender.cjs +1 -1
- package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
- package/dist/cjs/transpiler/html/html.cjs +1 -1
- package/dist/cjs/transpiler/html/html.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/insertion.cjs +1 -1
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/nesting/nesting.cjs +1 -1
- package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/translation.cjs +1 -1
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +1 -1
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs +1 -1
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs +1 -1
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs +1 -1
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMaskContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs +1 -1
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getSplittedContent.mjs +1 -1
- package/dist/esm/deepTransformPlugins/getSplittedContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs +1 -1
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeType.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +1 -1
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
- package/dist/esm/formatters/compact.mjs.map +1 -1
- package/dist/esm/formatters/currency.mjs.map +1 -1
- package/dist/esm/formatters/date.mjs.map +1 -1
- package/dist/esm/formatters/list.mjs.map +1 -1
- package/dist/esm/formatters/number.mjs.map +1 -1
- package/dist/esm/formatters/percentage.mjs.map +1 -1
- package/dist/esm/formatters/relativeTime.mjs.map +1 -1
- package/dist/esm/formatters/units.mjs.map +1 -1
- package/dist/esm/getStorageAttributes.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/deepTransform.mjs +1 -1
- package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getNesting.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/localization/getBrowserLocale.mjs +1 -1
- package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/localization/getHTMLTextDir.mjs +1 -1
- package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
- package/dist/esm/localization/getLocaleLang.mjs.map +1 -1
- package/dist/esm/localization/getLocaleName.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/localization/localeDetector.mjs.map +1 -1
- package/dist/esm/localization/localeMapper.mjs +1 -1
- package/dist/esm/localization/localeMapper.mjs.map +1 -1
- package/dist/esm/localization/localeResolver.mjs.map +1 -1
- package/dist/esm/localization/rewriteUtils.mjs.map +1 -1
- package/dist/esm/localization/validatePrefix.mjs.map +1 -1
- package/dist/esm/messageFormat/ICU.mjs +1 -1
- package/dist/esm/messageFormat/ICU.mjs.map +1 -1
- package/dist/esm/messageFormat/i18next.mjs +1 -1
- package/dist/esm/messageFormat/i18next.mjs.map +1 -1
- package/dist/esm/messageFormat/vue-i18n.mjs +1 -1
- package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
- package/dist/esm/transpiler/condition/condition.mjs +1 -1
- package/dist/esm/transpiler/condition/condition.mjs.map +1 -1
- package/dist/esm/transpiler/enumeration/enumeration.mjs +1 -1
- package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/file/file.mjs +1 -1
- package/dist/esm/transpiler/file/file.mjs.map +1 -1
- package/dist/esm/transpiler/file/fileBrowser.mjs +1 -1
- package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -1
- package/dist/esm/transpiler/gender/gender.mjs +1 -1
- package/dist/esm/transpiler/gender/gender.mjs.map +1 -1
- package/dist/esm/transpiler/html/html.mjs +1 -1
- package/dist/esm/transpiler/html/html.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/insertion.mjs +1 -1
- package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/markdown.mjs +1 -1
- package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
- package/dist/esm/transpiler/nesting/nesting.mjs +1 -1
- package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
- package/dist/esm/transpiler/translation/translation.mjs +1 -1
- package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
- package/dist/esm/utils/intl.mjs +1 -1
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/esm/utils/isSameKeyPath.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +12 -11
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +12 -11
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +12 -11
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts +2 -1
- package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getMaskContent.d.ts +1 -1
- package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts +3 -1
- package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getMultilingualDictionary.d.ts +1 -1
- package/dist/types/deepTransformPlugins/getMultilingualDictionary.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts +1 -1
- package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getSplittedContent.d.ts +2 -1
- package/dist/types/deepTransformPlugins/getSplittedContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/insertContentInDictionary.d.ts +2 -1
- package/dist/types/deepTransformPlugins/insertContentInDictionary.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts +2 -1
- package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts +3 -1
- package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +3 -1
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getEmptyNode.d.ts +1 -1
- package/dist/types/dictionaryManipulator/getEmptyNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts +1 -1
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeType.d.ts +2 -1
- package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts +1 -1
- package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/normalizeDictionary.d.ts +2 -1
- package/dist/types/dictionaryManipulator/normalizeDictionary.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +3 -3
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts +2 -1
- package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts +2 -1
- package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts +1 -1
- package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts.map +1 -1
- package/dist/types/formatters/compact.d.ts +1 -1
- package/dist/types/formatters/currency.d.ts +1 -1
- package/dist/types/formatters/date.d.ts +1 -1
- package/dist/types/formatters/list.d.ts +1 -1
- package/dist/types/formatters/number.d.ts +1 -1
- package/dist/types/formatters/percentage.d.ts +1 -1
- package/dist/types/formatters/relativeTime.d.ts +1 -1
- package/dist/types/formatters/units.d.ts +1 -1
- package/dist/types/getStorageAttributes.d.ts +1 -1
- package/dist/types/getStorageAttributes.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/deepTransform.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/getContent.d.ts +2 -1
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts +4 -1
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getDictionary.d.ts +2 -1
- package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
- package/dist/types/interpreter/getNesting.d.ts +2 -1
- package/dist/types/interpreter/getNesting.d.ts.map +1 -1
- package/dist/types/interpreter/getTranslation.d.ts +1 -1
- package/dist/types/localization/getBrowserLocale.d.ts +1 -1
- package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
- package/dist/types/localization/getHTMLTextDir.d.ts +1 -1
- package/dist/types/localization/getHTMLTextDir.d.ts.map +1 -1
- package/dist/types/localization/getLocale.d.ts +1 -1
- package/dist/types/localization/getLocaleFromPath.d.ts +3 -1
- package/dist/types/localization/getLocaleFromPath.d.ts.map +1 -1
- package/dist/types/localization/getLocaleLang.d.ts +1 -1
- package/dist/types/localization/getLocaleName.d.ts +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts +2 -1
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/localization/getMultilingualUrls.d.ts +2 -1
- package/dist/types/localization/getMultilingualUrls.d.ts.map +1 -1
- package/dist/types/localization/getPathWithoutLocale.d.ts +1 -1
- package/dist/types/localization/getPrefix.d.ts +3 -1
- package/dist/types/localization/getPrefix.d.ts.map +1 -1
- package/dist/types/localization/localeDetector.d.ts +1 -1
- package/dist/types/localization/localeMapper.d.ts +2 -1
- package/dist/types/localization/localeMapper.d.ts.map +1 -1
- package/dist/types/localization/localeResolver.d.ts +2 -1
- package/dist/types/localization/localeResolver.d.ts.map +1 -1
- package/dist/types/localization/rewriteUtils.d.ts +3 -1
- package/dist/types/localization/rewriteUtils.d.ts.map +1 -1
- package/dist/types/localization/validatePrefix.d.ts +1 -1
- package/dist/types/messageFormat/ICU.d.ts +1 -1
- package/dist/types/messageFormat/ICU.d.ts.map +1 -1
- package/dist/types/messageFormat/i18next.d.ts +1 -1
- package/dist/types/messageFormat/vue-i18n.d.ts +1 -1
- package/dist/types/messageFormat/vue-i18n.d.ts.map +1 -1
- package/dist/types/transpiler/condition/condition.d.ts +1 -1
- package/dist/types/transpiler/condition/condition.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/file/file.d.ts +1 -1
- package/dist/types/transpiler/file/file.d.ts.map +1 -1
- package/dist/types/transpiler/file/fileBrowser.d.ts +1 -1
- package/dist/types/transpiler/file/fileBrowser.d.ts.map +1 -1
- package/dist/types/transpiler/gender/gender.d.ts +1 -1
- package/dist/types/transpiler/gender/gender.d.ts.map +1 -1
- package/dist/types/transpiler/html/html.d.ts +1 -1
- package/dist/types/transpiler/html/html.d.ts.map +1 -1
- package/dist/types/transpiler/insertion/insertion.d.ts +1 -1
- package/dist/types/transpiler/insertion/insertion.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/markdown.d.ts +1 -1
- package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
- package/dist/types/transpiler/nesting/nesting.d.ts +2 -1
- package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
- package/dist/types/transpiler/translation/translation.d.ts +3 -2
- package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
- package/dist/types/utils/intl.d.ts +1 -1
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/dist/types/utils/isSameKeyPath.d.ts +1 -1
- package/dist/types/utils/localeStorage.d.ts +2 -1
- package/dist/types/utils/localeStorage.d.ts.map +1 -1
- package/package.json +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewriteUtils.mjs","names":[],"sources":["../../../src/localization/rewriteUtils.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"rewriteUtils.mjs","names":[],"sources":["../../../src/localization/rewriteUtils.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { RewriteObject, RewriteRules, RoutingConfig } from '@intlayer/types/config';\nimport type { Locale } from '@intlayer/types/allLocales';\n\nexport type LocalizedPathResult = {\n path: string;\n isRewritten: boolean;\n};\n\n/**\n * Normalizes legacy Record format or extracts specialized rules from RewriteObject.\n */\nexport const getRewriteRules = (\n rewrite: RoutingConfig['rewrite'],\n context: keyof RewriteObject = 'url'\n): RewriteRules | undefined => {\n if (!rewrite) return undefined;\n\n if ('url' in rewrite) {\n return (rewrite as RewriteObject)[context];\n }\n\n // Normalize legacy format\n return {\n rules: Object.entries(rewrite).map(([canonical, localized]) => ({\n // Normalize canonical path\n canonical: canonical.startsWith('/')\n ? canonical.replace(/\\[([^\\]]+)\\]/g, ':$1')\n : `/${canonical.replace(/\\[([^\\]]+)\\]/g, ':$1')}`,\n\n // Normalize localized path\n localized: Object.fromEntries(\n Object.entries(localized).map(([locale, pattern]) => {\n const normalizedPattern = pattern?.startsWith('/')\n ? pattern.replace(/\\[([^\\]]+)\\]/g, ':$1')\n : `/${(pattern || '').replace(/\\[([^\\]]+)\\]/g, ':$1')}`;\n return [locale, normalizedPattern];\n })\n ),\n })),\n };\n};\n\n/**\n * Converts normalized pattern to Regex.\n * Internal syntax supports:\n * - :param -> ([^/]+) (one segment)\n * - :param* -> (.*) (zero or more segments)\n * - :param+ -> (.+) (one or more segments)\n * - :param? -> ([^/]*) (zero or one segment)\n */\nconst patternToRegex = (pattern: string) => {\n const regexString = pattern\n .replace(/\\//g, '\\\\/') // Escape slashes\n .replace(/\\\\\\/:(?:[^/\\\\*+?]+)\\*/g, '(?:\\\\/(.*))?') // /:param*\n .replace(/\\\\\\/:(?:[^/\\\\*+?]+)\\?/g, '(?:\\\\/([^\\\\/]+))?') // /:param?\n .replace(/:([^/\\\\*+?]+)\\*/g, '(.*)') // :param* (if no leading slash)\n .replace(/:([^/\\\\*+?]+)\\?/g, '([^\\\\/]*)') // :param? (if no leading slash)\n .replace(/:([^/\\\\*+?]+)\\+/g, '(.+)') // :param+\n .replace(/:([^/\\\\*+?]+)/g, '([^\\\\/]+)'); // :param\n\n return new RegExp(`^${regexString}$`);\n};\n\n/**\n * Replaces route parameters in a path with provided values.\n */\nconst fillPath = (pattern: string, params: string[]) => {\n let index = 0;\n return (\n pattern\n .replace(/:([^/\\\\*+?]+)[*+?]?/g, () => params[index++] ?? '')\n .replace(/\\/+/g, '/')\n .replace(/\\/$/, '') || '/'\n );\n};\n\n/**\n * Extract values from a URL based on a pattern.\n */\nconst extractParams = (url: string, pattern: string): string[] | null => {\n const regex = patternToRegex(pattern);\n const match = url.match(regex);\n return match ? match.slice(1) : null;\n};\n\n/**\n * Given a localized URL (e.g., \"/produits/123\"), finds the canonical internal path (e.g., \"/products/123\").\n * If locale is provided, only check for that locale. Otherwise, check for all locales.\n */\nexport const getCanonicalPath = (\n localizedPath: string,\n locale?: Locale,\n rewriteRules?: RewriteRules\n): string => {\n if (!rewriteRules) return localizedPath;\n\n for (const rule of rewriteRules.rules) {\n const { canonical, localized } = rule;\n const localesToCheck = locale ? [locale] : Object.keys(localized);\n\n for (const loc of localesToCheck) {\n const localizedPattern = localized[loc as keyof typeof localized];\n\n if (!localizedPattern) continue;\n\n const params = extractParams(localizedPath, localizedPattern);\n\n if (params) {\n return fillPath(canonical, params);\n }\n }\n }\n\n return localizedPath;\n};\n\n/**\n * Given a canonical path (e.g., \"/products/123\"), finds the localized URL pattern (e.g., \"/produits/123\").\n */\nexport const getLocalizedPath = (\n canonicalPath: string,\n locale: LocalesValues,\n rewriteRules?: RewriteRules\n): LocalizedPathResult => {\n if (!rewriteRules) return { path: canonicalPath, isRewritten: false };\n\n for (const rule of rewriteRules.rules) {\n const { canonical, localized } = rule;\n\n // Check if the input path matches a configured canonical pattern\n const params = extractParams(canonicalPath, canonical);\n\n if (params) {\n const targetPattern = localized[locale as keyof typeof localized];\n\n if (targetPattern) {\n return {\n path: fillPath(targetPattern, params),\n isRewritten: true,\n };\n }\n }\n }\n\n return { path: canonicalPath, isRewritten: false };\n};\n\n/**\n * Returns the internal path for a given canonical path and locale.\n * Ensures the locale prefix is present exactly once.\n */\nexport const getInternalPath = (\n canonicalPath: string,\n locale: Locale\n): string => {\n const pathWithLeadingSlash = canonicalPath.startsWith('/')\n ? canonicalPath\n : `/${canonicalPath}`;\n\n if (\n pathWithLeadingSlash.startsWith(`/${locale}/`) ||\n pathWithLeadingSlash === `/${locale}`\n ) {\n return pathWithLeadingSlash;\n }\n\n return `/${locale}${pathWithLeadingSlash === '/' ? '' : pathWithLeadingSlash}`;\n};\n\n/**\n * Given a current pathname and locale, returns the pretty localized path if a rewrite rule exists and the path is not already localized.\n */\nexport const getRewritePath = (\n pathname: string,\n locale: Locale,\n rewrite?: RoutingConfig['rewrite']\n): string | undefined => {\n const rules = getRewriteRules(rewrite, 'url');\n if (!rules) return undefined;\n\n // Identify canonical path (relative to root, no locale prefix expected in 'url' context)\n const canonicalPath = getCanonicalPath(pathname, undefined, rules);\n\n // Get the localized path for the current locale\n const { path: localizedPath, isRewritten } = getLocalizedPath(\n canonicalPath,\n locale,\n rules\n );\n\n if (isRewritten && localizedPath !== pathname) {\n return localizedPath;\n }\n\n return undefined;\n};\n"],"mappings":"AAYA,MAAa,GACX,EACA,EAA+B,QACF,CACxB,KAOL,MALI,QAAS,EACH,EAA0B,GAI7B,CACL,MAAO,OAAO,QAAQ,EAAQ,CAAC,KAAK,CAAC,EAAW,MAAgB,CAE9D,UAAW,EAAU,WAAW,IAAI,CAChC,EAAU,QAAQ,gBAAiB,MAAM,CACzC,IAAI,EAAU,QAAQ,gBAAiB,MAAM,GAGjD,UAAW,OAAO,YAChB,OAAO,QAAQ,EAAU,CAAC,KAAK,CAAC,EAAQ,KAI/B,CAAC,EAHkB,GAAS,WAAW,IAAI,CAC9C,EAAQ,QAAQ,gBAAiB,MAAM,CACvC,KAAK,GAAW,IAAI,QAAQ,gBAAiB,MAAM,GACrB,CAClC,CACH,CACF,EAAE,CACJ,EAWG,EAAkB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,EAAe,YAAa,GAAO,EAOvC,GACX,EACA,IACW,CACX,IAAM,EAAuB,EAAc,WAAW,IAAI,CACtD,EACA,IAAI,IASR,OANE,EAAqB,WAAW,IAAI,EAAO,GAAG,EAC9C,IAAyB,IAAI,IAEtB,EAGF,IAAI,IAAS,IAAyB,IAAM,GAAK,KAM7C,GACX,EACA,EACA,IACuB,CACvB,IAAM,EAAQ,EAAgB,EAAS,MAAM,CAC7C,GAAI,CAAC,EAAO,OAMZ,GAAM,CAAE,KAAM,EAAe,eAAgB,EAHvB,EAAiB,EAAU,IAAA,GAAW,EAAM,CAKhE,EACA,EACD,CAED,GAAI,GAAe,IAAkB,EACnC,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatePrefix.mjs","names":[],"sources":["../../../src/localization/validatePrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types';\nimport { getPrefix } from './getPrefix';\n\nexport type ValidatePrefixResult = {\n isValid: boolean;\n localePrefix: string | undefined;\n};\n\n/**\n * Checks whether a given locale is valid based on the configured locales.\n *\n * @param locale - The locale value to validate. Can be `undefined` or `null`.\n * @param options - Optional configuration to override default settings.\n * @param options.locales - Array of valid locales. Defaults to the configured internationalization locales.\n * @param options.defaultLocale - The default locale to use as fallback. Defaults to the configured default locale.\n * @param options.mode - The routing mode (`'prefix'`, `'prefix-all'`, or `'no-prefix'`). Defaults to the configured routing mode.\n * @returns An object containing the validation result and the locale prefix.\n *\n * @example\n * // Check if 'en' is a valid locale\n * const { isValid, localePrefix } = validatePrefix('en');\n *\n * @example\n * // Check with custom options\n * const { isValid, localePrefix } = validatePrefix('fr', {\n * locales: ['en', 'fr', 'es'],\n * defaultLocale: 'en',\n * mode: 'prefix-all',\n * });\n */\nexport const validatePrefix = (\n locale: LocalesValues | undefined | null,\n options?: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: typeof configuration.routing.mode;\n }\n): ValidatePrefixResult => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES,\n ...options,\n };\n\n // If no locale provided (optional param), will use default\n // In `routing.mode = 'prefix-all'`, the locale is required to be a valid locale\n const { localePrefix } = getPrefix(locale || defaultLocale, {\n mode,\n locales,\n defaultLocale,\n });\n\n if (localePrefix === locale && locale === undefined) {\n return { isValid: true, localePrefix: undefined };\n }\n\n // Check if the provided locale is valid\n const isValid: boolean = locales.some((localeEl) => localeEl === locale);\n\n return { isValid: isValid, localePrefix };\n};\n"],"mappings":"0IAgCA,MAAa,GACX,EACA,IAKyB,CACzB,GAAM,CAAE,gBAAe,OAAM,WAAY,CACvC,cACE,GAAe,sBAAsB,eACrC,EAAc,qBAAqB,eACrC,KAAM,GAAe,SAAS,MAAQ,EAAc,QAAQ,aAC5D,QACE,GAAe,sBAAsB,SACrC,EAAc,qBAAqB,QACrC,GAAG,EACJ,CAIK,CAAE,gBAAiB,EAAU,GAAU,EAAe,CAC1D,OACA,UACA,gBACD,CAAC,CASF,OAPI,IAAiB,GAAU,IAAW,IAAA,GACjC,CAAE,QAAS,GAAM,aAAc,IAAA,GAAW,CAM5C,CAAE,QAFgB,EAAQ,KAAM,GAAa,IAAa,EAAO,CAE7C,eAAc"}
|
|
1
|
+
{"version":3,"file":"validatePrefix.mjs","names":[],"sources":["../../../src/localization/validatePrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getPrefix } from './getPrefix';\n\nexport type ValidatePrefixResult = {\n isValid: boolean;\n localePrefix: string | undefined;\n};\n\n/**\n * Checks whether a given locale is valid based on the configured locales.\n *\n * @param locale - The locale value to validate. Can be `undefined` or `null`.\n * @param options - Optional configuration to override default settings.\n * @param options.locales - Array of valid locales. Defaults to the configured internationalization locales.\n * @param options.defaultLocale - The default locale to use as fallback. Defaults to the configured default locale.\n * @param options.mode - The routing mode (`'prefix'`, `'prefix-all'`, or `'no-prefix'`). Defaults to the configured routing mode.\n * @returns An object containing the validation result and the locale prefix.\n *\n * @example\n * // Check if 'en' is a valid locale\n * const { isValid, localePrefix } = validatePrefix('en');\n *\n * @example\n * // Check with custom options\n * const { isValid, localePrefix } = validatePrefix('fr', {\n * locales: ['en', 'fr', 'es'],\n * defaultLocale: 'en',\n * mode: 'prefix-all',\n * });\n */\nexport const validatePrefix = (\n locale: LocalesValues | undefined | null,\n options?: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: typeof configuration.routing.mode;\n }\n): ValidatePrefixResult => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES,\n ...options,\n };\n\n // If no locale provided (optional param), will use default\n // In `routing.mode = 'prefix-all'`, the locale is required to be a valid locale\n const { localePrefix } = getPrefix(locale || defaultLocale, {\n mode,\n locales,\n defaultLocale,\n });\n\n if (localePrefix === locale && locale === undefined) {\n return { isValid: true, localePrefix: undefined };\n }\n\n // Check if the provided locale is valid\n const isValid: boolean = locales.some((localeEl) => localeEl === locale);\n\n return { isValid: isValid, localePrefix };\n};\n"],"mappings":"0IAgCA,MAAa,GACX,EACA,IAKyB,CACzB,GAAM,CAAE,gBAAe,OAAM,WAAY,CACvC,cACE,GAAe,sBAAsB,eACrC,EAAc,qBAAqB,eACrC,KAAM,GAAe,SAAS,MAAQ,EAAc,QAAQ,aAC5D,QACE,GAAe,sBAAsB,SACrC,EAAc,qBAAqB,QACrC,GAAG,EACJ,CAIK,CAAE,gBAAiB,EAAU,GAAU,EAAe,CAC1D,OACA,UACA,gBACD,CAAC,CASF,OAPI,IAAiB,GAAU,IAAW,IAAA,GACjC,CAAE,QAAS,GAAM,aAAc,IAAA,GAAW,CAM5C,CAAE,QAFgB,EAAQ,KAAM,GAAa,IAAa,EAAO,CAE7C,eAAc"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{enu as t}from"../transpiler/enumeration/enumeration.mjs";import{gender as n}from"../transpiler/gender/gender.mjs";import{html as r}from"../transpiler/html/html.mjs";import{insert as i}from"../transpiler/insertion/insertion.mjs";import{NodeType as a}from"@intlayer/types";const o=e=>{let t=0,n=()=>{let n=[],i=``;for(;t<e.length;){let a=e[t];if(a===`{`)i&&=(n.push(i),``),t++,n.push(r());else if(a===`}`)break;else if(a===`'`)if(t+1<e.length&&e[t+1]===`'`)i+=`'`,t+=2;else{let n=e.indexOf(`'`,t+1);n===-1?(i+=`'`,t++):(i+=e.substring(t+1,n),t=n+1)}else i+=a,t++}return i&&n.push(i),n},r=()=>{let r=``;for(;t<e.length&&/[^,}]/.test(e[t]);)r+=e[t],t++;if(r=r.trim(),t>=e.length)throw Error(`Unclosed argument`);if(e[t]===`}`)return t++,{type:`argument`,name:r};if(e[t]===`,`){t++;let i=``;for(;t<e.length&&/[^,}]/.test(e[t]);)i+=e[t],t++;if(i=i.trim(),t>=e.length)throw Error(`Unclosed argument`);if(e[t]===`}`)return t++,{type:`argument`,name:r,format:{type:i}};if(e[t]===`,`)if(t++,i===`plural`||i===`select`){let a={};for(;t<e.length&&e[t]!==`}`;){for(;t<e.length&&/\s/.test(e[t]);)t++;let r=``;for(;t<e.length&&/[^{\s]/.test(e[t]);)r+=e[t],t++;for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]!==`{`)throw Error(`Expected { after option key`);t++;let i=n();if(e[t]!==`}`)throw Error(`Expected } after option value`);for(t++,a[r]=i;t<e.length&&/\s/.test(e[t]);)t++}if(t++,i===`plural`)return{type:`plural`,name:r,options:a};if(i===`select`)return{type:`select`,name:r,options:a}}else{let n=``;for(;t<e.length&&e[t]!==`}`;)n+=e[t],t++;if(t>=e.length)throw Error(`Unclosed argument`);return n=n.trim(),t++,{type:`argument`,name:r,format:{type:i,style:n}}}}throw Error(`Malformed argument`)};return n()},s=e=>{if(e.length===0)return``;if(e.length===1&&typeof e[0]==`string`){let t=e[0];return/<[a-zA-Z0-9-]+[^>]*>/.test(t)?r(t):t}if(e.every(e=>typeof e==`string`||e.type===`argument`)){let t=``;for(let n of e)typeof n==`string`?t+=n:typeof n!=`string`&&n.type===`argument`&&(n.format?t+=`{${n.name}, ${n.format.type}${n.format.style?`, ${n.format.style}`:``}}`:t+=`{{${n.name}}}`);return/<[a-zA-Z0-9-]+[^>]*>/.test(t)?r(t):i(t)}if(e.length===1){let a=e[0];if(typeof a==`string`)return/<[a-zA-Z0-9-]+[^>]*>/.test(a)?r(a):a;if(a.type===`argument`)return a.format?i(`{${a.name}, ${a.format.type}${a.format.style?`, ${a.format.style}`:``}}`):i(`{{${a.name}}}`);if(a.type===`plural`){let e={};for(let[t,n]of Object.entries(a.options)){let r=t;t.startsWith(`=`)?r=t.substring(1):t===`one`?r=`1`:t===`two`?r=`2`:t===`few`?r=`<=3`:t===`many`?r=`>=4`:t===`other`&&(r=`fallback`),e[r]=s(n.map(e=>typeof e==`string`?e.replace(/#/g,`{{${a.name}}}`):e))}return e.__intlayer_icu_var=a.name,t(e)}if(a.type===`select`){let e={};for(let[t,n]of Object.entries(a.options))e[t]=s(n);let r=Object.keys(e);return(e.male||e.female)&&r.every(e=>[`male`,`female`,`other`,`fallback`].includes(e))?n({fallback:e.other,male:e.male,female:e.female}):(e.__intlayer_icu_var=a.name,t(e))}}return e.map(e=>s([e]))},c={canHandle:e=>typeof e==`string`&&(e.includes(`{`)||e.includes(`}`)||/<[a-zA-Z0-9-]+[^>]*>/.test(e)),transform:e=>{try{return s(o(e))}catch{return e}}},l={canHandle:e=>typeof e==`string`&&(e.includes(`{`)||e.includes(`}`))||e&&typeof e==`object`&&(e.nodeType===a.Insertion||e.nodeType===a.HTML||e.nodeType===a.Enumeration||e.nodeType===a.Gender||e.nodeType===`composite`)||Array.isArray(e),transform:(e,t,n)=>{if(typeof e==`string`)return e.replace(/\{\{([^}]+)\}\}/g,`{$1}`);if(e.nodeType===a.Insertion)return e.insertion.replace(/\{\{([^}]+)\}\}/g,`{$1}`);if(e.nodeType===a.HTML)return e.html;if(e.nodeType===a.Enumeration){let r=e.enumeration,i={};for(let[e,a]of Object.entries(r)){if(e===`__intlayer_icu_var`)continue;let r=n(a,t);i[e]=typeof r==`string`?r:JSON.stringify(r)}let a=r.__intlayer_icu_var||`n`;if(!r.__intlayer_icu_var){let e=(i.fallback||i.other||Object.values(i)[0]).match(/\{([a-zA-Z0-9_]+)\}(?!,)/);e&&(a=e[1])}let o=Object.keys(i),s=[`1`,`2`,`<=3`,`>=4`,`fallback`,`other`,`zero`,`one`,`two`,`few`,`many`],c=o.every(e=>s.includes(e)||/^[<>=]?\d+(\.\d+)?$/.test(e)),l=[];if(c){for(let[e,t]of Object.entries(i)){let n=e;n=e===`fallback`?`other`:e===`<=3`?`few`:e===`>=4`?`many`:/^\d+$/.test(e)?`=${e}`:[`zero`,`few`,`many`].includes(e)?e:`other`;let r=t;r=r.replace(RegExp(`\\{${a}\\}`,`g`),`#`),l.push(`${n} {${r}}`)}return`{${a}, plural, ${l.join(` `)}}`}else{let e=Object.entries(i).sort(([e],[t])=>e===`fallback`||e===`other`?1:t===`fallback`||t===`other`?-1:0);for(let[t,n]of e){let e=t;t===`fallback`&&(e=`other`),l.push(`${e} {${n}}`)}return`{${a}, select, ${l.join(` `)}}`}}if(e.nodeType===a.Gender){let r=e.gender,i=[],a=Object.entries(r).sort(([e],[t])=>e===`fallback`?1:t===`fallback`?-1:0);for(let[e,r]of a){let a=e;e===`fallback`&&(a=`other`);let o=n(r,t),s=typeof o==`string`?o:JSON.stringify(o);i.push(`${a} {${s}}`)}return`{gender, select, ${i.join(` `)}}`}return Array.isArray(e)||e.nodeType===`composite`&&Array.isArray(e.composite)?(Array.isArray(e)?e:e.composite).map(e=>n(e,t)).join(``):n(e,t)}},u=t=>e(t,{dictionaryKey:`icu`,keyPath:[],plugins:[{id:`icu`,...l}]}),d=t=>e(t,{dictionaryKey:`icu`,keyPath:[],plugins:[{id:`icu`,...c}]});export{d as icuToIntlayerFormatter,u as intlayerToICUFormatter};
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{enu as t}from"../transpiler/enumeration/enumeration.mjs";import{gender as n}from"../transpiler/gender/gender.mjs";import{html as r}from"../transpiler/html/html.mjs";import{insert as i}from"../transpiler/insertion/insertion.mjs";import{NodeType as a}from"@intlayer/types/nodeType";const o=e=>{let t=0,n=()=>{let n=[],i=``;for(;t<e.length;){let a=e[t];if(a===`{`)i&&=(n.push(i),``),t++,n.push(r());else if(a===`}`)break;else if(a===`'`)if(t+1<e.length&&e[t+1]===`'`)i+=`'`,t+=2;else{let n=e.indexOf(`'`,t+1);n===-1?(i+=`'`,t++):(i+=e.substring(t+1,n),t=n+1)}else i+=a,t++}return i&&n.push(i),n},r=()=>{let r=``;for(;t<e.length&&/[^,}]/.test(e[t]);)r+=e[t],t++;if(r=r.trim(),t>=e.length)throw Error(`Unclosed argument`);if(e[t]===`}`)return t++,{type:`argument`,name:r};if(e[t]===`,`){t++;let i=``;for(;t<e.length&&/[^,}]/.test(e[t]);)i+=e[t],t++;if(i=i.trim(),t>=e.length)throw Error(`Unclosed argument`);if(e[t]===`}`)return t++,{type:`argument`,name:r,format:{type:i}};if(e[t]===`,`)if(t++,i===`plural`||i===`select`){let a={};for(;t<e.length&&e[t]!==`}`;){for(;t<e.length&&/\s/.test(e[t]);)t++;let r=``;for(;t<e.length&&/[^{\s]/.test(e[t]);)r+=e[t],t++;for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]!==`{`)throw Error(`Expected { after option key`);t++;let i=n();if(e[t]!==`}`)throw Error(`Expected } after option value`);for(t++,a[r]=i;t<e.length&&/\s/.test(e[t]);)t++}if(t++,i===`plural`)return{type:`plural`,name:r,options:a};if(i===`select`)return{type:`select`,name:r,options:a}}else{let n=``;for(;t<e.length&&e[t]!==`}`;)n+=e[t],t++;if(t>=e.length)throw Error(`Unclosed argument`);return n=n.trim(),t++,{type:`argument`,name:r,format:{type:i,style:n}}}}throw Error(`Malformed argument`)};return n()},s=e=>{if(e.length===0)return``;if(e.length===1&&typeof e[0]==`string`){let t=e[0];return/<[a-zA-Z0-9-]+[^>]*>/.test(t)?r(t):t}if(e.every(e=>typeof e==`string`||e.type===`argument`)){let t=``;for(let n of e)typeof n==`string`?t+=n:typeof n!=`string`&&n.type===`argument`&&(n.format?t+=`{${n.name}, ${n.format.type}${n.format.style?`, ${n.format.style}`:``}}`:t+=`{{${n.name}}}`);return/<[a-zA-Z0-9-]+[^>]*>/.test(t)?r(t):i(t)}if(e.length===1){let a=e[0];if(typeof a==`string`)return/<[a-zA-Z0-9-]+[^>]*>/.test(a)?r(a):a;if(a.type===`argument`)return a.format?i(`{${a.name}, ${a.format.type}${a.format.style?`, ${a.format.style}`:``}}`):i(`{{${a.name}}}`);if(a.type===`plural`){let e={};for(let[t,n]of Object.entries(a.options)){let r=t;t.startsWith(`=`)?r=t.substring(1):t===`one`?r=`1`:t===`two`?r=`2`:t===`few`?r=`<=3`:t===`many`?r=`>=4`:t===`other`&&(r=`fallback`),e[r]=s(n.map(e=>typeof e==`string`?e.replace(/#/g,`{{${a.name}}}`):e))}return e.__intlayer_icu_var=a.name,t(e)}if(a.type===`select`){let e={};for(let[t,n]of Object.entries(a.options))e[t]=s(n);let r=Object.keys(e);return(e.male||e.female)&&r.every(e=>[`male`,`female`,`other`,`fallback`].includes(e))?n({fallback:e.other,male:e.male,female:e.female}):(e.__intlayer_icu_var=a.name,t(e))}}return e.map(e=>s([e]))},c={canHandle:e=>typeof e==`string`&&(e.includes(`{`)||e.includes(`}`)||/<[a-zA-Z0-9-]+[^>]*>/.test(e)),transform:e=>{try{return s(o(e))}catch{return e}}},l={canHandle:e=>typeof e==`string`&&(e.includes(`{`)||e.includes(`}`))||e&&typeof e==`object`&&(e.nodeType===a.Insertion||e.nodeType===a.HTML||e.nodeType===a.Enumeration||e.nodeType===a.Gender||e.nodeType===`composite`)||Array.isArray(e),transform:(e,t,n)=>{if(typeof e==`string`)return e.replace(/\{\{([^}]+)\}\}/g,`{$1}`);if(e.nodeType===a.Insertion)return e.insertion.replace(/\{\{([^}]+)\}\}/g,`{$1}`);if(e.nodeType===a.HTML)return e.html;if(e.nodeType===a.Enumeration){let r=e.enumeration,i={};for(let[e,a]of Object.entries(r)){if(e===`__intlayer_icu_var`)continue;let r=n(a,t);i[e]=typeof r==`string`?r:JSON.stringify(r)}let a=r.__intlayer_icu_var||`n`;if(!r.__intlayer_icu_var){let e=(i.fallback||i.other||Object.values(i)[0]).match(/\{([a-zA-Z0-9_]+)\}(?!,)/);e&&(a=e[1])}let o=Object.keys(i),s=[`1`,`2`,`<=3`,`>=4`,`fallback`,`other`,`zero`,`one`,`two`,`few`,`many`],c=o.every(e=>s.includes(e)||/^[<>=]?\d+(\.\d+)?$/.test(e)),l=[];if(c){for(let[e,t]of Object.entries(i)){let n=e;n=e===`fallback`?`other`:e===`<=3`?`few`:e===`>=4`?`many`:/^\d+$/.test(e)?`=${e}`:[`zero`,`few`,`many`].includes(e)?e:`other`;let r=t;r=r.replace(RegExp(`\\{${a}\\}`,`g`),`#`),l.push(`${n} {${r}}`)}return`{${a}, plural, ${l.join(` `)}}`}else{let e=Object.entries(i).sort(([e],[t])=>e===`fallback`||e===`other`?1:t===`fallback`||t===`other`?-1:0);for(let[t,n]of e){let e=t;t===`fallback`&&(e=`other`),l.push(`${e} {${n}}`)}return`{${a}, select, ${l.join(` `)}}`}}if(e.nodeType===a.Gender){let r=e.gender,i=[],a=Object.entries(r).sort(([e],[t])=>e===`fallback`?1:t===`fallback`?-1:0);for(let[e,r]of a){let a=e;e===`fallback`&&(a=`other`);let o=n(r,t),s=typeof o==`string`?o:JSON.stringify(o);i.push(`${a} {${s}}`)}return`{gender, select, ${i.join(` `)}}`}return Array.isArray(e)||e.nodeType===`composite`&&Array.isArray(e.composite)?(Array.isArray(e)?e:e.composite).map(e=>n(e,t)).join(``):n(e,t)}},u=t=>e(t,{dictionaryKey:`icu`,keyPath:[],plugins:[{id:`icu`,...l}]}),d=t=>e(t,{dictionaryKey:`icu`,keyPath:[],plugins:[{id:`icu`,...c}]});export{d as icuToIntlayerFormatter,u as intlayerToICUFormatter};
|
|
2
2
|
//# sourceMappingURL=ICU.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ICU.mjs","names":["insert","enu"],"sources":["../../../src/messageFormat/ICU.ts"],"sourcesContent":["import { type Dictionary, NodeType } from '@intlayer/types';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, gender, html, insert } from '../transpiler';\n\n/**\n * ICU MessageFormat Converter\n *\n * This module converts between ICU MessageFormat and Intlayer's internal format.\n *\n * IMPORTANT: Two different formats are used:\n *\n * 1. ICU MessageFormat (external format):\n * - Simple variables: {name}\n * - Formatted variables: {amount, number, currency}\n * - Plural: {count, plural, =0 {none} other {# items}}\n * - Select: {gender, select, male {He} female {She} other {They}}\n *\n * 2. Intlayer Internal Format:\n * - Simple variables: {{name}} (double braces for clarity and to distinguish from literal text)\n * - Formatted variables: {amount, number, currency} (keeps ICU format)\n * - Plural: enu({ 0: 'none', fallback: '{{count}} items' })\n * - Select/Gender: gender({ male: 'He', female: 'She', fallback: 'They' })\n *\n * Conversion flow:\n * - ICU → Intlayer: {name} → {{name}}\n * - Intlayer → ICU: {{name}} → {name}\n *\n * The double braces in Intlayer format serve to:\n * - Distinguish variables from literal text containing braces\n * - Work with getInsertion() runtime function which expects {{var}} patterns\n * - Provide clear visual distinction in content dictionaries\n */\n\n// Types for our AST\ntype ICUNode =\n | string\n | {\n type: 'argument';\n name: string;\n format?: { type: string; style?: string };\n }\n | { type: 'plural'; name: string; options: Record<string, ICUNode[]> }\n | { type: 'select'; name: string; options: Record<string, ICUNode[]> };\n\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue };\n\nconst parseICU = (text: string): ICUNode[] => {\n let index = 0;\n\n const parseNodes = (): ICUNode[] => {\n const nodes: ICUNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n nodes.push(parseArgument());\n } else if (char === '}') {\n // End of current block\n break;\n } else if (char === \"'\") {\n // Escaping\n if (index + 1 < text.length && text[index + 1] === \"'\") {\n currentText += \"'\";\n index += 2;\n } else {\n // Find next quote\n const nextQuote = text.indexOf(\"'\", index + 1);\n if (nextQuote !== -1) {\n // Determine if this is escaping syntax characters\n // For simplicity, we'll treat content between single quotes as literal\n // provided it contains syntax chars.\n // Standard ICU: ' quoted string '\n // If it is just an apostrophe, it should be doubled.\n // But simplified: take content between quotes literally.\n currentText += text.substring(index + 1, nextQuote);\n index = nextQuote + 1;\n } else {\n currentText += \"'\";\n index++;\n }\n }\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n return nodes;\n };\n\n const parseArgument = (): ICUNode => {\n // We are past '{'\n // Parse name\n let name = '';\n while (index < text.length && /[^,}]/.test(text[index])) {\n name += text[index];\n index++;\n }\n name = name.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name };\n }\n\n // Must be comma\n if (text[index] === ',') {\n index++;\n // Parse type\n let type = '';\n while (index < text.length && /[^,}]/.test(text[index])) {\n type += text[index];\n index++;\n }\n type = type.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name, format: { type } };\n }\n\n if (text[index] === ',') {\n index++;\n\n // If plural or select, parse options\n if (type === 'plural' || type === 'select') {\n // Parse options\n const options: Record<string, ICUNode[]> = {};\n\n while (index < text.length && text[index] !== '}') {\n // skip whitespace\n while (index < text.length && /\\s/.test(text[index])) index++;\n\n // parse key\n let key = '';\n while (index < text.length && /[^{\\s]/.test(text[index])) {\n key += text[index];\n index++;\n }\n\n while (index < text.length && /\\s/.test(text[index])) index++;\n\n if (text[index] !== '{')\n throw new Error('Expected { after option key');\n index++; // skip {\n\n const value = parseNodes();\n\n if (text[index] !== '}')\n throw new Error('Expected } after option value');\n index++; // skip }\n\n options[key] = value;\n\n while (index < text.length && /\\s/.test(text[index])) index++;\n }\n\n index++; // skip closing argument }\n\n if (type === 'plural') {\n return { type: 'plural', name, options };\n } else if (type === 'select') {\n return { type: 'select', name, options };\n }\n } else {\n // Parse style for number/date/time\n let style = '';\n while (index < text.length && text[index] !== '}') {\n style += text[index];\n index++;\n }\n if (index >= text.length) throw new Error('Unclosed argument');\n\n style = style.trim();\n index++; // skip }\n\n return { type: 'argument', name, format: { type, style } };\n }\n }\n }\n\n throw new Error('Malformed argument');\n };\n\n return parseNodes();\n};\n\nconst icuNodesToIntlayer = (nodes: ICUNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') {\n const node = nodes[0];\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n\n // Check if we can flatten to a single string (insert)\n const canFlatten = nodes.every(\n (node) => typeof node === 'string' || node.type === 'argument'\n );\n if (canFlatten) {\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else if (typeof node !== 'string' && node.type === 'argument') {\n if (node.format) {\n // Formatted variables keep ICU format: {var, type, style}\n str += `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`;\n } else {\n // Simple variables use Intlayer format: {{var}}\n str += `{{${node.name}}}`;\n }\n }\n }\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(str)) {\n return html(str);\n }\n return insert(str);\n }\n\n // Mix of string and complex types.\n // If we have just one complex type and it covers everything?\n if (nodes.length === 1) {\n const node = nodes[0];\n\n if (typeof node === 'string') {\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n if (node.type === 'argument') {\n if (node.format) {\n return insert(\n `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`\n );\n }\n return insert(`{{${node.name}}}`);\n }\n if (node.type === 'plural') {\n const options: Record<string, any> = {};\n\n for (const [key, val] of Object.entries(node.options)) {\n // Map ICU keys to Intlayer keys\n let newKey = key;\n if (key.startsWith('=')) {\n newKey = key.substring(1); // =0 -> 0\n } else if (key === 'one') {\n newKey = '1';\n } else if (key === 'two') {\n newKey = '2';\n } else if (key === 'few') {\n newKey = '<=3';\n } else if (key === 'many') {\n newKey = '>=4';\n } else if (key === 'other') {\n newKey = 'fallback';\n }\n // Handle # in plural value\n // For plural, we need to pass the variable name down or replace #\n // Intlayer uses {{n}} (or whatever var name) for simple variables\n // We should replace # with {{n}} in the string parts of val\n const replacedVal = val.map((v) => {\n if (typeof v === 'string') {\n return v.replace(/#/g, `{{${node.name}}}`);\n }\n return v;\n });\n\n options[newKey] = icuNodesToIntlayer(replacedVal);\n }\n\n // Preserve variable name\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n }\n if (node.type === 'select') {\n const options: Record<string, any> = {};\n\n for (const [key, val] of Object.entries(node.options)) {\n options[key] = icuNodesToIntlayer(val);\n }\n\n // Check if it looks like gender\n const optionKeys = Object.keys(options);\n // It is gender if it has 'male' OR 'female' AND only contains gender keys (male, female, other)\n const isGender =\n (options.male || options.female) &&\n optionKeys.every((k) =>\n ['male', 'female', 'other', 'fallback'].includes(k)\n );\n\n if (isGender) {\n return gender({\n fallback: options.other,\n male: options.male,\n female: options.female,\n });\n }\n\n // Preserve variable name\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n }\n }\n\n // If multiple nodes, return array\n return nodes.map((node) => icuNodesToIntlayer([node]));\n};\n\nconst icuToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' &&\n (node.includes('{') ||\n node.includes('}') ||\n /<[a-zA-Z0-9-]+[^>]*>/.test(node)),\n transform: (node: any) => {\n try {\n const ast = parseICU(node);\n return icuNodesToIntlayer(ast);\n } catch {\n // If parsing fails, return original string\n return node;\n }\n },\n};\n\nconst intlayerToIcuPlugin = {\n canHandle: (node: any) =>\n (typeof node === 'string' && (node.includes('{') || node.includes('}'))) ||\n (node &&\n typeof node === 'object' &&\n (node.nodeType === NodeType.Insertion ||\n node.nodeType === NodeType.HTML ||\n node.nodeType === NodeType.Enumeration ||\n node.nodeType === NodeType.Gender ||\n node.nodeType === 'composite')) ||\n Array.isArray(node),\n transform: (node: any, props: any, next: any) => {\n // Convert Intlayer's double-brace format {{var}} to ICU's single-brace format {var}\n if (typeof node === 'string') {\n return node.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeType.Insertion) {\n // Convert Intlayer format to ICU format:\n // - {{name}} → {name} (simple variable)\n // - {amount, number, currency} → {amount, number, currency} (formatted variable, already in ICU format)\n return node.insertion.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeType.HTML) {\n return node.html;\n }\n\n if (node.nodeType === NodeType.Enumeration) {\n const options = node.enumeration;\n\n // Transform all values first\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (key === '__intlayer_icu_var') continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n // Infer variable name\n let varName = options.__intlayer_icu_var || 'n';\n\n if (!options.__intlayer_icu_var) {\n const fallbackVal =\n transformedOptions.fallback ||\n transformedOptions.other ||\n Object.values(transformedOptions)[0];\n // Match {variable} but avoid {variable, ...} (which are nested ICUs)\n // Actually nested ICU starts with {var, ...\n // Simple variable is {var}\n // We look for {var} that is NOT followed by ,\n const match = fallbackVal.match(/\\{([a-zA-Z0-9_]+)\\}(?!,)/);\n if (match) {\n varName = match[1];\n }\n }\n\n const keys = Object.keys(transformedOptions);\n const pluralKeys = [\n '1',\n '2',\n '<=3',\n '>=4',\n 'fallback',\n 'other',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n ];\n // Also check for numbers\n const isPlural = keys.every(\n (k) => pluralKeys.includes(k) || /^[<>=]?\\d+(\\.\\d+)?$/.test(k)\n );\n\n const parts = [];\n\n if (isPlural) {\n for (const [key, val] of Object.entries(transformedOptions)) {\n let icuKey = key;\n\n if (key === 'fallback') icuKey = 'other';\n else if (key === '<=3') icuKey = 'few';\n else if (key === '>=4') icuKey = 'many';\n else if (/^\\d+$/.test(key)) icuKey = `=${key}`;\n else if (['zero', 'few', 'many'].includes(key)) icuKey = key;\n else icuKey = 'other';\n\n let strVal = val;\n\n // Replace {varName} with #\n // Note: next() has already converted {{var}} -> {var}\n strVal = strVal.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), '#');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n\n return `{${varName}, plural, ${parts.join(' ')}}`;\n } else {\n // Select\n const entries = Object.entries(transformedOptions).sort(\n ([keyA], [keyB]) => {\n if (keyA === 'fallback' || keyA === 'other') return 1;\n if (keyB === 'fallback' || keyB === 'other') return -1;\n return 0;\n }\n );\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n // Do NOT map other keys to 'other'. Keep 'active', 'inactive', etc.\n\n parts.push(`${icuKey} {${val}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n }\n\n if (node.nodeType === NodeType.Gender) {\n const options = node.gender;\n const varName = 'gender';\n const parts = [];\n\n const entries = Object.entries(options).sort(([keyA], [keyB]) => {\n if (keyA === 'fallback') return 1;\n if (keyB === 'fallback') return -1;\n return 0;\n });\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n const childVal = next(val, props);\n const strVal =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n // handle array/composite\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToICUFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'icu',\n keyPath: [],\n plugins: [{ id: 'icu', ...intlayerToIcuPlugin }],\n });\n};\n\nexport const icuToIntlayerFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'icu',\n keyPath: [],\n plugins: [{ id: 'icu', ...icuToIntlayerPlugin }],\n });\n};\n"],"mappings":"sWAoDA,MAAM,EAAY,GAA4B,CAC5C,IAAI,EAAQ,EAEN,MAA8B,CAClC,IAAM,EAAmB,EAAE,CACvB,EAAc,GAElB,KAAO,EAAQ,EAAK,QAAQ,CAC1B,IAAM,EAAO,EAAK,GAElB,GAAI,IAAS,IACX,AAEE,KADA,EAAM,KAAK,EAAY,CACT,IAEhB,IACA,EAAM,KAAK,GAAe,CAAC,SAClB,IAAS,IAElB,cACS,IAAS,IAElB,GAAI,EAAQ,EAAI,EAAK,QAAU,EAAK,EAAQ,KAAO,IACjD,GAAe,IACf,GAAS,MACJ,CAEL,IAAM,EAAY,EAAK,QAAQ,IAAK,EAAQ,EAAE,CAC1C,IAAc,IAUhB,GAAe,IACf,MAJA,GAAe,EAAK,UAAU,EAAQ,EAAG,EAAU,CACnD,EAAQ,EAAY,QAOxB,GAAe,EACf,IAOJ,OAHI,GACF,EAAM,KAAK,EAAY,C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AAM,QAAQ,EAAK,UAAU,EAGnD,MAAM,QAAQ,EAAK,CAAG,EAAO,EAAK,WAC5B,IAAK,GAAc,EAAK,EAAM,EAAM,CAAC,CAC1C,KAAK,GAAG,CAGhB,EAAK,EAAM,EAAM,EAE3B,CAEY,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,MACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,MAAO,GAAG,EAAqB,CAAC,CACjD,CAAC,CAGS,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,MACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,MAAO,GAAG,EAAqB,CAAC,CACjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"ICU.mjs","names":["insert","enu"],"sources":["../../../src/messageFormat/ICU.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';;\nimport { NodeType } from '@intlayer/types/nodeType';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, gender, html, insert } from '../transpiler';\n\n/**\n * ICU MessageFormat Converter\n *\n * This module converts between ICU MessageFormat and Intlayer's internal format.\n *\n * IMPORTANT: Two different formats are used:\n *\n * 1. ICU MessageFormat (external format):\n * - Simple variables: {name}\n * - Formatted variables: {amount, number, currency}\n * - Plural: {count, plural, =0 {none} other {# items}}\n * - Select: {gender, select, male {He} female {She} other {They}}\n *\n * 2. Intlayer Internal Format:\n * - Simple variables: {{name}} (double braces for clarity and to distinguish from literal text)\n * - Formatted variables: {amount, number, currency} (keeps ICU format)\n * - Plural: enu({ 0: 'none', fallback: '{{count}} items' })\n * - Select/Gender: gender({ male: 'He', female: 'She', fallback: 'They' })\n *\n * Conversion flow:\n * - ICU → Intlayer: {name} → {{name}}\n * - Intlayer → ICU: {{name}} → {name}\n *\n * The double braces in Intlayer format serve to:\n * - Distinguish variables from literal text containing braces\n * - Work with getInsertion() runtime function which expects {{var}} patterns\n * - Provide clear visual distinction in content dictionaries\n */\n\n// Types for our AST\ntype ICUNode =\n | string\n | {\n type: 'argument';\n name: string;\n format?: { type: string; style?: string };\n }\n | { type: 'plural'; name: string; options: Record<string, ICUNode[]> }\n | { type: 'select'; name: string; options: Record<string, ICUNode[]> };\n\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue };\n\nconst parseICU = (text: string): ICUNode[] => {\n let index = 0;\n\n const parseNodes = (): ICUNode[] => {\n const nodes: ICUNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n nodes.push(parseArgument());\n } else if (char === '}') {\n // End of current block\n break;\n } else if (char === \"'\") {\n // Escaping\n if (index + 1 < text.length && text[index + 1] === \"'\") {\n currentText += \"'\";\n index += 2;\n } else {\n // Find next quote\n const nextQuote = text.indexOf(\"'\", index + 1);\n if (nextQuote !== -1) {\n // Determine if this is escaping syntax characters\n // For simplicity, we'll treat content between single quotes as literal\n // provided it contains syntax chars.\n // Standard ICU: ' quoted string '\n // If it is just an apostrophe, it should be doubled.\n // But simplified: take content between quotes literally.\n currentText += text.substring(index + 1, nextQuote);\n index = nextQuote + 1;\n } else {\n currentText += \"'\";\n index++;\n }\n }\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n return nodes;\n };\n\n const parseArgument = (): ICUNode => {\n // We are past '{'\n // Parse name\n let name = '';\n while (index < text.length && /[^,}]/.test(text[index])) {\n name += text[index];\n index++;\n }\n name = name.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name };\n }\n\n // Must be comma\n if (text[index] === ',') {\n index++;\n // Parse type\n let type = '';\n while (index < text.length && /[^,}]/.test(text[index])) {\n type += text[index];\n index++;\n }\n type = type.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name, format: { type } };\n }\n\n if (text[index] === ',') {\n index++;\n\n // If plural or select, parse options\n if (type === 'plural' || type === 'select') {\n // Parse options\n const options: Record<string, ICUNode[]> = {};\n\n while (index < text.length && text[index] !== '}') {\n // skip whitespace\n while (index < text.length && /\\s/.test(text[index])) index++;\n\n // parse key\n let key = '';\n while (index < text.length && /[^{\\s]/.test(text[index])) {\n key += text[index];\n index++;\n }\n\n while (index < text.length && /\\s/.test(text[index])) index++;\n\n if (text[index] !== '{')\n throw new Error('Expected { after option key');\n index++; // skip {\n\n const value = parseNodes();\n\n if (text[index] !== '}')\n throw new Error('Expected } after option value');\n index++; // skip }\n\n options[key] = value;\n\n while (index < text.length && /\\s/.test(text[index])) index++;\n }\n\n index++; // skip closing argument }\n\n if (type === 'plural') {\n return { type: 'plural', name, options };\n } else if (type === 'select') {\n return { type: 'select', name, options };\n }\n } else {\n // Parse style for number/date/time\n let style = '';\n while (index < text.length && text[index] !== '}') {\n style += text[index];\n index++;\n }\n if (index >= text.length) throw new Error('Unclosed argument');\n\n style = style.trim();\n index++; // skip }\n\n return { type: 'argument', name, format: { type, style } };\n }\n }\n }\n\n throw new Error('Malformed argument');\n };\n\n return parseNodes();\n};\n\nconst icuNodesToIntlayer = (nodes: ICUNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') {\n const node = nodes[0];\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n\n // Check if we can flatten to a single string (insert)\n const canFlatten = nodes.every(\n (node) => typeof node === 'string' || node.type === 'argument'\n );\n if (canFlatten) {\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else if (typeof node !== 'string' && node.type === 'argument') {\n if (node.format) {\n // Formatted variables keep ICU format: {var, type, style}\n str += `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`;\n } else {\n // Simple variables use Intlayer format: {{var}}\n str += `{{${node.name}}}`;\n }\n }\n }\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(str)) {\n return html(str);\n }\n return insert(str);\n }\n\n // Mix of string and complex types.\n // If we have just one complex type and it covers everything?\n if (nodes.length === 1) {\n const node = nodes[0];\n\n if (typeof node === 'string') {\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n if (node.type === 'argument') {\n if (node.format) {\n return insert(\n `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`\n );\n }\n return insert(`{{${node.name}}}`);\n }\n if (node.type === 'plural') {\n const options: Record<string, any> = {};\n\n for (const [key, val] of Object.entries(node.options)) {\n // Map ICU keys to Intlayer keys\n let newKey = key;\n if (key.startsWith('=')) {\n newKey = key.substring(1); // =0 -> 0\n } else if (key === 'one') {\n newKey = '1';\n } else if (key === 'two') {\n newKey = '2';\n } else if (key === 'few') {\n newKey = '<=3';\n } else if (key === 'many') {\n newKey = '>=4';\n } else if (key === 'other') {\n newKey = 'fallback';\n }\n // Handle # in plural value\n // For plural, we need to pass the variable name down or replace #\n // Intlayer uses {{n}} (or whatever var name) for simple variables\n // We should replace # with {{n}} in the string parts of val\n const replacedVal = val.map((v) => {\n if (typeof v === 'string') {\n return v.replace(/#/g, `{{${node.name}}}`);\n }\n return v;\n });\n\n options[newKey] = icuNodesToIntlayer(replacedVal);\n }\n\n // Preserve variable name\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n }\n if (node.type === 'select') {\n const options: Record<string, any> = {};\n\n for (const [key, val] of Object.entries(node.options)) {\n options[key] = icuNodesToIntlayer(val);\n }\n\n // Check if it looks like gender\n const optionKeys = Object.keys(options);\n // It is gender if it has 'male' OR 'female' AND only contains gender keys (male, female, other)\n const isGender =\n (options.male || options.female) &&\n optionKeys.every((k) =>\n ['male', 'female', 'other', 'fallback'].includes(k)\n );\n\n if (isGender) {\n return gender({\n fallback: options.other,\n male: options.male,\n female: options.female,\n });\n }\n\n // Preserve variable name\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n }\n }\n\n // If multiple nodes, return array\n return nodes.map((node) => icuNodesToIntlayer([node]));\n};\n\nconst icuToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' &&\n (node.includes('{') ||\n node.includes('}') ||\n /<[a-zA-Z0-9-]+[^>]*>/.test(node)),\n transform: (node: any) => {\n try {\n const ast = parseICU(node);\n return icuNodesToIntlayer(ast);\n } catch {\n // If parsing fails, return original string\n return node;\n }\n },\n};\n\nconst intlayerToIcuPlugin = {\n canHandle: (node: any) =>\n (typeof node === 'string' && (node.includes('{') || node.includes('}'))) ||\n (node &&\n typeof node === 'object' &&\n (node.nodeType === NodeType.Insertion ||\n node.nodeType === NodeType.HTML ||\n node.nodeType === NodeType.Enumeration ||\n node.nodeType === NodeType.Gender ||\n node.nodeType === 'composite')) ||\n Array.isArray(node),\n transform: (node: any, props: any, next: any) => {\n // Convert Intlayer's double-brace format {{var}} to ICU's single-brace format {var}\n if (typeof node === 'string') {\n return node.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeType.Insertion) {\n // Convert Intlayer format to ICU format:\n // - {{name}} → {name} (simple variable)\n // - {amount, number, currency} → {amount, number, currency} (formatted variable, already in ICU format)\n return node.insertion.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeType.HTML) {\n return node.html;\n }\n\n if (node.nodeType === NodeType.Enumeration) {\n const options = node.enumeration;\n\n // Transform all values first\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (key === '__intlayer_icu_var') continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n // Infer variable name\n let varName = options.__intlayer_icu_var || 'n';\n\n if (!options.__intlayer_icu_var) {\n const fallbackVal =\n transformedOptions.fallback ||\n transformedOptions.other ||\n Object.values(transformedOptions)[0];\n // Match {variable} but avoid {variable, ...} (which are nested ICUs)\n // Actually nested ICU starts with {var, ...\n // Simple variable is {var}\n // We look for {var} that is NOT followed by ,\n const match = fallbackVal.match(/\\{([a-zA-Z0-9_]+)\\}(?!,)/);\n if (match) {\n varName = match[1];\n }\n }\n\n const keys = Object.keys(transformedOptions);\n const pluralKeys = [\n '1',\n '2',\n '<=3',\n '>=4',\n 'fallback',\n 'other',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n ];\n // Also check for numbers\n const isPlural = keys.every(\n (k) => pluralKeys.includes(k) || /^[<>=]?\\d+(\\.\\d+)?$/.test(k)\n );\n\n const parts = [];\n\n if (isPlural) {\n for (const [key, val] of Object.entries(transformedOptions)) {\n let icuKey = key;\n\n if (key === 'fallback') icuKey = 'other';\n else if (key === '<=3') icuKey = 'few';\n else if (key === '>=4') icuKey = 'many';\n else if (/^\\d+$/.test(key)) icuKey = `=${key}`;\n else if (['zero', 'few', 'many'].includes(key)) icuKey = key;\n else icuKey = 'other';\n\n let strVal = val;\n\n // Replace {varName} with #\n // Note: next() has already converted {{var}} -> {var}\n strVal = strVal.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), '#');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n\n return `{${varName}, plural, ${parts.join(' ')}}`;\n } else {\n // Select\n const entries = Object.entries(transformedOptions).sort(\n ([keyA], [keyB]) => {\n if (keyA === 'fallback' || keyA === 'other') return 1;\n if (keyB === 'fallback' || keyB === 'other') return -1;\n return 0;\n }\n );\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n // Do NOT map other keys to 'other'. Keep 'active', 'inactive', etc.\n\n parts.push(`${icuKey} {${val}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n }\n\n if (node.nodeType === NodeType.Gender) {\n const options = node.gender;\n const varName = 'gender';\n const parts = [];\n\n const entries = Object.entries(options).sort(([keyA], [keyB]) => {\n if (keyA === 'fallback') return 1;\n if (keyB === 'fallback') return -1;\n return 0;\n });\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n const childVal = next(val, props);\n const strVal =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n // handle array/composite\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToICUFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'icu',\n keyPath: [],\n plugins: [{ id: 'icu', ...intlayerToIcuPlugin }],\n });\n};\n\nexport const icuToIntlayerFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'icu',\n keyPath: [],\n plugins: [{ id: 'icu', ...icuToIntlayerPlugin }],\n });\n};\n"],"mappings":"+WAqDA,MAAM,EAAY,GAA4B,CAC5C,IAAI,EAAQ,EAEN,MAA8B,CAClC,IAAM,EAAmB,EAAE,CACvB,EAAc,GAElB,KAAO,EAAQ,EAAK,QAAQ,CAC1B,IAAM,EAAO,EAAK,GAElB,GAAI,IAAS,IACX,AAEE,KADA,EAAM,KAAK,EAAY,CACT,IAEhB,IACA,EAAM,KAAK,GAAe,CAAC,SAClB,IAAS,IAElB,cACS,IAAS,IAElB,GAAI,EAAQ,EAAI,EAAK,QAAU,EAAK,EAAQ,KAAO,IACjD,GAAe,IACf,GAAS,MACJ,CAEL,IAAM,EAAY,EAAK,QAAQ,IAAK,EAAQ,EAAE,CAC1C,IAAc,IAUhB,GAAe,IACf,MAJA,GAAe,EAAK,UAAU,EAAQ,EAAG,EAAU,CACnD,EAAQ,EAAY,QAOxB,GAAe,EACf,IAOJ,OAHI,GACF,EAAM,KAAK,EAAY,CAElB,GAGH,MAA+B,CAGn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,EAGnD,MAAM,QAAQ,EAAK,CAAG,EAAO,EAAK,WAC5B,IAAK,GAAc,EAAK,EAAM,EAAM,CAAC,CAC1C,KAAK,GAAG,CAGhB,EAAK,EAAM,EAAM,EAE3B,CAEY,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,MACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,MAAO,GAAG,EAAqB,CAAC,CACjD,CAAC,CAGS,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,MACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,MAAO,GAAG,EAAqB,CAAC,CACjD,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{enu as t}from"../transpiler/enumeration/enumeration.mjs";import{gender as n}from"../transpiler/gender/gender.mjs";import{html as r}from"../transpiler/html/html.mjs";import{insert as i}from"../transpiler/insertion/insertion.mjs";import{NodeType as a}from"@intlayer/types";const o=e=>{let t=0,n=()=>{let n=[],a=``;for(;t<e.length;){let o=e[t];if(o===`{`&&e[t+1]===`{`)a&&=(n.push(a),``),t+=2,n.push(r());else if(o===`{`)a&&=(n.push(a),``),t++,n.push(i());else if(o===`}`)break;else a+=o,t++}return a&&n.push(a),n},r=()=>{let n=``;for(;t<e.length;){if(e[t]===`}`&&e[t+1]===`}`)return t+=2,{type:`argument`,name:n.trim()};n+=e[t],t++}throw Error(`Unclosed i18next variable`)},i=()=>{let r=``;for(;t<e.length&&/[^,}]/.test(e[t]);)r+=e[t],t++;if(r=r.trim(),t>=e.length)throw Error(`Unclosed argument`);if(e[t]===`}`)return t++,{type:`argument`,name:r};if(e[t]===`,`){t++;let i=``;for(;t<e.length&&/[^,}]/.test(e[t]);)i+=e[t],t++;if(i=i.trim(),t>=e.length)throw Error(`Unclosed argument`);if(e[t]===`}`)return t++,{type:`argument`,name:r,format:{type:i}};if(e[t]===`,`)if(t++,i===`plural`||i===`select`){let a={};for(;t<e.length&&e[t]!==`}`;){for(;t<e.length&&/\s/.test(e[t]);)t++;let r=``;for(;t<e.length&&/[^{\s]/.test(e[t]);)r+=e[t],t++;for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]!==`{`)throw Error(`Expected { after option key`);t++;let i=n();if(e[t]!==`}`)throw Error(`Expected } after option value`);for(t++,a[r]=i;t<e.length&&/\s/.test(e[t]);)t++}if(t++,i===`plural`)return{type:`plural`,name:r,options:a};if(i===`select`)return{type:`select`,name:r,options:a}}else{let n=``;for(;t<e.length&&e[t]!==`}`;)n+=e[t],t++;if(t>=e.length)throw Error(`Unclosed argument`);return n=n.trim(),t++,{type:`argument`,name:r,format:{type:i,style:n}}}}throw Error(`Malformed argument`)};return n()},s=e=>{if(e.length===0)return``;if(e.length===1&&typeof e[0]==`string`){let t=e[0];return/<[a-zA-Z0-9-]+[^>]*>/.test(t)?r(t):t}if(e.every(e=>typeof e==`string`||e.type===`argument`)){let t=``;for(let n of e)typeof n==`string`?t+=n:typeof n!=`string`&&n.type===`argument`&&(n.format?t+=`{${n.name}, ${n.format.type}${n.format.style?`, ${n.format.style}`:``}}`:t+=`{{${n.name}}}`);return/<[a-zA-Z0-9-]+[^>]*>/.test(t)?r(t):i(t)}if(e.length===1){let a=e[0];if(typeof a==`string`)return/<[a-zA-Z0-9-]+[^>]*>/.test(a)?r(a):a;if(a.type===`argument`)return a.format?i(`{${a.name}, ${a.format.type}${a.format.style?`, ${a.format.style}`:``}}`):i(`{{${a.name}}}`);if(a.type===`plural`){let e={};for(let[t,n]of Object.entries(a.options)){let r=t;t.startsWith(`=`)?r=t.substring(1):t===`one`?r=`1`:t===`two`?r=`2`:t===`few`?r=`<=3`:t===`many`?r=`>=4`:t===`other`&&(r=`fallback`),e[r]=s(n.map(e=>typeof e==`string`?e.replace(/#/g,`{{${a.name}}}`):e))}return e.__intlayer_icu_var=a.name,t(e)}if(a.type===`select`){let e={};for(let[t,n]of Object.entries(a.options))e[t]=s(n);let r=Object.keys(e);return(e.male||e.female)&&r.every(e=>[`male`,`female`,`other`,`fallback`].includes(e))?n({fallback:e.other,male:e.male,female:e.female}):(e.__intlayer_icu_var=a.name,t(e))}}return e.map(e=>s([e]))},c={canHandle:e=>typeof e==`string`&&(e.includes(`{`)||e.includes(`}`)||/<[a-zA-Z0-9-]+[^>]*>/.test(e)),transform:e=>{try{return s(o(e))}catch{return e}}},l={canHandle:e=>typeof e==`string`||e&&typeof e==`object`&&(e.nodeType===a.Insertion||e.nodeType===a.HTML||e.nodeType===a.Enumeration||e.nodeType===a.Gender||e.nodeType===`composite`)||Array.isArray(e),transform:(e,t,n)=>{if(typeof e==`string`)return e;if(e.nodeType===a.Insertion)return e.insertion.match(/\{[^}]*,[^}]*\}/),e.insertion;if(e.nodeType===a.HTML)return e.html;if(e.nodeType===a.Enumeration){let r=e.enumeration,i={};for(let[e,a]of Object.entries(r)){if(e===`__intlayer_icu_var`)continue;let r=n(a,t);i[e]=typeof r==`string`?r:JSON.stringify(r)}let a=r.__intlayer_icu_var||`count`;if(!r.__intlayer_icu_var){let e=i.fallback||i.other||Object.values(i)[0],t=e.match(/\{\{([a-zA-Z0-9_]+)\}\}/)||e.match(/\{([a-zA-Z0-9_]+)\}(?!,)/);t&&(a=t[1])}let o=Object.keys(i),s=[`1`,`2`,`<=3`,`>=4`,`fallback`,`other`,`zero`,`one`,`two`,`few`,`many`],c=o.every(e=>s.includes(e)||/^[<>=]?\d+(\.\d+)?$/.test(e)),l=[];if(c){for(let[e,t]of Object.entries(i)){let n=e;e===`fallback`?n=`other`:e===`<=3`?n=`few`:e===`>=4`?n=`many`:/^\d+$/.test(e)&&(n=`=${e}`);let r=t;r=r.replace(/\{\{([^}]+)\}\}/g,`{$1}`),r=r.replace(RegExp(`\\{${a}\\}`,`g`),`#`),l.push(`${n} {${r}}`)}return`{${a}, plural, ${l.join(` `)}}`}else{let e=Object.entries(i).sort(([e],[t])=>e===`fallback`||e===`other`?1:t===`fallback`||t===`other`?-1:0);for(let[t,n]of e){let e=t;t===`fallback`&&(e=`other`);let r=n;r=r.replace(/\{\{([^}]+)\}\}/g,`{$1}`),l.push(`${e} {${r}}`)}return`{${a}, select, ${l.join(` `)}}`}}if(e.nodeType===a.Gender){let r=e.gender,i=[],a=Object.entries(r).sort(([e],[t])=>e===`fallback`?1:t===`fallback`?-1:0);for(let[e,r]of a){let a=e;e===`fallback`&&(a=`other`);let o=n(r,t),s=typeof o==`string`?o:JSON.stringify(o);s=s.replace(/\{\{([^}]+)\}\}/g,`{$1}`),i.push(`${a} {${s}}`)}return`{gender, select, ${i.join(` `)}}`}return Array.isArray(e)||e.nodeType===`composite`&&Array.isArray(e.composite)?(Array.isArray(e)?e:e.composite).map(e=>n(e,t)).join(``):n(e,t)}},u=t=>e(t,{dictionaryKey:`i18next`,keyPath:[],plugins:[{id:`i18next`,...l}]}),d=t=>e(t,{dictionaryKey:`i18next`,keyPath:[],plugins:[{id:`i18next`,...c}]});export{d as i18nextToIntlayerFormatter,u as intlayerToI18nextFormatter};
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{enu as t}from"../transpiler/enumeration/enumeration.mjs";import{gender as n}from"../transpiler/gender/gender.mjs";import{html as r}from"../transpiler/html/html.mjs";import{insert as i}from"../transpiler/insertion/insertion.mjs";import{NodeType as a}from"@intlayer/types/nodeType";const o=e=>{let t=0,n=()=>{let n=[],a=``;for(;t<e.length;){let o=e[t];if(o===`{`&&e[t+1]===`{`)a&&=(n.push(a),``),t+=2,n.push(r());else if(o===`{`)a&&=(n.push(a),``),t++,n.push(i());else if(o===`}`)break;else a+=o,t++}return a&&n.push(a),n},r=()=>{let n=``;for(;t<e.length;){if(e[t]===`}`&&e[t+1]===`}`)return t+=2,{type:`argument`,name:n.trim()};n+=e[t],t++}throw Error(`Unclosed i18next variable`)},i=()=>{let r=``;for(;t<e.length&&/[^,}]/.test(e[t]);)r+=e[t],t++;if(r=r.trim(),t>=e.length)throw Error(`Unclosed argument`);if(e[t]===`}`)return t++,{type:`argument`,name:r};if(e[t]===`,`){t++;let i=``;for(;t<e.length&&/[^,}]/.test(e[t]);)i+=e[t],t++;if(i=i.trim(),t>=e.length)throw Error(`Unclosed argument`);if(e[t]===`}`)return t++,{type:`argument`,name:r,format:{type:i}};if(e[t]===`,`)if(t++,i===`plural`||i===`select`){let a={};for(;t<e.length&&e[t]!==`}`;){for(;t<e.length&&/\s/.test(e[t]);)t++;let r=``;for(;t<e.length&&/[^{\s]/.test(e[t]);)r+=e[t],t++;for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]!==`{`)throw Error(`Expected { after option key`);t++;let i=n();if(e[t]!==`}`)throw Error(`Expected } after option value`);for(t++,a[r]=i;t<e.length&&/\s/.test(e[t]);)t++}if(t++,i===`plural`)return{type:`plural`,name:r,options:a};if(i===`select`)return{type:`select`,name:r,options:a}}else{let n=``;for(;t<e.length&&e[t]!==`}`;)n+=e[t],t++;if(t>=e.length)throw Error(`Unclosed argument`);return n=n.trim(),t++,{type:`argument`,name:r,format:{type:i,style:n}}}}throw Error(`Malformed argument`)};return n()},s=e=>{if(e.length===0)return``;if(e.length===1&&typeof e[0]==`string`){let t=e[0];return/<[a-zA-Z0-9-]+[^>]*>/.test(t)?r(t):t}if(e.every(e=>typeof e==`string`||e.type===`argument`)){let t=``;for(let n of e)typeof n==`string`?t+=n:typeof n!=`string`&&n.type===`argument`&&(n.format?t+=`{${n.name}, ${n.format.type}${n.format.style?`, ${n.format.style}`:``}}`:t+=`{{${n.name}}}`);return/<[a-zA-Z0-9-]+[^>]*>/.test(t)?r(t):i(t)}if(e.length===1){let a=e[0];if(typeof a==`string`)return/<[a-zA-Z0-9-]+[^>]*>/.test(a)?r(a):a;if(a.type===`argument`)return a.format?i(`{${a.name}, ${a.format.type}${a.format.style?`, ${a.format.style}`:``}}`):i(`{{${a.name}}}`);if(a.type===`plural`){let e={};for(let[t,n]of Object.entries(a.options)){let r=t;t.startsWith(`=`)?r=t.substring(1):t===`one`?r=`1`:t===`two`?r=`2`:t===`few`?r=`<=3`:t===`many`?r=`>=4`:t===`other`&&(r=`fallback`),e[r]=s(n.map(e=>typeof e==`string`?e.replace(/#/g,`{{${a.name}}}`):e))}return e.__intlayer_icu_var=a.name,t(e)}if(a.type===`select`){let e={};for(let[t,n]of Object.entries(a.options))e[t]=s(n);let r=Object.keys(e);return(e.male||e.female)&&r.every(e=>[`male`,`female`,`other`,`fallback`].includes(e))?n({fallback:e.other,male:e.male,female:e.female}):(e.__intlayer_icu_var=a.name,t(e))}}return e.map(e=>s([e]))},c={canHandle:e=>typeof e==`string`&&(e.includes(`{`)||e.includes(`}`)||/<[a-zA-Z0-9-]+[^>]*>/.test(e)),transform:e=>{try{return s(o(e))}catch{return e}}},l={canHandle:e=>typeof e==`string`||e&&typeof e==`object`&&(e.nodeType===a.Insertion||e.nodeType===a.HTML||e.nodeType===a.Enumeration||e.nodeType===a.Gender||e.nodeType===`composite`)||Array.isArray(e),transform:(e,t,n)=>{if(typeof e==`string`)return e;if(e.nodeType===a.Insertion)return e.insertion.match(/\{[^}]*,[^}]*\}/),e.insertion;if(e.nodeType===a.HTML)return e.html;if(e.nodeType===a.Enumeration){let r=e.enumeration,i={};for(let[e,a]of Object.entries(r)){if(e===`__intlayer_icu_var`)continue;let r=n(a,t);i[e]=typeof r==`string`?r:JSON.stringify(r)}let a=r.__intlayer_icu_var||`count`;if(!r.__intlayer_icu_var){let e=i.fallback||i.other||Object.values(i)[0],t=e.match(/\{\{([a-zA-Z0-9_]+)\}\}/)||e.match(/\{([a-zA-Z0-9_]+)\}(?!,)/);t&&(a=t[1])}let o=Object.keys(i),s=[`1`,`2`,`<=3`,`>=4`,`fallback`,`other`,`zero`,`one`,`two`,`few`,`many`],c=o.every(e=>s.includes(e)||/^[<>=]?\d+(\.\d+)?$/.test(e)),l=[];if(c){for(let[e,t]of Object.entries(i)){let n=e;e===`fallback`?n=`other`:e===`<=3`?n=`few`:e===`>=4`?n=`many`:/^\d+$/.test(e)&&(n=`=${e}`);let r=t;r=r.replace(/\{\{([^}]+)\}\}/g,`{$1}`),r=r.replace(RegExp(`\\{${a}\\}`,`g`),`#`),l.push(`${n} {${r}}`)}return`{${a}, plural, ${l.join(` `)}}`}else{let e=Object.entries(i).sort(([e],[t])=>e===`fallback`||e===`other`?1:t===`fallback`||t===`other`?-1:0);for(let[t,n]of e){let e=t;t===`fallback`&&(e=`other`);let r=n;r=r.replace(/\{\{([^}]+)\}\}/g,`{$1}`),l.push(`${e} {${r}}`)}return`{${a}, select, ${l.join(` `)}}`}}if(e.nodeType===a.Gender){let r=e.gender,i=[],a=Object.entries(r).sort(([e],[t])=>e===`fallback`?1:t===`fallback`?-1:0);for(let[e,r]of a){let a=e;e===`fallback`&&(a=`other`);let o=n(r,t),s=typeof o==`string`?o:JSON.stringify(o);s=s.replace(/\{\{([^}]+)\}\}/g,`{$1}`),i.push(`${a} {${s}}`)}return`{gender, select, ${i.join(` `)}}`}return Array.isArray(e)||e.nodeType===`composite`&&Array.isArray(e.composite)?(Array.isArray(e)?e:e.composite).map(e=>n(e,t)).join(``):n(e,t)}},u=t=>e(t,{dictionaryKey:`i18next`,keyPath:[],plugins:[{id:`i18next`,...l}]}),d=t=>e(t,{dictionaryKey:`i18next`,keyPath:[],plugins:[{id:`i18next`,...c}]});export{d as i18nextToIntlayerFormatter,u as intlayerToI18nextFormatter};
|
|
2
2
|
//# sourceMappingURL=i18next.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18next.mjs","names":["insert","enu"],"sources":["../../../src/messageFormat/i18next.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\nimport { NodeType } from '@intlayer/types';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, gender, html, insert } from '../transpiler';\nimport type { JsonValue } from './ICU';\n\n// Types for our AST\ntype I18NextNode =\n | string\n | {\n type: 'argument';\n name: string;\n format?: { type: string; style?: string };\n }\n | { type: 'plural'; name: string; options: Record<string, I18NextNode[]> }\n | { type: 'select'; name: string; options: Record<string, I18NextNode[]> };\n\nconst parseI18Next = (text: string): I18NextNode[] => {\n let index = 0;\n\n const parseNodes = (): I18NextNode[] => {\n const nodes: I18NextNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n // Standard i18next variable: {{var}}\n if (char === '{' && text[index + 1] === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index += 2; // skip {{\n nodes.push(parseStandardArgument());\n }\n // ICU syntax: {var} or {var, plural, ...}\n else if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n nodes.push(parseICUArgument());\n } else if (char === '}') {\n // End of current block (likely ICU block end)\n break;\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n return nodes;\n };\n\n const parseStandardArgument = (): I18NextNode => {\n // We are past '{{'\n let name = '';\n while (index < text.length) {\n // Check for closing }}\n if (text[index] === '}' && text[index + 1] === '}') {\n index += 2; // skip }}\n return { type: 'argument', name: name.trim() };\n }\n name += text[index];\n index++;\n }\n throw new Error('Unclosed i18next variable');\n };\n\n const parseICUArgument = (): I18NextNode => {\n // We are past '{'\n let name = '';\n while (index < text.length && /[^,}]/.test(text[index])) {\n name += text[index];\n index++;\n }\n name = name.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name };\n }\n\n // Must be comma\n if (text[index] === ',') {\n index++;\n // Parse type\n let type = '';\n while (index < text.length && /[^,}]/.test(text[index])) {\n type += text[index];\n index++;\n }\n type = type.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name, format: { type } };\n }\n\n if (text[index] === ',') {\n index++;\n\n // If plural or select, parse options\n if (type === 'plural' || type === 'select') {\n const options: Record<string, I18NextNode[]> = {};\n\n while (index < text.length && text[index] !== '}') {\n while (index < text.length && /\\s/.test(text[index])) index++;\n\n let key = '';\n while (index < text.length && /[^{\\s]/.test(text[index])) {\n key += text[index];\n index++;\n }\n\n while (index < text.length && /\\s/.test(text[index])) index++;\n\n if (text[index] !== '{')\n throw new Error('Expected { after option key');\n index++; // skip {\n\n const value = parseNodes();\n\n if (text[index] !== '}')\n throw new Error('Expected } after option value');\n index++; // skip }\n\n options[key] = value;\n\n while (index < text.length && /\\s/.test(text[index])) index++;\n }\n\n index++; // skip closing argument }\n\n if (type === 'plural') {\n return { type: 'plural', name, options };\n } else if (type === 'select') {\n return { type: 'select', name, options };\n }\n } else {\n // Parse style for number/date/time\n let style = '';\n while (index < text.length && text[index] !== '}') {\n style += text[index];\n index++;\n }\n if (index >= text.length) throw new Error('Unclosed argument');\n\n style = style.trim();\n index++; // skip }\n\n return { type: 'argument', name, format: { type, style } };\n }\n }\n }\n\n throw new Error('Malformed argument');\n };\n\n return parseNodes();\n};\n\nconst i18nextNodesToIntlayer = (nodes: I18NextNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') {\n const node = nodes[0];\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n\n const canFlatten = nodes.every(\n (node) => typeof node === 'string' || node.type === 'argument'\n );\n\n if (canFlatten) {\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else if (typeof node !== 'string' && node.type === 'argument') {\n if (node.format) {\n // For formatted arguments, use ICU syntax: {name, type, style}\n str += `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`;\n } else {\n // For simple arguments, use standard i18next: {{name}}\n str += `{{${node.name}}}`;\n }\n }\n }\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(str)) {\n return html(str);\n }\n return insert(str);\n }\n\n if (nodes.length === 1) {\n const node = nodes[0];\n if (typeof node === 'string') {\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n\n if (node.type === 'argument') {\n if (node.format) {\n return insert(\n `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`\n );\n }\n return insert(`{{${node.name}}}`);\n }\n\n if (node.type === 'plural') {\n const options: Record<string, any> = {};\n for (const [key, val] of Object.entries(node.options)) {\n let newKey = key;\n if (key.startsWith('=')) {\n newKey = key.substring(1);\n } else if (key === 'one') {\n newKey = '1';\n } else if (key === 'two') {\n newKey = '2';\n } else if (key === 'few') {\n newKey = '<=3';\n } else if (key === 'many') {\n newKey = '>=4';\n } else if (key === 'other') {\n newKey = 'fallback';\n }\n // Handle # replacement\n const replacedVal = val.map((v) => {\n if (typeof v === 'string') {\n // In ICU plural, # is replaced by the number\n // In i18next, if using ICU plugin, it behaves same.\n // We map it to {{varName}} in Intlayer\n return v.replace(/#/g, `{{${node.name}}}`);\n }\n return v;\n });\n\n options[newKey] = i18nextNodesToIntlayer(replacedVal);\n }\n\n // Preserve variable name\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n }\n\n if (node.type === 'select') {\n const options: Record<string, any> = {};\n for (const [key, val] of Object.entries(node.options)) {\n options[key] = i18nextNodesToIntlayer(val);\n }\n\n // Check for gender\n const optionKeys = Object.keys(options);\n const isGender =\n (options.male || options.female) &&\n optionKeys.every((k) =>\n ['male', 'female', 'other', 'fallback'].includes(k)\n );\n\n if (isGender) {\n return gender({\n fallback: options.other,\n male: options.male,\n female: options.female,\n });\n }\n\n // Preserve variable name for generic select\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n }\n }\n\n return nodes.map((node) => i18nextNodesToIntlayer([node]));\n};\n\nconst i18nextToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' &&\n (node.includes('{') ||\n node.includes('}') ||\n /<[a-zA-Z0-9-]+[^>]*>/.test(node)),\n transform: (node: any) => {\n try {\n const ast = parseI18Next(node);\n return i18nextNodesToIntlayer(ast);\n } catch {\n return node;\n }\n },\n};\n\nconst intlayerToI18nextPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' ||\n (node &&\n typeof node === 'object' &&\n (node.nodeType === NodeType.Insertion ||\n node.nodeType === NodeType.HTML ||\n node.nodeType === NodeType.Enumeration ||\n node.nodeType === NodeType.Gender ||\n node.nodeType === 'composite')) ||\n Array.isArray(node),\n transform: (node: any, props: any, next: any) => {\n if (typeof node === 'string') {\n return node;\n }\n\n if (node.nodeType === NodeType.Insertion) {\n // If it contains ICU format syntax (curly braces but not double curly), keep it as is\n // But standard insert creates {{var}}.\n // Check if the original string was formatted (e.g. {val, number})\n if (node.insertion.match(/\\{[^}]*,[^}]*\\}/)) {\n // It's likely an ICU format string like {val, number}\n // We might need to ensure variables inside are not double-braced if they are part of the format\n // But wait, our parser outputs {val, number} as string for insertion.\n return node.insertion;\n }\n\n // Otherwise keep {{name}} for i18next\n return node.insertion;\n }\n\n if (node.nodeType === NodeType.HTML) {\n return node.html;\n }\n\n if (node.nodeType === NodeType.Enumeration) {\n const options = node.enumeration;\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (key === '__intlayer_icu_var') continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n // Infer variable name\n let varName = options.__intlayer_icu_var || 'count';\n\n if (!options.__intlayer_icu_var) {\n const fallbackVal =\n transformedOptions.fallback ||\n transformedOptions.other ||\n Object.values(transformedOptions)[0];\n\n // Search for {{var}} or {var}\n // Match {variable} but avoid {variable, ...} (which are nested ICUs)\n const match =\n fallbackVal.match(/\\{\\{([a-zA-Z0-9_]+)\\}\\}/) ||\n fallbackVal.match(/\\{([a-zA-Z0-9_]+)\\}(?!,)/);\n if (match) {\n varName = match[1];\n }\n }\n\n const keys = Object.keys(transformedOptions);\n const pluralKeys = [\n '1',\n '2',\n '<=3',\n '>=4',\n 'fallback',\n 'other',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n ];\n // Check if it is a plural\n const isPlural = keys.every(\n (k) => pluralKeys.includes(k) || /^[<>=]?\\d+(\\.\\d+)?$/.test(k)\n );\n\n const parts = [];\n\n if (isPlural) {\n for (const [key, val] of Object.entries(transformedOptions)) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n else if (key === '<=3') icuKey = 'few';\n else if (key === '>=4') icuKey = 'many';\n else if (/^\\d+$/.test(key)) icuKey = `=${key}`;\n\n let strVal = val;\n\n // Convert {{var}} to {var} inside ICU string\n // Also replace {varName} with # if it matches\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n strVal = strVal.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), '#');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, plural, ${parts.join(' ')}}`;\n } else {\n // Select\n const entries = Object.entries(transformedOptions).sort(\n ([keyA], [keyB]) => {\n if (keyA === 'fallback' || keyA === 'other') return 1;\n if (keyB === 'fallback' || keyB === 'other') return -1;\n return 0;\n }\n );\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n let strVal = val;\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n }\n\n if (node.nodeType === NodeType.Gender) {\n const options = node.gender;\n const varName = 'gender';\n const parts = [];\n\n const entries = Object.entries(options).sort(([keyA], [keyB]) => {\n if (keyA === 'fallback') return 1;\n if (keyB === 'fallback') return -1;\n return 0;\n });\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n const childVal = next(val, props);\n let strVal =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToI18nextFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'i18next',\n keyPath: [],\n plugins: [{ id: 'i18next', ...intlayerToI18nextPlugin }],\n });\n};\n\nexport const i18nextToIntlayerFormatter = (\n message: JsonValue\n): Dictionary['content'] => {\n return deepTransformNode(message, {\n dictionaryKey: 'i18next',\n keyPath: [],\n plugins: [{ id: 'i18next', ...i18nextToIntlayerPlugin }],\n });\n};\n"],"mappings":"sWAiBA,MAAM,EAAgB,GAAgC,CACpD,IAAI,EAAQ,EAEN,MAAkC,CACtC,IAAM,EAAuB,EAAE,CAC3B,EAAc,GAElB,KAAO,EAAQ,EAAK,QAAQ,CAC1B,IAAM,EAAO,EAAK,GAGlB,GAAI,IAAS,KAAO,EAAK,EAAQ,KAAO,IACtC,AAEE,KADA,EAAM,KAAK,EAAY,CACT,IAEhB,GAAS,EACT,EAAM,KAAK,GAAuB,CAAC,SAG5B,IAAS,IAChB,AAEE,KADA,EAAM,KAAK,EAAY,CACT,IAEhB,IACA,EAAM,KAAK,GAAkB,CAAC,SACrB,IAAS,IAElB,WAEA,GAAe,EACf,IAOJ,OAHI,GACF,EAAM,KAAK,EAAY,CAElB,GAGH,MAA2C,CAE/C,IAAI,EAAO,GACX,KAAO,EAAQ,EAAK,QAAQ,CAE1B,GAAI,EAAK,KAAW,KAAO,EAAK,EAAQ,KAAO,IAE7C,MADA,IAAS,EACF,CAAE,KAAM,WAAY,KAAM,EAAK,MAAM,CAAE,CAEhD,GAAQ,EAAK,GACb,IAEF,MAAU,MAAM,4BAA4B,EAGxC,MAAsC,CAE1C,IAAI,EAAO,GACX,KAAO,EAAQ,EAAK,QAAU,QAAQ,KAAK,EAAK,GAAO,EACrD,GAAQ,EAAK,GACb,IAIF,G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5B,IAAK,GAAc,EAAK,EAAM,EAAM,CAAC,CAC1C,KAAK,GAAG,CAGhB,EAAK,EAAM,EAAM,EAE3B,CAEY,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,UACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,UAAW,GAAG,EAAyB,CAAC,CACzD,CAAC,CAGS,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,UACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,UAAW,GAAG,EAAyB,CAAC,CACzD,CAAC"}
|
|
1
|
+
{"version":3,"file":"i18next.mjs","names":["insert","enu"],"sources":["../../../src/messageFormat/i18next.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, gender, html, insert } from '../transpiler';\nimport type { JsonValue } from './ICU';\n\n// Types for our AST\ntype I18NextNode =\n | string\n | {\n type: 'argument';\n name: string;\n format?: { type: string; style?: string };\n }\n | { type: 'plural'; name: string; options: Record<string, I18NextNode[]> }\n | { type: 'select'; name: string; options: Record<string, I18NextNode[]> };\n\nconst parseI18Next = (text: string): I18NextNode[] => {\n let index = 0;\n\n const parseNodes = (): I18NextNode[] => {\n const nodes: I18NextNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n // Standard i18next variable: {{var}}\n if (char === '{' && text[index + 1] === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index += 2; // skip {{\n nodes.push(parseStandardArgument());\n }\n // ICU syntax: {var} or {var, plural, ...}\n else if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n nodes.push(parseICUArgument());\n } else if (char === '}') {\n // End of current block (likely ICU block end)\n break;\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n return nodes;\n };\n\n const parseStandardArgument = (): I18NextNode => {\n // We are past '{{'\n let name = '';\n while (index < text.length) {\n // Check for closing }}\n if (text[index] === '}' && text[index + 1] === '}') {\n index += 2; // skip }}\n return { type: 'argument', name: name.trim() };\n }\n name += text[index];\n index++;\n }\n throw new Error('Unclosed i18next variable');\n };\n\n const parseICUArgument = (): I18NextNode => {\n // We are past '{'\n let name = '';\n while (index < text.length && /[^,}]/.test(text[index])) {\n name += text[index];\n index++;\n }\n name = name.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name };\n }\n\n // Must be comma\n if (text[index] === ',') {\n index++;\n // Parse type\n let type = '';\n while (index < text.length && /[^,}]/.test(text[index])) {\n type += text[index];\n index++;\n }\n type = type.trim();\n\n if (index >= text.length) throw new Error('Unclosed argument');\n\n if (text[index] === '}') {\n index++;\n return { type: 'argument', name, format: { type } };\n }\n\n if (text[index] === ',') {\n index++;\n\n // If plural or select, parse options\n if (type === 'plural' || type === 'select') {\n const options: Record<string, I18NextNode[]> = {};\n\n while (index < text.length && text[index] !== '}') {\n while (index < text.length && /\\s/.test(text[index])) index++;\n\n let key = '';\n while (index < text.length && /[^{\\s]/.test(text[index])) {\n key += text[index];\n index++;\n }\n\n while (index < text.length && /\\s/.test(text[index])) index++;\n\n if (text[index] !== '{')\n throw new Error('Expected { after option key');\n index++; // skip {\n\n const value = parseNodes();\n\n if (text[index] !== '}')\n throw new Error('Expected } after option value');\n index++; // skip }\n\n options[key] = value;\n\n while (index < text.length && /\\s/.test(text[index])) index++;\n }\n\n index++; // skip closing argument }\n\n if (type === 'plural') {\n return { type: 'plural', name, options };\n } else if (type === 'select') {\n return { type: 'select', name, options };\n }\n } else {\n // Parse style for number/date/time\n let style = '';\n while (index < text.length && text[index] !== '}') {\n style += text[index];\n index++;\n }\n if (index >= text.length) throw new Error('Unclosed argument');\n\n style = style.trim();\n index++; // skip }\n\n return { type: 'argument', name, format: { type, style } };\n }\n }\n }\n\n throw new Error('Malformed argument');\n };\n\n return parseNodes();\n};\n\nconst i18nextNodesToIntlayer = (nodes: I18NextNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') {\n const node = nodes[0];\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n\n const canFlatten = nodes.every(\n (node) => typeof node === 'string' || node.type === 'argument'\n );\n\n if (canFlatten) {\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else if (typeof node !== 'string' && node.type === 'argument') {\n if (node.format) {\n // For formatted arguments, use ICU syntax: {name, type, style}\n str += `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`;\n } else {\n // For simple arguments, use standard i18next: {{name}}\n str += `{{${node.name}}}`;\n }\n }\n }\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(str)) {\n return html(str);\n }\n return insert(str);\n }\n\n if (nodes.length === 1) {\n const node = nodes[0];\n if (typeof node === 'string') {\n if (/<[a-zA-Z0-9-]+[^>]*>/.test(node)) {\n return html(node);\n }\n return node;\n }\n\n if (node.type === 'argument') {\n if (node.format) {\n return insert(\n `{${node.name}, ${node.format.type}${\n node.format.style ? `, ${node.format.style}` : ''\n }}`\n );\n }\n return insert(`{{${node.name}}}`);\n }\n\n if (node.type === 'plural') {\n const options: Record<string, any> = {};\n for (const [key, val] of Object.entries(node.options)) {\n let newKey = key;\n if (key.startsWith('=')) {\n newKey = key.substring(1);\n } else if (key === 'one') {\n newKey = '1';\n } else if (key === 'two') {\n newKey = '2';\n } else if (key === 'few') {\n newKey = '<=3';\n } else if (key === 'many') {\n newKey = '>=4';\n } else if (key === 'other') {\n newKey = 'fallback';\n }\n // Handle # replacement\n const replacedVal = val.map((v) => {\n if (typeof v === 'string') {\n // In ICU plural, # is replaced by the number\n // In i18next, if using ICU plugin, it behaves same.\n // We map it to {{varName}} in Intlayer\n return v.replace(/#/g, `{{${node.name}}}`);\n }\n return v;\n });\n\n options[newKey] = i18nextNodesToIntlayer(replacedVal);\n }\n\n // Preserve variable name\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n }\n\n if (node.type === 'select') {\n const options: Record<string, any> = {};\n for (const [key, val] of Object.entries(node.options)) {\n options[key] = i18nextNodesToIntlayer(val);\n }\n\n // Check for gender\n const optionKeys = Object.keys(options);\n const isGender =\n (options.male || options.female) &&\n optionKeys.every((k) =>\n ['male', 'female', 'other', 'fallback'].includes(k)\n );\n\n if (isGender) {\n return gender({\n fallback: options.other,\n male: options.male,\n female: options.female,\n });\n }\n\n // Preserve variable name for generic select\n options.__intlayer_icu_var = node.name;\n\n return enu(options);\n }\n }\n\n return nodes.map((node) => i18nextNodesToIntlayer([node]));\n};\n\nconst i18nextToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' &&\n (node.includes('{') ||\n node.includes('}') ||\n /<[a-zA-Z0-9-]+[^>]*>/.test(node)),\n transform: (node: any) => {\n try {\n const ast = parseI18Next(node);\n return i18nextNodesToIntlayer(ast);\n } catch {\n return node;\n }\n },\n};\n\nconst intlayerToI18nextPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' ||\n (node &&\n typeof node === 'object' &&\n (node.nodeType === NodeType.Insertion ||\n node.nodeType === NodeType.HTML ||\n node.nodeType === NodeType.Enumeration ||\n node.nodeType === NodeType.Gender ||\n node.nodeType === 'composite')) ||\n Array.isArray(node),\n transform: (node: any, props: any, next: any) => {\n if (typeof node === 'string') {\n return node;\n }\n\n if (node.nodeType === NodeType.Insertion) {\n // If it contains ICU format syntax (curly braces but not double curly), keep it as is\n // But standard insert creates {{var}}.\n // Check if the original string was formatted (e.g. {val, number})\n if (node.insertion.match(/\\{[^}]*,[^}]*\\}/)) {\n // It's likely an ICU format string like {val, number}\n // We might need to ensure variables inside are not double-braced if they are part of the format\n // But wait, our parser outputs {val, number} as string for insertion.\n return node.insertion;\n }\n\n // Otherwise keep {{name}} for i18next\n return node.insertion;\n }\n\n if (node.nodeType === NodeType.HTML) {\n return node.html;\n }\n\n if (node.nodeType === NodeType.Enumeration) {\n const options = node.enumeration;\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (key === '__intlayer_icu_var') continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n // Infer variable name\n let varName = options.__intlayer_icu_var || 'count';\n\n if (!options.__intlayer_icu_var) {\n const fallbackVal =\n transformedOptions.fallback ||\n transformedOptions.other ||\n Object.values(transformedOptions)[0];\n\n // Search for {{var}} or {var}\n // Match {variable} but avoid {variable, ...} (which are nested ICUs)\n const match =\n fallbackVal.match(/\\{\\{([a-zA-Z0-9_]+)\\}\\}/) ||\n fallbackVal.match(/\\{([a-zA-Z0-9_]+)\\}(?!,)/);\n if (match) {\n varName = match[1];\n }\n }\n\n const keys = Object.keys(transformedOptions);\n const pluralKeys = [\n '1',\n '2',\n '<=3',\n '>=4',\n 'fallback',\n 'other',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n ];\n // Check if it is a plural\n const isPlural = keys.every(\n (k) => pluralKeys.includes(k) || /^[<>=]?\\d+(\\.\\d+)?$/.test(k)\n );\n\n const parts = [];\n\n if (isPlural) {\n for (const [key, val] of Object.entries(transformedOptions)) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n else if (key === '<=3') icuKey = 'few';\n else if (key === '>=4') icuKey = 'many';\n else if (/^\\d+$/.test(key)) icuKey = `=${key}`;\n\n let strVal = val;\n\n // Convert {{var}} to {var} inside ICU string\n // Also replace {varName} with # if it matches\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n strVal = strVal.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), '#');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, plural, ${parts.join(' ')}}`;\n } else {\n // Select\n const entries = Object.entries(transformedOptions).sort(\n ([keyA], [keyB]) => {\n if (keyA === 'fallback' || keyA === 'other') return 1;\n if (keyB === 'fallback' || keyB === 'other') return -1;\n return 0;\n }\n );\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n let strVal = val;\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n }\n\n if (node.nodeType === NodeType.Gender) {\n const options = node.gender;\n const varName = 'gender';\n const parts = [];\n\n const entries = Object.entries(options).sort(([keyA], [keyB]) => {\n if (keyA === 'fallback') return 1;\n if (keyB === 'fallback') return -1;\n return 0;\n });\n\n for (const [key, val] of entries) {\n let icuKey = key;\n if (key === 'fallback') icuKey = 'other';\n\n const childVal = next(val, props);\n let strVal =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n\n strVal = strVal.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n parts.push(`${icuKey} {${strVal}}`);\n }\n return `{${varName}, select, ${parts.join(' ')}}`;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToI18nextFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'i18next',\n keyPath: [],\n plugins: [{ id: 'i18next', ...intlayerToI18nextPlugin }],\n });\n};\n\nexport const i18nextToIntlayerFormatter = (\n message: JsonValue\n): Dictionary['content'] => {\n return deepTransformNode(message, {\n dictionaryKey: 'i18next',\n keyPath: [],\n plugins: [{ id: 'i18next', ...i18nextToIntlayerPlugin }],\n });\n};\n"],"mappings":"+WAiBA,MAAM,EAAgB,GAAgC,CACpD,IAAI,EAAQ,EAEN,MAAkC,CACtC,IAAM,EAAuB,EAAE,CAC3B,EAAc,GAElB,KAAO,EAAQ,EAAK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AO,IAAI,EAAQ,YAAY,EAAM,KAAK,IAAI,CAAC,IAInD,GAAI,EAAK,WAAa,EAAS,OAAQ,CACrC,IAAM,EAAU,EAAK,OAEf,EAAQ,EAAE,CAEV,EAAU,OAAO,QAAQ,EAAQ,CAAC,MAAM,CAAC,GAAO,CAAC,KACjD,IAAS,WAAmB,EAC5B,IAAS,WAAmB,GACzB,EACP,CAEF,IAAK,GAAM,CAAC,EAAK,KAAQ,EAAS,CAChC,IAAI,EAAS,EACT,IAAQ,aAAY,EAAS,SAEjC,IAAM,EAAW,EAAK,EAAK,EAAM,CAC7B,EACF,OAAO,GAAa,SAAW,EAAW,KAAK,UAAU,EAAS,CAEpE,EAAS,EAAO,QAAQ,mBAAoB,OAAO,CACnD,EAAM,KAAK,GAAG,EAAO,IAAI,EAAO,GAAG,CAErC,MAAO,oBAAwB,EAAM,KAAK,IAAI,CAAC,GAYjD,OARE,MAAM,QAAQ,EAAK,EAClB,EAAK,WAAa,aAAe,MAAM,QAAQ,EAAK,UAAU,EAEnD,MAAM,QAAQ,EAAK,CAAG,EAAO,EAAK,WAC5B,IAAK,GAAc,EAAK,EAAM,EAAM,CAAC,CAC1C,KAAK,GAAG,CAGhB,EAAK,EAAM,EAAM,EAE3B,CAEY,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,UACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,UAAW,GAAG,EAAyB,CAAC,CACzD,CAAC,CAGS,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,UACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,UAAW,GAAG,EAAyB,CAAC,CACzD,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{enu as t}from"../transpiler/enumeration/enumeration.mjs";import{insert as n}from"../transpiler/insertion/insertion.mjs";import{NodeType as r}from"@intlayer/types";const i=e=>{let t=0,n=[],r=``;for(;t<e.length;){let i=e[t];if(i===`{`){r&&=(n.push(r),``),t++;let i=``;for(;t<e.length&&e[t]!==`}`;)i+=e[t],t++;t<e.length&&t++,n.push({type:`argument`,name:i.trim()})}else r+=i,t++}return r&&n.push(r),n},a=e=>{let t=[],n=``,r=0;for(;r<e.length;){let i=e[r];i===`\\`&&r+1<e.length&&e[r+1]===`|`?(n+=`|`,r+=2):i===`|`?(t.push(n.trim()),n=``,r++):(n+=i,r++)}return t.push(n.trim()),t.map(i)},o=e=>{if(e.length===0)return``;if(e.length===1&&typeof e[0]==`string`)return e[0];let t=``;for(let n of e)typeof n==`string`?t+=n:t+=`{{${n.name}}}`;return n(t)},s=e=>{if(e.length===1)return o(e[0]);let n={};return e.length===2?(n[1]=o(e[0]),n.fallback=o(e[1])):e.length===3?(n[0]=o(e[0]),n[1]=o(e[1]),n.fallback=o(e[2])):e.forEach((t,r)=>{r===e.length-1?n.fallback=o(t):n[r.toString()]=o(t)}),n.__intlayer_vue_i18n_var=`count`,t(n)},c={canHandle:e=>typeof e==`string`&&(e.includes(`{`)||e.includes(`|`)),transform:e=>{try{return s(a(e))}catch{return e}}},l={canHandle:e=>typeof e==`string`||e&&typeof e==`object`&&(e.nodeType===r.Insertion||e.nodeType===r.Enumeration||e.nodeType===r.Gender||e.nodeType===`composite`)||Array.isArray(e),transform:(e,t,n)=>{if(typeof e==`string`)return e.replace(/\{\{([^}]+)\}\}/g,`{$1}`);if(e.nodeType===r.Insertion)return e.insertion.replace(/\{\{([^}]+)\}\}/g,`{$1}`);if(e.nodeType===r.Enumeration){let r=e.enumeration,i={};for(let[e,a]of Object.entries(r)){if(e===`__intlayer_vue_i18n_var`)continue;let r=n(a,t);i[e]=typeof r==`string`?r:JSON.stringify(r)}let a=Object.keys(i);if(a.includes(`0`)){let e=a.filter(e=>/^\d+$/.test(e)).map(Number),t=Math.max(...e),n=i.fallback||i.other,r=[];if(t<=1&&!a.includes(`2`))return`${i[0]||``} | ${i[1]||``} | ${n}`;let o=Math.max(1,t);for(let e=0;e<=o;e++){let t=e.toString();i[t]?r.push(i[t]):r.push(``)}return r.push(n),r.join(` | `).replace(/ \| {2}\| /g,` | | `)}return a.includes(`1`)&&(a.includes(`fallback`)||a.includes(`other`))?`${i[1]} | ${i.fallback||i.other}`:a.length===1&&(a.includes(`fallback`)||a.includes(`other`))?i.fallback||i.other:i.fallback||Object.values(i)[0]}if(e.nodeType===r.Gender){let r=e.gender,i={};for(let[e,a]of Object.entries(r)){let r=e;e===`fallback`&&(r=`other`),i[r]=n(a,t)}return i}return Array.isArray(e)||e.nodeType===`composite`&&Array.isArray(e.composite)?(Array.isArray(e)?e:e.composite).map(e=>n(e,t)).join(``):n(e,t)}},u=t=>e(t,{dictionaryKey:`vue-i18n`,keyPath:[],plugins:[{id:`vue-i18n`,...l}]}),d=t=>e(t,{dictionaryKey:`vue-i18n`,keyPath:[],plugins:[{id:`vue-i18n`,...c}]});export{u as intlayerToVueI18nFormatter,d as vueI18nToIntlayerFormatter};
|
|
1
|
+
import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{enu as t}from"../transpiler/enumeration/enumeration.mjs";import{insert as n}from"../transpiler/insertion/insertion.mjs";import{NodeType as r}from"@intlayer/types/nodeType";const i=e=>{let t=0,n=[],r=``;for(;t<e.length;){let i=e[t];if(i===`{`){r&&=(n.push(r),``),t++;let i=``;for(;t<e.length&&e[t]!==`}`;)i+=e[t],t++;t<e.length&&t++,n.push({type:`argument`,name:i.trim()})}else r+=i,t++}return r&&n.push(r),n},a=e=>{let t=[],n=``,r=0;for(;r<e.length;){let i=e[r];i===`\\`&&r+1<e.length&&e[r+1]===`|`?(n+=`|`,r+=2):i===`|`?(t.push(n.trim()),n=``,r++):(n+=i,r++)}return t.push(n.trim()),t.map(i)},o=e=>{if(e.length===0)return``;if(e.length===1&&typeof e[0]==`string`)return e[0];let t=``;for(let n of e)typeof n==`string`?t+=n:t+=`{{${n.name}}}`;return n(t)},s=e=>{if(e.length===1)return o(e[0]);let n={};return e.length===2?(n[1]=o(e[0]),n.fallback=o(e[1])):e.length===3?(n[0]=o(e[0]),n[1]=o(e[1]),n.fallback=o(e[2])):e.forEach((t,r)=>{r===e.length-1?n.fallback=o(t):n[r.toString()]=o(t)}),n.__intlayer_vue_i18n_var=`count`,t(n)},c={canHandle:e=>typeof e==`string`&&(e.includes(`{`)||e.includes(`|`)),transform:e=>{try{return s(a(e))}catch{return e}}},l={canHandle:e=>typeof e==`string`||e&&typeof e==`object`&&(e.nodeType===r.Insertion||e.nodeType===r.Enumeration||e.nodeType===r.Gender||e.nodeType===`composite`)||Array.isArray(e),transform:(e,t,n)=>{if(typeof e==`string`)return e.replace(/\{\{([^}]+)\}\}/g,`{$1}`);if(e.nodeType===r.Insertion)return e.insertion.replace(/\{\{([^}]+)\}\}/g,`{$1}`);if(e.nodeType===r.Enumeration){let r=e.enumeration,i={};for(let[e,a]of Object.entries(r)){if(e===`__intlayer_vue_i18n_var`)continue;let r=n(a,t);i[e]=typeof r==`string`?r:JSON.stringify(r)}let a=Object.keys(i);if(a.includes(`0`)){let e=a.filter(e=>/^\d+$/.test(e)).map(Number),t=Math.max(...e),n=i.fallback||i.other,r=[];if(t<=1&&!a.includes(`2`))return`${i[0]||``} | ${i[1]||``} | ${n}`;let o=Math.max(1,t);for(let e=0;e<=o;e++){let t=e.toString();i[t]?r.push(i[t]):r.push(``)}return r.push(n),r.join(` | `).replace(/ \| {2}\| /g,` | | `)}return a.includes(`1`)&&(a.includes(`fallback`)||a.includes(`other`))?`${i[1]} | ${i.fallback||i.other}`:a.length===1&&(a.includes(`fallback`)||a.includes(`other`))?i.fallback||i.other:i.fallback||Object.values(i)[0]}if(e.nodeType===r.Gender){let r=e.gender,i={};for(let[e,a]of Object.entries(r)){let r=e;e===`fallback`&&(r=`other`),i[r]=n(a,t)}return i}return Array.isArray(e)||e.nodeType===`composite`&&Array.isArray(e.composite)?(Array.isArray(e)?e:e.composite).map(e=>n(e,t)).join(``):n(e,t)}},u=t=>e(t,{dictionaryKey:`vue-i18n`,keyPath:[],plugins:[{id:`vue-i18n`,...l}]}),d=t=>e(t,{dictionaryKey:`vue-i18n`,keyPath:[],plugins:[{id:`vue-i18n`,...c}]});export{u as intlayerToVueI18nFormatter,d as vueI18nToIntlayerFormatter};
|
|
2
2
|
//# sourceMappingURL=vue-i18n.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-i18n.mjs","names":["insert","enu"],"sources":["../../../src/messageFormat/vue-i18n.ts"],"sourcesContent":["import { type Dictionary, NodeType } from '@intlayer/types';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, insert } from '../transpiler';\nimport type { JsonValue } from './ICU';\n\n// Types for our AST\ntype VueI18nNode =\n | string\n | {\n type: 'argument';\n name: string;\n };\n\nconst parseVueI18nPart = (text: string): VueI18nNode[] => {\n let index = 0;\n const nodes: VueI18nNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n let name = '';\n while (index < text.length && text[index] !== '}') {\n name += text[index];\n index++;\n }\n if (index < text.length) {\n index++; // skip }\n }\n nodes.push({ type: 'argument', name: name.trim() });\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n\n return nodes;\n};\n\nconst parseVueI18n = (text: string): VueI18nNode[][] => {\n // Split by | but handle escaped \\|\n const parts: string[] = [];\n let currentPart = '';\n let index = 0;\n\n while (index < text.length) {\n const char = text[index];\n if (char === '\\\\' && index + 1 < text.length && text[index + 1] === '|') {\n currentPart += '|';\n index += 2;\n } else if (char === '|') {\n parts.push(currentPart.trim()); // Trim to remove surrounding spaces\n currentPart = '';\n index++;\n } else {\n currentPart += char;\n index++;\n }\n }\n parts.push(currentPart.trim()); // Trim last part too\n\n return parts.map(parseVueI18nPart);\n};\n\nconst vueI18nPartToIntlayer = (nodes: VueI18nNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') return nodes[0];\n\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else {\n str += `{{${node.name}}}`;\n }\n }\n return insert(str);\n};\n\nconst vueI18nNodesToIntlayer = (parts: VueI18nNode[][]): any => {\n if (parts.length === 1) {\n return vueI18nPartToIntlayer(parts[0]);\n }\n\n // Handle pluralization (choice)\n const options: Record<string, any> = {};\n const varName = 'count'; // Default variable for vue-i18n choices\n\n if (parts.length === 2) {\n // 2 choices: 1 | other\n options['1'] = vueI18nPartToIntlayer(parts[0]);\n options.fallback = vueI18nPartToIntlayer(parts[1]);\n } else if (parts.length === 3) {\n // 3 choices: 0 | 1 | other\n options['0'] = vueI18nPartToIntlayer(parts[0]);\n options['1'] = vueI18nPartToIntlayer(parts[1]);\n options.fallback = vueI18nPartToIntlayer(parts[2]);\n } else {\n // > 3 choices: 0 | 1 | 2 | ... | other\n parts.forEach((part, index) => {\n if (index === parts.length - 1) {\n options.fallback = vueI18nPartToIntlayer(part);\n } else {\n options[index.toString()] = vueI18nPartToIntlayer(part);\n }\n });\n }\n\n // Preserve variable name\n options.__intlayer_vue_i18n_var = varName;\n\n return enu(options);\n};\n\nconst vueI18nToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' && (node.includes('{') || node.includes('|')),\n transform: (node: any) => {\n try {\n const ast = parseVueI18n(node);\n return vueI18nNodesToIntlayer(ast);\n } catch {\n return node;\n }\n },\n};\n\nconst intlayerToVueI18nPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' ||\n (node &&\n typeof node === 'object' &&\n (node.nodeType === NodeType.Insertion ||\n node.nodeType === NodeType.Enumeration ||\n node.nodeType === NodeType.Gender ||\n node.nodeType === 'composite')) ||\n Array.isArray(node),\n transform: (node: any, props: any, next: any) => {\n if (typeof node === 'string') {\n // replace {{...}} with {...} even in strings\n return node.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeType.Insertion) {\n // {{name}} -> {name}\n return node.insertion.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeType.Enumeration) {\n const options = node.enumeration;\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (key === '__intlayer_vue_i18n_var') continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n // We need to reconstruct the pipe-separated string.\n // 2 parts: 1, fallback\n // 3 parts: 0, 1, fallback\n\n const keys = Object.keys(transformedOptions);\n\n // Heuristic to decide format\n // Use loose condition for 3 parts: if 0 exists, OR if 2 exists, etc.\n // But typically 0, 1, 2...\n // If '0' is present, we likely want the 3+ parts format.\n if (keys.includes('0')) {\n const indices = keys.filter((key) => /^\\d+$/.test(key)).map(Number);\n const maxIndex = Math.max(...indices);\n\n const fallback =\n transformedOptions.fallback || transformedOptions.other;\n const resultParts = [];\n\n // Check if we can use simple 3-part: 0 | 1 | fallback\n // Only if maxIndex <= 1\n if (maxIndex <= 1 && !keys.includes('2')) {\n const zero = transformedOptions['0'] || '';\n const one = transformedOptions['1'] || ''; // Gap handling?\n return `${zero} | ${one} | ${fallback}`;\n }\n\n // General case: loop until maxIndex\n const limit = Math.max(1, maxIndex);\n\n for (let i = 0; i <= limit; i++) {\n const key = i.toString();\n if (transformedOptions[key]) {\n resultParts.push(transformedOptions[key]);\n } else {\n resultParts.push(''); // Empty string for gaps\n }\n }\n resultParts.push(fallback);\n return resultParts.join(' | ').replace(/ \\| {2}\\| /g, ' | | ');\n }\n\n // 2 parts: 1 | fallback\n if (\n keys.includes('1') &&\n (keys.includes('fallback') || keys.includes('other'))\n ) {\n return `${transformedOptions['1']} | ${transformedOptions.fallback || transformedOptions.other}`;\n }\n\n // Fallback for only fallback?\n if (\n keys.length === 1 &&\n (keys.includes('fallback') || keys.includes('other'))\n ) {\n return transformedOptions.fallback || transformedOptions.other;\n }\n\n // Default fallback\n return (\n transformedOptions.fallback || Object.values(transformedOptions)[0]\n );\n }\n\n // Gender not supported by vue-i18n string format, return object\n if (node.nodeType === NodeType.Gender) {\n const options = node.gender;\n const transformedOptions: Record<string, any> = {};\n\n // Just map values\n for (const [key, val] of Object.entries(options)) {\n let newKey = key;\n if (key === 'fallback') newKey = 'other'; // vue-i18n doesn't strictly have 'other' for gender objects but standard convention often uses similar keys\n\n const childVal = next(val, props);\n transformedOptions[newKey] = childVal;\n }\n return transformedOptions;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToVueI18nFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'vue-i18n',\n keyPath: [],\n plugins: [{ id: 'vue-i18n', ...intlayerToVueI18nPlugin }],\n });\n};\n\nexport const vueI18nToIntlayerFormatter = (\n message: JsonValue\n): Dictionary['content'] => {\n return deepTransformNode(message, {\n dictionaryKey: 'vue-i18n',\n keyPath: [],\n plugins: [{ id: 'vue-i18n', ...vueI18nToIntlayerPlugin }],\n });\n};\n"],"mappings":"0PAaA,MAAM,EAAoB,GAAgC,CACxD,IAAI,EAAQ,EACN,EAAuB,EAAE,CAC3B,EAAc,GAElB,KAAO,EAAQ,EAAK,QAAQ,CAC1B,IAAM,EAAO,EAAK,GAElB,GAAI,IAAS,IAAK,CAChB,AAEE,KADA,EAAM,KAAK,EAAY,CACT,IAEhB,IACA,IAAI,EAAO,GACX,KAAO,EAAQ,EAAK,QAAU,EAAK,KAAW,KAC5C,GAAQ,EAAK,GACb,IAEE,EAAQ,EAAK,QACf,IAEF,EAAM,KAAK,CAAE,KAAM,WAAY,KAAM,EAAK,MAAM,CAAE,CAAC,MAEnD,GAAe,EACf,IAQJ,OAJI,GACF,EAAM,KAAK,EAAY,CAGlB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ary } from '@intlayer/types/dictionary';;\nimport { NodeType } from '@intlayer/types/nodeType';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, insert } from '../transpiler';\nimport type { JsonValue } from './ICU';\n\n// Types for our AST\ntype VueI18nNode =\n | string\n | {\n type: 'argument';\n name: string;\n };\n\nconst parseVueI18nPart = (text: string): VueI18nNode[] => {\n let index = 0;\n const nodes: VueI18nNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n let name = '';\n while (index < text.length && text[index] !== '}') {\n name += text[index];\n index++;\n }\n if (index < text.length) {\n index++; // skip }\n }\n nodes.push({ type: 'argument', name: name.trim() });\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n\n return nodes;\n};\n\nconst parseVueI18n = (text: string): VueI18nNode[][] => {\n // Split by | but handle escaped \\|\n const parts: string[] = [];\n let currentPart = '';\n let index = 0;\n\n while (index < text.length) {\n const char = text[index];\n if (char === '\\\\' && index + 1 < text.length && text[index + 1] === '|') {\n currentPart += '|';\n index += 2;\n } else if (char === '|') {\n parts.push(currentPart.trim()); // Trim to remove surrounding spaces\n currentPart = '';\n index++;\n } else {\n currentPart += char;\n index++;\n }\n }\n parts.push(currentPart.trim()); // Trim last part too\n\n return parts.map(parseVueI18nPart);\n};\n\nconst vueI18nPartToIntlayer = (nodes: VueI18nNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') return nodes[0];\n\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else {\n str += `{{${node.name}}}`;\n }\n }\n return insert(str);\n};\n\nconst vueI18nNodesToIntlayer = (parts: VueI18nNode[][]): any => {\n if (parts.length === 1) {\n return vueI18nPartToIntlayer(parts[0]);\n }\n\n // Handle pluralization (choice)\n const options: Record<string, any> = {};\n const varName = 'count'; // Default variable for vue-i18n choices\n\n if (parts.length === 2) {\n // 2 choices: 1 | other\n options['1'] = vueI18nPartToIntlayer(parts[0]);\n options.fallback = vueI18nPartToIntlayer(parts[1]);\n } else if (parts.length === 3) {\n // 3 choices: 0 | 1 | other\n options['0'] = vueI18nPartToIntlayer(parts[0]);\n options['1'] = vueI18nPartToIntlayer(parts[1]);\n options.fallback = vueI18nPartToIntlayer(parts[2]);\n } else {\n // > 3 choices: 0 | 1 | 2 | ... | other\n parts.forEach((part, index) => {\n if (index === parts.length - 1) {\n options.fallback = vueI18nPartToIntlayer(part);\n } else {\n options[index.toString()] = vueI18nPartToIntlayer(part);\n }\n });\n }\n\n // Preserve variable name\n options.__intlayer_vue_i18n_var = varName;\n\n return enu(options);\n};\n\nconst vueI18nToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' && (node.includes('{') || node.includes('|')),\n transform: (node: any) => {\n try {\n const ast = parseVueI18n(node);\n return vueI18nNodesToIntlayer(ast);\n } catch {\n return node;\n }\n },\n};\n\nconst intlayerToVueI18nPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' ||\n (node &&\n typeof node === 'object' &&\n (node.nodeType === NodeType.Insertion ||\n node.nodeType === NodeType.Enumeration ||\n node.nodeType === NodeType.Gender ||\n node.nodeType === 'composite')) ||\n Array.isArray(node),\n transform: (node: any, props: any, next: any) => {\n if (typeof node === 'string') {\n // replace {{...}} with {...} even in strings\n return node.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeType.Insertion) {\n // {{name}} -> {name}\n return node.insertion.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeType.Enumeration) {\n const options = node.enumeration;\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (key === '__intlayer_vue_i18n_var') continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n // We need to reconstruct the pipe-separated string.\n // 2 parts: 1, fallback\n // 3 parts: 0, 1, fallback\n\n const keys = Object.keys(transformedOptions);\n\n // Heuristic to decide format\n // Use loose condition for 3 parts: if 0 exists, OR if 2 exists, etc.\n // But typically 0, 1, 2...\n // If '0' is present, we likely want the 3+ parts format.\n if (keys.includes('0')) {\n const indices = keys.filter((key) => /^\\d+$/.test(key)).map(Number);\n const maxIndex = Math.max(...indices);\n\n const fallback =\n transformedOptions.fallback || transformedOptions.other;\n const resultParts = [];\n\n // Check if we can use simple 3-part: 0 | 1 | fallback\n // Only if maxIndex <= 1\n if (maxIndex <= 1 && !keys.includes('2')) {\n const zero = transformedOptions['0'] || '';\n const one = transformedOptions['1'] || ''; // Gap handling?\n return `${zero} | ${one} | ${fallback}`;\n }\n\n // General case: loop until maxIndex\n const limit = Math.max(1, maxIndex);\n\n for (let i = 0; i <= limit; i++) {\n const key = i.toString();\n if (transformedOptions[key]) {\n resultParts.push(transformedOptions[key]);\n } else {\n resultParts.push(''); // Empty string for gaps\n }\n }\n resultParts.push(fallback);\n return resultParts.join(' | ').replace(/ \\| {2}\\| /g, ' | | ');\n }\n\n // 2 parts: 1 | fallback\n if (\n keys.includes('1') &&\n (keys.includes('fallback') || keys.includes('other'))\n ) {\n return `${transformedOptions['1']} | ${transformedOptions.fallback || transformedOptions.other}`;\n }\n\n // Fallback for only fallback?\n if (\n keys.length === 1 &&\n (keys.includes('fallback') || keys.includes('other'))\n ) {\n return transformedOptions.fallback || transformedOptions.other;\n }\n\n // Default fallback\n return (\n transformedOptions.fallback || Object.values(transformedOptions)[0]\n );\n }\n\n // Gender not supported by vue-i18n string format, return object\n if (node.nodeType === NodeType.Gender) {\n const options = node.gender;\n const transformedOptions: Record<string, any> = {};\n\n // Just map values\n for (const [key, val] of Object.entries(options)) {\n let newKey = key;\n if (key === 'fallback') newKey = 'other'; // vue-i18n doesn't strictly have 'other' for gender objects but standard convention often uses similar keys\n\n const childVal = next(val, props);\n transformedOptions[newKey] = childVal;\n }\n return transformedOptions;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToVueI18nFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'vue-i18n',\n keyPath: [],\n plugins: [{ id: 'vue-i18n', ...intlayerToVueI18nPlugin }],\n });\n};\n\nexport const vueI18nToIntlayerFormatter = (\n message: JsonValue\n): Dictionary['content'] => {\n return deepTransformNode(message, {\n dictionaryKey: 'vue-i18n',\n keyPath: [],\n plugins: [{ id: 'vue-i18n', ...vueI18nToIntlayerPlugin }],\n });\n};\n"],"mappings":"mQAcA,MAAM,EAAoB,GAAgC,CACxD,IAAI,EAAQ,EACN,EAAuB,EAAE,CAC3B,EAAc,GAElB,KAAO,EAAQ,EAAK,QAAQ,CAC1B,IAAM,EAAO,EAAK,GAElB,GAAI,IAAS,IAAK,CAChB,AAEE,KADA,EAAM,KAAK,EAAY,CACT,IAEhB,IACA,IAAI,EAAO,GACX,KAAO,EAAQ,EAAK,QAAU,EAAK,KAAW,KAC5C,GAAQ,EAAK,GACb,IAEE,EAAQ,EAAK,QACf,IAEF,EAAM,KAAK,CAAE,KAAM,WAAY,KAAM,EAAK,MAAM,CAAE,CAAC,MAEnD,GAAe,EACf,IAQJ,OAJI,GACF,EAAM,KAAK,EAAY,CAGlB,GAGH,EAAgB,GAAkC,CAEtD,IAAM,EAAkB,EAAE,CACtB,EAAc,GACd,EAAQ,EAEZ,KAAO,EAAQ,EAAK,QAAQ,CAC1B,IAAM,EAAO,EAAK,GACd,IAAS,MAAQ,EAAQ,EAAI,EAAK,QAAU,EAAK,EAAQ,KAAO,KAClE,GAAe,IACf,GAAS,GACA,IAAS,KAClB,EAAM,KAAK,EAAY,MAAM,CAAC,CAC9B,EAAc,GACd,MAEA,GAAe,EAC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,IACf,EAAK,SAAS,WAAW,EAAI,EAAK,SAAS,QAAQ,EAE7C,EAAmB,UAAY,EAAmB,MAKzD,EAAmB,UAAY,OAAO,OAAO,EAAmB,CAAC,GAKrE,GAAI,EAAK,WAAa,EAAS,OAAQ,CACrC,IAAM,EAAU,EAAK,OACf,EAA0C,EAAE,CAGlD,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,EAAQ,CAAE,CAChD,IAAI,EAAS,EACT,IAAQ,aAAY,EAAS,SAGjC,EAAmB,GADF,EAAK,EAAK,EAAM,CAGnC,OAAO,EAYT,OARE,MAAM,QAAQ,EAAK,EAClB,EAAK,WAAa,aAAe,MAAM,QAAQ,EAAK,UAAU,EAEnD,MAAM,QAAQ,EAAK,CAAG,EAAO,EAAK,WAC5B,IAAK,GAAc,EAAK,EAAM,EAAM,CAAC,CAC1C,KAAK,GAAG,CAGhB,EAAK,EAAM,EAAM,EAE3B,CAEY,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,WACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,WAAY,GAAG,EAAyB,CAAC,CAC1D,CAAC,CAGS,EACX,GAEO,EAAkB,EAAS,CAChC,cAAe,WACf,QAAS,EAAE,CACX,QAAS,CAAC,CAAE,GAAI,WAAY,GAAG,EAAyB,CAAC,CAC1D,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{NodeType as e,formatNodeType as t}from"@intlayer/types";const n=n=>t(e.Condition,n);export{n as cond};
|
|
1
|
+
import{NodeType as e,formatNodeType as t}from"@intlayer/types/nodeType";const n=n=>t(e.Condition,n);export{n as cond};
|
|
2
2
|
//# sourceMappingURL=condition.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.mjs","names":[],"sources":["../../../../src/transpiler/condition/condition.ts"],"sourcesContent":["import { formatNodeType, NodeType
|
|
1
|
+
{"version":3,"file":"condition.mjs","names":[],"sources":["../../../../src/transpiler/condition/condition.ts"],"sourcesContent":["import { formatNodeType, NodeType } from '@intlayer/types/nodeType';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';;\n\nexport type ConditionContentStates<Content> = Record<`${boolean}`, Content> & {\n fallback?: Content;\n};\n\nexport type ConditionContent<Content = unknown> = TypedNodeModel<\n NodeType.Condition,\n ConditionContentStates<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a condition.\n *\n * Usage:\n *\n * ```ts\n * cond({\n * 'true': 'The condition is validated',\n * 'false': 'The condition is not validated',\n * });\n * ```\n *\n * The last key provided will be used as the fallback value.\n *\n */\nconst condition = <Content>(content?: ConditionContentStates<Content>) =>\n formatNodeType(NodeType.Condition, content);\n\nexport { condition as cond };\n"],"mappings":"wEA6BA,MAAM,EAAsB,GAC1B,EAAe,EAAS,UAAW,EAAQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{NodeType as e,formatNodeType as t}from"@intlayer/types";const n=n=>t(e.Enumeration,n);export{n as enu};
|
|
1
|
+
import{NodeType as e,formatNodeType as t}from"@intlayer/types/nodeType";const n=n=>t(e.Enumeration,n);export{n as enu};
|
|
2
2
|
//# sourceMappingURL=enumeration.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enumeration.mjs","names":[],"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import { formatNodeType, NodeType
|
|
1
|
+
{"version":3,"file":"enumeration.mjs","names":[],"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import { formatNodeType, NodeType } from '@intlayer/types/nodeType';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';;\n\ntype Positive = number | `${number}`;\ntype Negative = `-${number}`;\ntype Numbers = Positive | Negative;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\nexport type EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type EnumerationContentState<Content> = Partial<\n Record<EnterFormat, Content>\n> & {\n fallback?: Content;\n};\n\nexport type EnumerationContent<Content = unknown> = TypedNodeModel<\n NodeType.Enumeration,\n EnumerationContentState<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * enu({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * });\n * ```\n *\n * > The order of the keys will define the priority of the content.\n *\n */\nconst enumeration = <Content>(content?: EnumerationContentState<Content>) =>\n formatNodeType(NodeType.Enumeration, content);\n\nexport { enumeration as enu };\n"],"mappings":"wEAoDA,MAAM,EAAwB,GAC5B,EAAe,EAAS,YAAa,EAAQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{NodeType as e,formatNodeType as t}from"@intlayer/types";import{colorizePath as n,getAppLogger as r}from"@intlayer/config/logger";import{existsSync as i,readFileSync as a,statSync as o}from"node:fs";import{dirname as s,isAbsolute as c,relative as l,resolve as u}from"node:path";const d=(s,d,f)=>{let p=s.startsWith(`./`)||s.startsWith(`../`),m=r(),h;if(c(s)?(m(`Using absolute path for file is not recommended. Use relative paths instead. Path: ${s}, imported from: ${d}`,{level:`warn`}),h=s):h=u(p?d:f,s),i(h)&&o(h).isFile())try{let n=a(h,`utf8`);return t(e.File,s,{content:n,fixedPath:l(f,h)})}catch{m(`Unable to read path: ${n(l(f,h))}`,{level:`warn`})}else m(`File not found: ${n(l(f,h))}`,{level:`warn`});return t(e.File,s,{content:`-`})},f=e=>{let{INTLAYER_FILE_PATH:t,INTLAYER_BASE_DIR:n}=globalThis;return d(e,s(t),n)};export{f as file,d as fileContent};
|
|
1
|
+
import{NodeType as e,formatNodeType as t}from"@intlayer/types/nodeType";import{colorizePath as n,getAppLogger as r}from"@intlayer/config/logger";import{existsSync as i,readFileSync as a,statSync as o}from"node:fs";import{dirname as s,isAbsolute as c,relative as l,resolve as u}from"node:path";const d=(s,d,f)=>{let p=s.startsWith(`./`)||s.startsWith(`../`),m=r(),h;if(c(s)?(m(`Using absolute path for file is not recommended. Use relative paths instead. Path: ${s}, imported from: ${d}`,{level:`warn`}),h=s):h=u(p?d:f,s),i(h)&&o(h).isFile())try{let n=a(h,`utf8`);return t(e.File,s,{content:n,fixedPath:l(f,h)})}catch{m(`Unable to read path: ${n(l(f,h))}`,{level:`warn`})}else m(`File not found: ${n(l(f,h))}`,{level:`warn`});return t(e.File,s,{content:`-`})},f=e=>{let{INTLAYER_FILE_PATH:t,INTLAYER_BASE_DIR:n}=globalThis;return d(e,s(t),n)};export{f as file,d as fileContent};
|
|
2
2
|
//# sourceMappingURL=file.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.mjs","names":[],"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, isAbsolute, relative, resolve } from 'node:path';\nimport { colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport { formatNodeType, NodeType
|
|
1
|
+
{"version":3,"file":"file.mjs","names":[],"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, isAbsolute, relative, resolve } from 'node:path';\nimport { colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport { formatNodeType, NodeType } from '@intlayer/types/nodeType';\n\nexport type FileContentConstructor<T extends Record<string, any> = {}> =\n TypedNodeModel<NodeType.File, string, T>;\n\nexport type FileContent = FileContentConstructor<{\n content: string;\n fixedPath?: string;\n}>;\n\nexport const fileContent = (\n path: string,\n callerDir: string,\n baseDir: string\n): FileContent => {\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n const appLogger = getAppLogger();\n\n let filePath: string;\n if (isAbsolute(path)) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${callerDir}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(baseDir, path);\n }\n\n if (existsSync(filePath) && statSync(filePath).isFile()) {\n try {\n const content = readFileSync(filePath, 'utf8');\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(baseDir, filePath),\n });\n } catch {\n appLogger(\n `Unable to read path: ${colorizePath(relative(baseDir, filePath))}`,\n { level: 'warn' }\n );\n }\n } else {\n appLogger(`File not found: ${colorizePath(relative(baseDir, filePath))}`, {\n level: 'warn',\n });\n }\n\n return formatNodeType(NodeType.File, path, {\n content: `-`,\n });\n};\n\ntype GlobalIntlayerFilePath = {\n INTLAYER_FILE_PATH: string;\n INTLAYER_BASE_DIR: string;\n};\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n const { INTLAYER_FILE_PATH, INTLAYER_BASE_DIR } =\n globalThis as unknown as GlobalIntlayerFilePath;\n\n const callerDir = dirname(INTLAYER_FILE_PATH);\n const baseDir = INTLAYER_BASE_DIR;\n\n return fileContent(path, callerDir, baseDir);\n};\n"],"mappings":"qSAcA,MAAa,GACX,EACA,EACA,IACgB,CAChB,IAAM,EAAiB,EAAK,WAAW,KAAK,EAAI,EAAK,WAAW,MAAM,CAChE,EAAY,GAAc,CAE5B,EAaJ,GAZI,EAAW,EAAK,EAClB,EACE,sFAAsF,EAAK,mBAAmB,IAC9G,CAAE,MAAO,OAAQ,CAClB,CACD,EAAW,GAIX,EAFW,EADF,EACU,EAEA,EAFW,EAEG,CAG/B,EAAW,EAAS,EAAI,EAAS,EAAS,CAAC,QAAQ,CACrD,GAAI,CACF,IAAM,EAAU,EAAa,EAAU,OAAO,CAE9C,OAAO,EAAe,EAAS,KAAM,EAAM,CACzC,UACA,UAAW,EAAS,EAAS,EAAS,CACvC,CAAC,MACI,CACN,EACE,wBAAwB,EAAa,EAAS,EAAS,EAAS,CAAC,GACjE,CAAE,MAAO,OAAQ,CAClB,MAGH,EAAU,mBAAmB,EAAa,EAAS,EAAS,EAAS,CAAC,GAAI,CACxE,MAAO,OACR,CAAC,CAGJ,OAAO,EAAe,EAAS,KAAM,EAAM,CACzC,QAAS,IACV,CAAC,EAuBS,EAAQ,GAA8B,CACjD,GAAM,CAAE,qBAAoB,qBAC1B,WAKF,OAAO,EAAY,EAHD,EAAQ,EAAmB,CAC7B,EAE4B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=e=>{throw Error(`file is not available in browser`)};export{e as file};
|
|
2
2
|
//# sourceMappingURL=fileBrowser.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileBrowser.mjs","names":[],"sources":["../../../../src/transpiler/file/fileBrowser.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"fileBrowser.mjs","names":[],"sources":["../../../../src/transpiler/file/fileBrowser.ts"],"sourcesContent":["import type { FileContent } from './file';\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (_path: string): FileContent => {\n throw new Error('file is not available in browser');\n\n // return formatNodeType(NodeType.File, path, {\n // content: '',\n // fixedPath: '',\n // });\n};\n"],"mappings":"AAiBA,MAAa,EAAQ,GAA+B,CAClD,MAAU,MAAM,mCAAmC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{NodeType as e,formatNodeType as t}from"@intlayer/types";const n=n=>t(e.Gender,n);export{n as gender};
|
|
1
|
+
import{NodeType as e,formatNodeType as t}from"@intlayer/types/nodeType";const n=n=>t(e.Gender,n);export{n as gender};
|
|
2
2
|
//# sourceMappingURL=gender.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gender.mjs","names":[],"sources":["../../../../src/transpiler/gender/gender.ts"],"sourcesContent":["import { formatNodeType, NodeType
|
|
1
|
+
{"version":3,"file":"gender.mjs","names":[],"sources":["../../../../src/transpiler/gender/gender.ts"],"sourcesContent":["import type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport { formatNodeType, NodeType } from '@intlayer/types/nodeType';\n\nexport type Gender = 'male' | 'female' | 'fallback';\n\nexport type GenderContentStates<Content> = Record<`${Gender}`, Content> & {\n fallback?: Content;\n};\n\nexport type GenderContent<Content = unknown> = TypedNodeModel<\n NodeType.Gender,\n GenderContentStates<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a gender.\n *\n * Usage:\n *\n * ```ts\n * gender({\n * 'true': 'The gender is validated',\n * 'false': 'The gender is not validated',\n * });\n * ```\n *\n * The last key provided will be used as the fallback value.\n *\n */\nconst gender = <Content>(content?: GenderContentStates<Content>) =>\n formatNodeType(NodeType.Gender, content);\n\nexport { gender };\n"],"mappings":"wEA+BA,MAAM,EAAmB,GACvB,EAAe,EAAS,OAAQ,EAAQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getHTMLCustomComponents as e}from"./getHTMLCustomComponents.mjs";import{NodeType as t,formatNodeType as n}from"@intlayer/types";const r=(r,i)=>n(t.HTML,r,{tags:(()=>{if(i)return i;if(typeof r==`string`)return e(r);let t;if(typeof r==`function`?t=r():typeof r.then==`function`&&(t=async()=>e(await r)),typeof t==`string`)return e(t);try{return e(JSON.stringify(r))}catch{return[]}})()});export{r as html};
|
|
1
|
+
import{getHTMLCustomComponents as e}from"./getHTMLCustomComponents.mjs";import{NodeType as t,formatNodeType as n}from"@intlayer/types/nodeType";const r=(r,i)=>n(t.HTML,r,{tags:(()=>{if(i)return i;if(typeof r==`string`)return e(r);let t;if(typeof r==`function`?t=r():typeof r.then==`function`&&(t=async()=>e(await r)),typeof t==`string`)return e(t);try{return e(JSON.stringify(r))}catch{return[]}})()});export{r as html};
|
|
2
2
|
//# sourceMappingURL=html.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.mjs","names":[],"sources":["../../../../src/transpiler/html/html.ts"],"sourcesContent":["import { formatNodeType, NodeType
|
|
1
|
+
{"version":3,"file":"html.mjs","names":[],"sources":["../../../../src/transpiler/html/html.ts"],"sourcesContent":["import type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport { formatNodeType, NodeType } from '@intlayer/types/nodeType';\nimport { getHTMLCustomComponents } from './getHTMLCustomComponents';\n\ntype PropsType = 'number' | 'string' | 'node';\n\ntype ComponentName = string;\n\nexport type HTMLContentConstructor<\n Content = unknown,\n T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.HTML, Content, T>;\n\nexport type HTMLContent<\n Content = unknown,\n Components extends Record<ComponentName, PropsType> = Record<\n ComponentName,\n PropsType\n >,\n> = HTMLContentConstructor<\n Content,\n {\n tags: string[] | Components;\n }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to parse HTML/JSX-like strings and replace tags with components during interpretation.\n *\n * Usage:\n *\n * ```ts\n * html('Hello <b>World</b>')\n * ```\n *\n */\nexport const html = <\n Components extends Record<string, any> = Record<string, any>,\n Content = unknown,\n>(\n content: Content,\n components?: Components\n): HTMLContent<Content, Components> => {\n const getComponents = () => {\n if (components) {\n return components;\n }\n\n if (typeof content === 'string') {\n return getHTMLCustomComponents(content);\n }\n\n let stringContent: any;\n\n if (typeof content === 'function') {\n stringContent = content();\n } else if (typeof (content as Promise<string>).then === 'function') {\n stringContent = async () =>\n getHTMLCustomComponents((await (content as Promise<string>)) as string);\n }\n\n if (typeof stringContent === 'string') {\n return getHTMLCustomComponents(stringContent);\n }\n\n try {\n return getHTMLCustomComponents(JSON.stringify(content));\n } catch (_e) {\n return [];\n }\n };\n\n return formatNodeType(NodeType.HTML, content, {\n tags: getComponents(),\n });\n};\n"],"mappings":"gJAsCA,MAAa,GAIX,EACA,IA+BO,EAAe,EAAS,KAAM,EAAS,CAC5C,UA9B0B,CAC1B,GAAI,EACF,OAAO,EAGT,GAAI,OAAO,GAAY,SACrB,OAAO,EAAwB,EAAQ,CAGzC,IAAI,EASJ,GAPI,OAAO,GAAY,WACrB,EAAgB,GAAS,CAChB,OAAQ,EAA4B,MAAS,aACtD,EAAgB,SACd,EAAyB,MAAO,EAAuC,EAGvE,OAAO,GAAkB,SAC3B,OAAO,EAAwB,EAAc,CAG/C,GAAI,CACF,OAAO,EAAwB,KAAK,UAAU,EAAQ,CAAC,MAC5C,CACX,MAAO,EAAE,KAKU,CACtB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getInsertionValues as e}from"./getInsertionValues.mjs";import{NodeType as t,formatNodeType as n}from"@intlayer/types";const r=r=>n(t.Insertion,r,{fields:(()=>{if(typeof r==`string`)return e(r);let t;if(typeof r==`function`?t=r():typeof r.then==`function`&&(t=async()=>e(await r)),typeof t==`string`)return e(t);try{return e(JSON.stringify(r))}catch{return[]}})()});export{r as insert};
|
|
1
|
+
import{getInsertionValues as e}from"./getInsertionValues.mjs";import{NodeType as t,formatNodeType as n}from"@intlayer/types/nodeType";const r=r=>n(t.Insertion,r,{fields:(()=>{if(typeof r==`string`)return e(r);let t;if(typeof r==`function`?t=r():typeof r.then==`function`&&(t=async()=>e(await r)),typeof t==`string`)return e(t);try{return e(JSON.stringify(r))}catch{return[]}})()});export{r as insert};
|
|
2
2
|
//# sourceMappingURL=insertion.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertion.mjs","names":[],"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import { formatNodeType, NodeType
|
|
1
|
+
{"version":3,"file":"insertion.mjs","names":[],"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport { formatNodeType, NodeType } from '@intlayer/types/nodeType';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContentConstructor<\n Content = unknown,\n T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.Insertion, Content, T>;\n\nexport type InsertionContent<Content = unknown> = InsertionContentConstructor<\n Content,\n {\n fields: string[];\n }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to identify insertions inside a content.\n *\n * Usage:\n *\n * ```ts\n * insertion('Hi, my name is {{name}} and I am {{age}} years old.')\n * ```\n *\n */\nconst insertion = <Content = unknown>(\n content: Content\n): InsertionContent<Content> => {\n const getInsertions = () => {\n if (typeof content === 'string') {\n return getInsertionValues(content);\n }\n\n let stringContent: any;\n\n if (typeof content === 'function') {\n stringContent = content();\n } else if (typeof (content as Promise<string>).then === 'function') {\n stringContent = async () =>\n getInsertionValues(await (content as Promise<string>));\n }\n\n if (typeof stringContent === 'string') {\n return getInsertionValues(stringContent);\n }\n\n try {\n return getInsertionValues(JSON.stringify(content));\n } catch (_e) {\n return [];\n }\n };\n\n return formatNodeType(NodeType.Insertion, content, {\n fields: getInsertions(),\n });\n};\n\nexport { insertion as insert };\n"],"mappings":"sIA4BA,MAAM,EACJ,GA2BO,EAAe,EAAS,UAAW,EAAS,CACjD,YA1B0B,CAC1B,GAAI,OAAO,GAAY,SACrB,OAAO,EAAmB,EAAQ,CAGpC,IAAI,EASJ,GAPI,OAAO,GAAY,WACrB,EAAgB,GAAS,CAChB,OAAQ,EAA4B,MAAS,aACtD,EAAgB,SACd,EAAmB,MAAO,EAA4B,EAGtD,OAAO,GAAkB,SAC3B,OAAO,EAAmB,EAAc,CAG1C,GAAI,CACF,OAAO,EAAmB,KAAK,UAAU,EAAQ,CAAC,MACvC,CACX,MAAO,EAAE,KAKY,CACxB,CAAC"}
|