@intlayer/core 8.2.3 → 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,2 +1,2 @@
|
|
|
1
|
-
import{getCondition as e}from"../getCondition.mjs";import{getEnumeration as t}from"../getEnumeration.mjs";import{getGender as n}from"../getGender.mjs";import{getInsertion as r}from"../getInsertion.mjs";import{getNesting as i}from"../getNesting.mjs";import{getTranslation as a}from"../getTranslation.mjs";import{NodeType as o}from"@intlayer/types";const s=(e,t)=>({id:`translation-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Translation,transform:(n,r,i)=>{let s=structuredClone(n[o.Translation]);for(let e in s){let t={...r,children:s[e],keyPath:[...r.keyPath,{type:o.Translation,key:e}]};s[e]=i(s[e],t)}return a(s,e,t)}}),c={id:`enumeration-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Enumeration,transform:(e,n,r)=>{let i=structuredClone(e[o.Enumeration]);for(let e in i){let t=i[e];i[e]=r(t,{...n,children:t,keyPath:[...n.keyPath,{type:o.Enumeration,key:e}]})}return e=>{let n=t(i,typeof e==`number`?e:e.count);return typeof n==`function`&&typeof e==`object`?n(e):n}}},l={id:`condition-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Condition,transform:(t,n,r)=>{let i=structuredClone(t[o.Condition]);for(let e in i){let t=i[e];i[e]=r(t,{...n,children:t,keyPath:[...n.keyPath,{type:o.Condition,key:e}]})}return t=>{let n=e(i,typeof t==`boolean`?t:t.value);return typeof n==`function`&&typeof t==`object`?n(t):n}}},u={id:`insertion-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Insertion,transform:(e,t,n)=>{let i=[...t.keyPath,{type:o.Insertion}],a=e[o.Insertion],s={id:`insertion-string-plugin`,canHandle:e=>typeof e==`string`,transform:(e,n,i)=>{let a=i(e,{...n,children:e,plugins:[...(t.plugins??[]).filter(e=>e.id!==`intlayer-node-plugin`)]});return e=>{let o=r(a,e);return i(o,{...n,plugins:t.plugins,children:o})}}};return n(a,{...t,children:a,keyPath:i,plugins:[s,...t.plugins??[]]})}},d={id:`gender-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Gender,transform:(e,t,r)=>{let i=structuredClone(e[o.Gender]);for(let e in i){let n=i[e];i[e]=r(n,{...t,children:n,keyPath:[...t.keyPath,{type:o.Gender,key:e}]})}return e=>n(i,e)}},f=e=>({id:`nested-plugin`,canHandle:e=>typeof e==`object`&&(e?.nodeType===o.Nested||e?.nodeType===`nested`),transform:(t,n)=>i(t.nested.dictionaryKey,t.nested.path,{...n,locale:e??n.locale})}),p={id:`file-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.File,transform:(e,t,n)=>n(e.content,{...t,children:e.content})};export{l as conditionPlugin,c as enumerationPlugin,p as filePlugin,d as genderPlugin,u as insertionPlugin,f as nestedPlugin,s as translationPlugin};
|
|
1
|
+
import{getCondition as e}from"../getCondition.mjs";import{getEnumeration as t}from"../getEnumeration.mjs";import{getGender as n}from"../getGender.mjs";import{getInsertion as r}from"../getInsertion.mjs";import{getNesting as i}from"../getNesting.mjs";import{getTranslation as a}from"../getTranslation.mjs";import{NodeType as o}from"@intlayer/types/nodeType";const s=(e,t)=>({id:`translation-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Translation,transform:(n,r,i)=>{let s=structuredClone(n[o.Translation]);for(let e in s){let t={...r,children:s[e],keyPath:[...r.keyPath,{type:o.Translation,key:e}]};s[e]=i(s[e],t)}return a(s,e,t)}}),c={id:`enumeration-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Enumeration,transform:(e,n,r)=>{let i=structuredClone(e[o.Enumeration]);for(let e in i){let t=i[e];i[e]=r(t,{...n,children:t,keyPath:[...n.keyPath,{type:o.Enumeration,key:e}]})}return e=>{let n=t(i,typeof e==`number`?e:e.count);return typeof n==`function`&&typeof e==`object`?n(e):n}}},l={id:`condition-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Condition,transform:(t,n,r)=>{let i=structuredClone(t[o.Condition]);for(let e in i){let t=i[e];i[e]=r(t,{...n,children:t,keyPath:[...n.keyPath,{type:o.Condition,key:e}]})}return t=>{let n=e(i,typeof t==`boolean`?t:t.value);return typeof n==`function`&&typeof t==`object`?n(t):n}}},u={id:`insertion-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Insertion,transform:(e,t,n)=>{let i=[...t.keyPath,{type:o.Insertion}],a=e[o.Insertion],s={id:`insertion-string-plugin`,canHandle:e=>typeof e==`string`,transform:(e,n,i)=>{let a=i(e,{...n,children:e,plugins:[...(t.plugins??[]).filter(e=>e.id!==`intlayer-node-plugin`)]});return e=>{let o=r(a,e);return i(o,{...n,plugins:t.plugins,children:o})}}};return n(a,{...t,children:a,keyPath:i,plugins:[s,...t.plugins??[]]})}},d={id:`gender-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.Gender,transform:(e,t,r)=>{let i=structuredClone(e[o.Gender]);for(let e in i){let n=i[e];i[e]=r(n,{...t,children:n,keyPath:[...t.keyPath,{type:o.Gender,key:e}]})}return e=>n(i,e)}},f=e=>({id:`nested-plugin`,canHandle:e=>typeof e==`object`&&(e?.nodeType===o.Nested||e?.nodeType===`nested`),transform:(t,n)=>i(t.nested.dictionaryKey,t.nested.path,{...n,locale:e??n.locale})}),p={id:`file-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===o.File,transform:(e,t,n)=>n(e.content,{...t,children:e.content})};export{l as conditionPlugin,c as enumerationPlugin,p as filePlugin,d as genderPlugin,u as insertionPlugin,f as nestedPlugin,s as translationPlugin};
|
|
2
2
|
//# sourceMappingURL=plugins.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import {\n type DeclaredLocales,\n type DictionaryKeys,\n type KeyPath,\n type Locale,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as keyof typeof result] = deepTransformNode(\n result[key as keyof typeof result],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: string;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => DeepTransformContent<string, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Gender]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<T[NodeType.Gender][keyof T[NodeType.Gender]], S>\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins = {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Gender,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Gender]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [...props.keyPath, { type: NodeType.Gender, key } as KeyPath],\n };\n result[key as keyof typeof result] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result, value);\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins => ({\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeType.Nested || node?.nodeType === 'nested'),\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }),\n});\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.File]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n gender: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin’s transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as keyof typeof result] = deepTransformNode(\n result[key as keyof typeof result],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: string;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => DeepTransformContent<string, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Gender]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<T[NodeType.Gender][keyof T[NodeType.Gender]], S>\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins = {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Gender,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Gender]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [...props.keyPath, { type: NodeType.Gender, key } as KeyPath],\n };\n result[key as keyof typeof result] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result, value);\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins => ({\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeType.Nested || node?.nodeType === 'nested'),\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }),\n});\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.File]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n gender: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin’s transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.mjs","names":[],"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"getDictionary.mjs","names":[],"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import type { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n Plugins,\n} from './getContent';\nimport { getContent } from './getContent/getContent';\n\n/**\n * Transforms a dictionary in a single pass, applying each plugin as needed.\n *\n * @param dictionary The dictionary to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n * @param additionalPlugins An array of NodeTransformer that define how to transform recognized nodes.\n * If omitted, we’ll use a default set of plugins.\n */\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n plugins?: Plugins[]\n): DeepTransformContent<T['content'], IInterpreterPluginState, L> => {\n const props: NodeProps = {\n dictionaryKey: dictionary.key,\n dictionaryPath: dictionary.filePath,\n keyPath: [],\n plugins,\n };\n\n return getContent(dictionary.content, props, locale, true);\n};\n"],"mappings":"yDAkBA,MAAa,GAIX,EACA,EACA,IACmE,CACnE,IAAM,EAAmB,CACvB,cAAe,EAAW,IAC1B,eAAgB,EAAW,SAC3B,QAAS,EAAE,CACX,UACD,CAED,OAAO,EAAW,EAAW,QAAS,EAAO,EAAQ,GAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.mjs","names":[],"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type {
|
|
1
|
+
{"version":3,"file":"getIntlayer.mjs","names":[],"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { DeclaredLocales, DictionaryKeys, DictionaryRegistryContent, DictionaryRegistryElement, LocalesValues } from '@intlayer/types/module_augmentation';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\n\n/**\n * Creates a Recursive Proxy that returns the path of the accessed key\n * stringified. This prevents the app from crashing on undefined access.\n */\nconst createSafeFallback = (path = ''): any => {\n return new Proxy(\n // Target is a function so it can be called if the dictionary expects a function\n () => path,\n {\n get: (_target, prop) => {\n // Handle common object methods to prevent infinite recursion or weird behavior\n if (\n prop === 'toJSON' ||\n prop === Symbol.toPrimitive ||\n prop === 'toString'\n ) {\n return () => path;\n }\n if (prop === 'then') {\n return undefined; // Prevent it from being treated as a Promise\n }\n\n // Recursively build the path (e.g., \"myDictionary.home.title\")\n const nextPath = path ? `${path}.${String(prop)}` : String(prop);\n return createSafeFallback(nextPath);\n },\n // If the code tries to execute the missing key as a function: t.title()\n apply: () => {\n return path;\n },\n }\n );\n};\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n plugins?: Plugins[]\n): DeepTransformContent<\n DictionaryRegistryContent<T>,\n IInterpreterPluginState,\n L\n> => {\n const dictionaries = getDictionaries();\n const dictionary = dictionaries[key as T] as DictionaryRegistryElement<T>;\n\n if (!dictionary) {\n // Log a warning instead of throwing (so developers know it's missing)\n const logger = getAppLogger(configuration);\n logger(\n `Dictionary ${colorizeKey(key as string)} was not found. Using fallback proxy.`,\n {\n level: 'warn',\n isVerbose: true,\n }\n );\n\n if (process.env.NODE_ENV === 'development') {\n // Return the Safe Proxy\n // We initialize it with the dictionary key name so the UI shows \"my-dictionary.someKey\"\n return createSafeFallback(key as string);\n }\n\n return createSafeFallback(key as string);\n }\n\n return getDictionary<DictionaryRegistryElement<T>, L>(\n dictionary,\n locale,\n plugins\n );\n};\n"],"mappings":"iOAeA,MAAM,GAAsB,EAAO,KAC1B,IAAI,UAEH,EACN,CACE,KAAM,EAAS,IAAS,CAEtB,GACE,IAAS,UACT,IAAS,OAAO,aAChB,IAAS,WAET,UAAa,EAEX,OAAS,OAMb,OAAO,EADU,EAAO,GAAG,EAAK,GAAG,OAAO,EAAK,GAAK,OAAO,EAAK,CAC7B,EAGrC,UACS,EAEV,CACF,CAGU,GAIX,EACA,EACA,IAKG,CAEH,IAAM,EADe,GAAiB,CACN,GAsBhC,OApBK,EAoBE,EACL,EACA,EACA,EACD,EAtBgB,EAAa,EAAc,CAExC,cAAc,EAAY,EAAc,CAAC,uCACzC,CACE,MAAO,OACP,UAAW,GACZ,CACF,CAQM,EAAmB,EAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNesting.mjs","names":[],"sources":["../../../src/interpreter/getNesting.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"getNesting.mjs","names":[],"sources":["../../../src/interpreter/getNesting.ts"],"sourcesContent":["import type { DictionaryKeys, DictionaryRegistryContent } from '@intlayer/types/module_augmentation';\nimport type { GetSubPath } from '@intlayer/types/dictionary';\nimport type { ValidDotPathsFor } from '../transpiler';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\n\nexport type GetNestingResult<\n K extends DictionaryKeys,\n P = undefined,\n S = IInterpreterPluginState,\n> = GetSubPath<DeepTransformContent<DictionaryRegistryContent<K>, S>, P>;\n\n/**\n * Extracts content from another dictionary by its key and an optional path.\n *\n * This allows for reusing content across different dictionaries.\n *\n * @param dictionaryKey - The key of the dictionary to nest.\n * @param path - Optional dot-separated path to a specific field within the nested dictionary.\n * @param props - Optional properties like locale and plugins.\n * @returns The nested content.\n *\n * @example\n * ```ts\n * const content = getNesting(\"common\", \"buttons.save\");\n * // 'Save'\n * ```\n */\nexport const getNesting = <K extends DictionaryKeys, P>(\n dictionaryKey: K,\n path?: P extends ValidDotPathsFor<K> ? P : never,\n props?: NodeProps\n): GetNestingResult<K, P> => {\n const dictionary = getIntlayer(dictionaryKey, props?.locale, props?.plugins);\n\n if (typeof path === 'string') {\n const pathArray = (path as string).split('.');\n let current: any = dictionary;\n\n for (const key of pathArray) {\n // Safely traverse down the object using the path\n current = current?.[key];\n // If we cannot find the path, return the whole dictionary as a fallback\n if (current === undefined) {\n return dictionary as any;\n }\n }\n\n return current;\n }\n\n // Default or error handling if path is not a string or otherwise undefined\n return dictionary as any;\n};\n"],"mappings":"gDAgCA,MAAa,GACX,EACA,EACA,IAC2B,CAC3B,IAAM,EAAa,EAAY,EAAe,GAAO,OAAQ,GAAO,QAAQ,CAE5E,GAAI,OAAO,GAAS,SAAU,CAC5B,IAAM,EAAa,EAAgB,MAAM,IAAI,CACzC,EAAe,EAEnB,IAAK,IAAM,KAAO,EAIhB,GAFA,EAAU,IAAU,GAEhB,IAAY,IAAA,GACd,OAAO,EAIX,OAAO,EAIT,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslation.mjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\n\n/**\n * Check if a value is a plain object that can be safely processed.\n * Returns false for Promises, React elements, class instances, etc.\n */\nconst isPlainObject = (value: unknown): boolean => {\n if (value === null || typeof value !== 'object') {\n return false;\n }\n\n // Don't process Promises (e.g., Next.js 15+ params)\n if (value instanceof Promise || typeof (value as any).then === 'function') {\n return false;\n }\n\n // Don't process React elements or other framework VNodes\n if (\n (value as any).$$typeof !== undefined ||\n (value as any).__v_isVNode !== undefined ||\n (value as any)._isVNode !== undefined ||\n (value as any).isJSX !== undefined\n ) {\n return false;\n }\n\n // Only process plain objects and arrays\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null || Array.isArray(value);\n};\n\n/**\n * Recursively merges two objects.\n * Resembles the behavior of `defu` but respects `isPlainObject` to avoid merging React elements.\n * Arrays are replaced, not merged.\n */\nconst deepMergeObjects = (target: any, source: any): any => {\n if (target === undefined) return source;\n if (source === undefined) return target;\n\n if (Array.isArray(target)) return target;\n\n if (isPlainObject(target) && isPlainObject(source)) {\n const result = { ...target };\n for (const key of Object.keys(source)) {\n if (key === '__proto__' || key === 'constructor') continue;\n\n if (Object.hasOwn(target, key)) {\n result[key] = deepMergeObjects(target[key], source[key]);\n } else {\n result[key] = source[key];\n }\n }\n return result;\n }\n\n return target;\n};\n\n/**\n * Recursively removes undefined values from an object.\n * Handles circular references by tracking visited objects.\n */\nconst removeUndefinedValues = <T>(\n object: T,\n visited = new WeakSet<object>()\n): T => {\n if (typeof object !== 'object' || object === null) {\n return object;\n }\n\n // Handle circular references - return original to avoid infinite recursion\n if (visited.has(object)) {\n return object;\n }\n visited.add(object);\n\n // Don't process non-plain objects (Promises, React elements, etc.)\n if (!isPlainObject(object)) {\n return object;\n }\n\n if (Array.isArray(object)) {\n return object.map((item) => removeUndefinedValues(item, visited)) as T;\n }\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(object)) {\n if (value !== undefined) {\n result[key] = removeUndefinedValues(value, visited);\n }\n }\n return result as T;\n};\n\n/**\n * Picks the appropriate content from a locale map based on the provided locale.\n *\n * It handles:\n * 1. Exact locale match (e.g., 'en-US').\n * 2. Generic locale fallback (e.g., 'en' if 'en-US' is not found).\n * 3. Explicit fallback locale.\n * 4. Deep merging of objects to ensure partial translations are complemented by fallbacks.\n *\n * @param languageContent - A map of locales to content.\n * @param locale - The target locale to retrieve.\n * @param fallback - Optional fallback locale if the target is not found.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * const content = getTranslation({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n */\nexport const getTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>,\n locale: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n const results: Content[] = [];\n\n const getContent = (loc: string) =>\n languageContent[loc as keyof typeof languageContent];\n\n // Get Target Content\n const content = getContent(locale);\n if (typeof content === 'string') {\n return content;\n } else if (content !== undefined) {\n results.push(content);\n }\n\n // Get Target Generic Content (e.g. 'en' from 'en-US')\n if (locale.includes('-')) {\n const genericLocale = locale.split('-')[0];\n if (genericLocale in languageContent) {\n const genericContent = getContent(genericLocale);\n\n if (typeof genericContent === 'string') {\n // If we haven't found specific content yet, return generic string\n if (results.length === 0) return genericContent;\n } else if (genericContent !== undefined) {\n results.push(genericContent);\n }\n }\n }\n\n // Get Fallback Content\n if (fallback !== undefined && fallback !== locale) {\n // 3a. Fallback Specific\n if (fallback in languageContent) {\n const fallbackContent = getContent(fallback);\n\n if (typeof fallbackContent === 'string') {\n if (results.length === 0) return fallbackContent;\n } else if (fallbackContent !== undefined) {\n results.push(fallbackContent);\n }\n }\n\n // Fallback Generic (The missing piece: e.g. 'en' from 'en-GB' fallback)\n if (fallback.includes('-')) {\n const genericFallback = fallback.split('-')[0];\n const genericLocale = locale.split('-')[0];\n\n // Only add if it's different from the target generic (to avoid duplication)\n // and exists in the dictionary\n if (\n genericFallback !== genericLocale &&\n genericFallback in languageContent\n ) {\n const genericFallbackContent = getContent(genericFallback);\n\n if (typeof genericFallbackContent === 'string') {\n if (results.length === 0) return genericFallbackContent;\n } else if (genericFallbackContent !== undefined) {\n results.push(genericFallbackContent);\n }\n }\n }\n }\n\n if (results.length === 0) {\n return undefined as Content;\n }\n\n // Clean undefined values so they don't overwrite fallbacks\n // Order: [Target, Generic, Fallback, FallbackGeneric]\n // defu first argument takes precedence, so Target wins\n const cleanResults = results\n .filter((item) => typeof item !== 'undefined')\n .map((item) => removeUndefinedValues(item));\n\n // If only one result, return it directly (no merging needed)\n if (cleanResults.length === 1) {\n return cleanResults[0];\n }\n\n // If the first result is an array, return it directly (arrays replace, don't merge)\n // defu would incorrectly convert arrays to objects with numeric keys\n if (Array.isArray(cleanResults[0])) {\n return cleanResults[0];\n }\n\n // Merge objects with custom merge - first argument takes precedence\n // Cast to object[] since by this point we've already returned early for strings, arrays, and single results\n return (cleanResults as object[]).reduce((acc, curr) =>\n deepMergeObjects(acc, curr)\n ) as Content;\n};\n"],"mappings":"AAMA,MAAM,EAAiB,GAA4B,CAWjD,GAVsB,OAAO,GAAU,WAAnC,GAKA,aAAiB,SAAW,OAAQ,EAAc,MAAS,YAM5D,EAAc,WAAa,IAAA,IAC3B,EAAc,cAAgB,IAAA,IAC9B,EAAc,WAAa,IAAA,IAC3B,EAAc,QAAU,IAAA,GAEzB,MAAO,GAIT,IAAM,EAAQ,OAAO,eAAe,EAAM,CAC1C,OAAO,IAAU,OAAO,WAAa,IAAU,MAAQ,MAAM,QAAQ,EAAM,EAQvE,GAAoB,EAAa,IAAqB,CAC1D,GAAI,IAAW,IAAA,GAAW,OAAO,EAGjC,GAFI,IAAW,IAAA,IAEX,MAAM,QAAQ,EAAO,CAAE,OAAO,EAElC,GAAI,EAAc,EAAO,EAAI,EAAc,EAAO,CAAE,CAClD,IAAM,EAAS,CAAE,GAAG,EAAQ,CAC5B,IAAK,IAAM,KAAO,OAAO,KAAK,EAAO,CAC/B,IAAQ,aAAe,IAAQ,gBAE/B,OAAO,OAAO,EAAQ,EAAI,CAC5B,EAAO,GAAO,EAAiB,EAAO,GAAM,EAAO,GAAK,CAExD,EAAO,GAAO,EAAO,IAGzB,OAAO,EAGT,OAAO,GAOH,GACJ,EACA,EAAU,IAAI,UACR,CAYN,GAXI,OAAO,GAAW,WAAY,GAK9B,EAAQ,IAAI,EAAO,GAGvB,EAAQ,IAAI,EAAO,CAGf,CAAC,EAAc,EAAO,EACxB,OAAO,EAGT,GAAI,MAAM,QAAQ,EAAO,CACvB,OAAO,EAAO,IAAK,GAAS,EAAsB,EAAM,EAAQ,CAAC,CAGnE,IAAM,EAAkC,EAAE,CAC1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAO,CAC3C,IAAU,IAAA,KACZ,EAAO,GAAO,EAAsB,EAAO,EAAQ,EAGvD,OAAO,GA0BI,GACX,EACA,EACA,IACY,CACZ,IAAM,EAAqB,EAAE,CAEvB,EAAc,GAClB,EAAgB,GAGZ,EAAU,EAAW,EAAO,CAClC,GAAI,OAAO,GAAY,SACrB,OAAO,EAMT,GALW,IAAY,IAAA,IACrB,EAAQ,KAAK,EAAQ,CAInB,EAAO,SAAS,IAAI,CAAE,CACxB,IAAM,EAAgB,EAAO,MAAM,IAAI,CAAC,GACxC,GAAI,KAAiB,EAAiB,CACpC,IAAM,EAAiB,EAAW,EAAc,CAEhD,GAAI,OAAO,GAAmB,aAExB,EAAQ,SAAW,EAAG,OAAO,OACxB,IAAmB,IAAA,IAC5B,EAAQ,KAAK,EAAe,EAMlC,GAAI,IAAa,IAAA,IAAa,IAAa,EAAQ,CAEjD,GAAI,KAAY,EAAiB,CAC/B,IAAM,EAAkB,EAAW,EAAS,CAE5C,GAAI,OAAO,GAAoB,aACzB,EAAQ,SAAW,EAAG,OAAO,OACxB,IAAoB,IAAA,IAC7B,EAAQ,KAAK,EAAgB,CAKjC,GAAI,EAAS,SAAS,IAAI,CAAE,CAC1B,IAAM,EAAkB,EAAS,MAAM,IAAI,CAAC,GAK5C,GACE,IALoB,EAAO,MAAM,IAAI,CAAC,IAMtC,KAAmB,EACnB,CACA,IAAM,EAAyB,EAAW,EAAgB,CAE1D,GAAI,OAAO,GAA2B,aAChC,EAAQ,SAAW,EAAG,OAAO,OACxB,IAA2B,IAAA,IACpC,EAAQ,KAAK,EAAuB,GAM5C,GAAI,EAAQ,SAAW,EACrB,OAMF,IAAM,EAAe,EAClB,OAAQ,GAAgB,IAAS,OAAY,CAC7C,IAAK,GAAS,EAAsB,EAAK,CAAC,CAe7C,OAZI,EAAa,SAAW,GAMxB,MAAM,QAAQ,EAAa,GAAG,CACzB,EAAa,GAKd,EAA0B,QAAQ,EAAK,IAC7C,EAAiB,EAAK,EAAK,CAC5B"}
|
|
1
|
+
{"version":3,"file":"getTranslation.mjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely processed.\n * Returns false for Promises, React elements, class instances, etc.\n */\nconst isPlainObject = (value: unknown): boolean => {\n if (value === null || typeof value !== 'object') {\n return false;\n }\n\n // Don't process Promises (e.g., Next.js 15+ params)\n if (value instanceof Promise || typeof (value as any).then === 'function') {\n return false;\n }\n\n // Don't process React elements or other framework VNodes\n if (\n (value as any).$$typeof !== undefined ||\n (value as any).__v_isVNode !== undefined ||\n (value as any)._isVNode !== undefined ||\n (value as any).isJSX !== undefined\n ) {\n return false;\n }\n\n // Only process plain objects and arrays\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null || Array.isArray(value);\n};\n\n/**\n * Recursively merges two objects.\n * Resembles the behavior of `defu` but respects `isPlainObject` to avoid merging React elements.\n * Arrays are replaced, not merged.\n */\nconst deepMergeObjects = (target: any, source: any): any => {\n if (target === undefined) return source;\n if (source === undefined) return target;\n\n if (Array.isArray(target)) return target;\n\n if (isPlainObject(target) && isPlainObject(source)) {\n const result = { ...target };\n for (const key of Object.keys(source)) {\n if (key === '__proto__' || key === 'constructor') continue;\n\n if (Object.hasOwn(target, key)) {\n result[key] = deepMergeObjects(target[key], source[key]);\n } else {\n result[key] = source[key];\n }\n }\n return result;\n }\n\n return target;\n};\n\n/**\n * Recursively removes undefined values from an object.\n * Handles circular references by tracking visited objects.\n */\nconst removeUndefinedValues = <T>(\n object: T,\n visited = new WeakSet<object>()\n): T => {\n if (typeof object !== 'object' || object === null) {\n return object;\n }\n\n // Handle circular references - return original to avoid infinite recursion\n if (visited.has(object)) {\n return object;\n }\n visited.add(object);\n\n // Don't process non-plain objects (Promises, React elements, etc.)\n if (!isPlainObject(object)) {\n return object;\n }\n\n if (Array.isArray(object)) {\n return object.map((item) => removeUndefinedValues(item, visited)) as T;\n }\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(object)) {\n if (value !== undefined) {\n result[key] = removeUndefinedValues(value, visited);\n }\n }\n return result as T;\n};\n\n/**\n * Picks the appropriate content from a locale map based on the provided locale.\n *\n * It handles:\n * 1. Exact locale match (e.g., 'en-US').\n * 2. Generic locale fallback (e.g., 'en' if 'en-US' is not found).\n * 3. Explicit fallback locale.\n * 4. Deep merging of objects to ensure partial translations are complemented by fallbacks.\n *\n * @param languageContent - A map of locales to content.\n * @param locale - The target locale to retrieve.\n * @param fallback - Optional fallback locale if the target is not found.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * const content = getTranslation({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n */\nexport const getTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>,\n locale: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n const results: Content[] = [];\n\n const getContent = (loc: string) =>\n languageContent[loc as keyof typeof languageContent];\n\n // Get Target Content\n const content = getContent(locale);\n if (typeof content === 'string') {\n return content;\n } else if (content !== undefined) {\n results.push(content);\n }\n\n // Get Target Generic Content (e.g. 'en' from 'en-US')\n if (locale.includes('-')) {\n const genericLocale = locale.split('-')[0];\n if (genericLocale in languageContent) {\n const genericContent = getContent(genericLocale);\n\n if (typeof genericContent === 'string') {\n // If we haven't found specific content yet, return generic string\n if (results.length === 0) return genericContent;\n } else if (genericContent !== undefined) {\n results.push(genericContent);\n }\n }\n }\n\n // Get Fallback Content\n if (fallback !== undefined && fallback !== locale) {\n // 3a. Fallback Specific\n if (fallback in languageContent) {\n const fallbackContent = getContent(fallback);\n\n if (typeof fallbackContent === 'string') {\n if (results.length === 0) return fallbackContent;\n } else if (fallbackContent !== undefined) {\n results.push(fallbackContent);\n }\n }\n\n // Fallback Generic (The missing piece: e.g. 'en' from 'en-GB' fallback)\n if (fallback.includes('-')) {\n const genericFallback = fallback.split('-')[0];\n const genericLocale = locale.split('-')[0];\n\n // Only add if it's different from the target generic (to avoid duplication)\n // and exists in the dictionary\n if (\n genericFallback !== genericLocale &&\n genericFallback in languageContent\n ) {\n const genericFallbackContent = getContent(genericFallback);\n\n if (typeof genericFallbackContent === 'string') {\n if (results.length === 0) return genericFallbackContent;\n } else if (genericFallbackContent !== undefined) {\n results.push(genericFallbackContent);\n }\n }\n }\n }\n\n if (results.length === 0) {\n return undefined as Content;\n }\n\n // Clean undefined values so they don't overwrite fallbacks\n // Order: [Target, Generic, Fallback, FallbackGeneric]\n // defu first argument takes precedence, so Target wins\n const cleanResults = results\n .filter((item) => typeof item !== 'undefined')\n .map((item) => removeUndefinedValues(item));\n\n // If only one result, return it directly (no merging needed)\n if (cleanResults.length === 1) {\n return cleanResults[0];\n }\n\n // If the first result is an array, return it directly (arrays replace, don't merge)\n // defu would incorrectly convert arrays to objects with numeric keys\n if (Array.isArray(cleanResults[0])) {\n return cleanResults[0];\n }\n\n // Merge objects with custom merge - first argument takes precedence\n // Cast to object[] since by this point we've already returned early for strings, arrays, and single results\n return (cleanResults as object[]).reduce((acc, curr) =>\n deepMergeObjects(acc, curr)\n ) as Content;\n};\n"],"mappings":"AAMA,MAAM,EAAiB,GAA4B,CAWjD,GAVsB,OAAO,GAAU,WAAnC,GAKA,aAAiB,SAAW,OAAQ,EAAc,MAAS,YAM5D,EAAc,WAAa,IAAA,IAC3B,EAAc,cAAgB,IAAA,IAC9B,EAAc,WAAa,IAAA,IAC3B,EAAc,QAAU,IAAA,GAEzB,MAAO,GAIT,IAAM,EAAQ,OAAO,eAAe,EAAM,CAC1C,OAAO,IAAU,OAAO,WAAa,IAAU,MAAQ,MAAM,QAAQ,EAAM,EAQvE,GAAoB,EAAa,IAAqB,CAC1D,GAAI,IAAW,IAAA,GAAW,OAAO,EAGjC,GAFI,IAAW,IAAA,IAEX,MAAM,QAAQ,EAAO,CAAE,OAAO,EAElC,GAAI,EAAc,EAAO,EAAI,EAAc,EAAO,CAAE,CAClD,IAAM,EAAS,CAAE,GAAG,EAAQ,CAC5B,IAAK,IAAM,KAAO,OAAO,KAAK,EAAO,CAC/B,IAAQ,aAAe,IAAQ,gBAE/B,OAAO,OAAO,EAAQ,EAAI,CAC5B,EAAO,GAAO,EAAiB,EAAO,GAAM,EAAO,GAAK,CAExD,EAAO,GAAO,EAAO,IAGzB,OAAO,EAGT,OAAO,GAOH,GACJ,EACA,EAAU,IAAI,UACR,CAYN,GAXI,OAAO,GAAW,WAAY,GAK9B,EAAQ,IAAI,EAAO,GAGvB,EAAQ,IAAI,EAAO,CAGf,CAAC,EAAc,EAAO,EACxB,OAAO,EAGT,GAAI,MAAM,QAAQ,EAAO,CACvB,OAAO,EAAO,IAAK,GAAS,EAAsB,EAAM,EAAQ,CAAC,CAGnE,IAAM,EAAkC,EAAE,CAC1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAO,CAC3C,IAAU,IAAA,KACZ,EAAO,GAAO,EAAsB,EAAO,EAAQ,EAGvD,OAAO,GA0BI,GACX,EACA,EACA,IACY,CACZ,IAAM,EAAqB,EAAE,CAEvB,EAAc,GAClB,EAAgB,GAGZ,EAAU,EAAW,EAAO,CAClC,GAAI,OAAO,GAAY,SACrB,OAAO,EAMT,GALW,IAAY,IAAA,IACrB,EAAQ,KAAK,EAAQ,CAInB,EAAO,SAAS,IAAI,CAAE,CACxB,IAAM,EAAgB,EAAO,MAAM,IAAI,CAAC,GACxC,GAAI,KAAiB,EAAiB,CACpC,IAAM,EAAiB,EAAW,EAAc,CAEhD,GAAI,OAAO,GAAmB,aAExB,EAAQ,SAAW,EAAG,OAAO,OACxB,IAAmB,IAAA,IAC5B,EAAQ,KAAK,EAAe,EAMlC,GAAI,IAAa,IAAA,IAAa,IAAa,EAAQ,CAEjD,GAAI,KAAY,EAAiB,CAC/B,IAAM,EAAkB,EAAW,EAAS,CAE5C,GAAI,OAAO,GAAoB,aACzB,EAAQ,SAAW,EAAG,OAAO,OACxB,IAAoB,IAAA,IAC7B,EAAQ,KAAK,EAAgB,CAKjC,GAAI,EAAS,SAAS,IAAI,CAAE,CAC1B,IAAM,EAAkB,EAAS,MAAM,IAAI,CAAC,GAK5C,GACE,IALoB,EAAO,MAAM,IAAI,CAAC,IAMtC,KAAmB,EACnB,CACA,IAAM,EAAyB,EAAW,EAAgB,CAE1D,GAAI,OAAO,GAA2B,aAChC,EAAQ,SAAW,EAAG,OAAO,OACxB,IAA2B,IAAA,IACpC,EAAQ,KAAK,EAAuB,GAM5C,GAAI,EAAQ,SAAW,EACrB,OAMF,IAAM,EAAe,EAClB,OAAQ,GAAgB,IAAS,OAAY,CAC7C,IAAK,GAAS,EAAsB,EAAK,CAAC,CAe7C,OAZI,EAAa,SAAW,GAMxB,MAAM,QAAQ,EAAa,GAAG,CACzB,EAAa,GAKd,EAA0B,QAAQ,EAAK,IAC7C,EAAiB,EAAK,EAAK,CAC5B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getLocaleFromStorage as e}from"../utils/localeStorage.mjs";import{localeDetector as t}from"./localeDetector.mjs";import
|
|
1
|
+
import{getLocaleFromStorage as e}from"../utils/localeStorage.mjs";import{localeDetector as t}from"./localeDetector.mjs";import n from"@intlayer/config/built";import*as r from"@intlayer/types/locales";let i=function(e){return e.Querystring=`querystring`,e.Storage=`storage`,e.Navigator=`navigator`,e.HtmlTag=`htmlTag`,e}({});const a={getCookie:e=>document.cookie.split(`;`).find(t=>t.trim().startsWith(`${e}=`))?.split(`=`)[1],getLocaleStorage:e=>localStorage.getItem(e),getSessionStorage:e=>sessionStorage.getItem(e),isCookieEnabled:!0,setCookieStore:(e,t,n)=>cookieStore.set({name:e,value:t,path:n.path,domain:n.domain,expires:n.expires,sameSite:n.sameSite}),setCookieString:(e,t)=>{document.cookie=t},setSessionStorage:(e,t)=>sessionStorage.setItem(e,t),setLocaleStorage:(e,t)=>localStorage.setItem(e,t)},o=()=>({order:[i.Querystring,i.Storage,i.Navigator,i.HtmlTag],lookupQuerystring:`locale`,htmlTag:typeof document<`u`?document.documentElement:null}),s=(r,a)=>{let o={},s=()=>{if(typeof window>`u`)return;let e=window.location.search||``,t=new URLSearchParams(e).get(a.lookupQuerystring??``);t&&(o[i.Querystring]=t)},c=()=>{if(typeof window>`u`)return;let t=e({getCookie:e=>{try{let t=document.cookie.split(`;`),n=`${e}=`,r=t.find(e=>e.trim().startsWith(n));if(r)return r.split(`=`)[1].trim()}catch{}},getSessionStorage:e=>{try{return window.sessionStorage.getItem(e)??void 0}catch{}},getLocaleStorage:e=>{try{return window.localStorage.getItem(e)??void 0}catch{}}});t&&(o[i.Storage]=t)},l=()=>{if(typeof navigator>`u`)return;let{internationalization:e}=n,r=navigator.languages??[navigator.language],a=t({"accept-language":r.join(`,`)},e.locales,e.defaultLocale);a&&(o[i.Navigator]=a)},u=()=>{let e=a.htmlTag;if(e&&typeof e.getAttribute==`function`){let r=e.getAttribute(`lang`);if(r){let{internationalization:e}=n,a=t({"accept-language":r},e.locales,e.defaultLocale);o[i.HtmlTag]=a}}},d={[i.Querystring]:s,[i.Storage]:c,[i.Navigator]:l,[i.HtmlTag]:u};return r.forEach(e=>{d[e]?.()}),o},c=(e,t)=>{let{internationalization:i}=n;for(let n of t){let t=e[n];if(t&&i.locales.includes(t))return t}return i?.defaultLocale??r.ENGLISH},l=(e={})=>{let t={...o(),...e};return c(s(t.order??[],t),t.order??[])};export{i as LanguageDetector,l as getBrowserLocale,a as localeStorageOptions};
|
|
2
2
|
//# sourceMappingURL=getBrowserLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBrowserLocale.mjs","names":[],"sources":["../../../src/localization/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"getBrowserLocale.mjs","names":[],"sources":["../../../src/localization/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport * as Locales from '@intlayer/types/locales';\nimport {\n getLocaleFromStorage,\n type LocaleStorageOptions,\n} from '../utils/localeStorage';\nimport { localeDetector } from './localeDetector';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Storage = 'storage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\nexport const localeStorageOptions: LocaleStorageOptions = {\n getCookie: (name: string) =>\n document.cookie\n .split(';')\n .find((c) => c.trim().startsWith(`${name}=`))\n ?.split('=')[1],\n getLocaleStorage: (name: string) => localStorage.getItem(name),\n getSessionStorage: (name: string) => sessionStorage.getItem(name),\n isCookieEnabled: true,\n setCookieStore: (name, value, attributes) =>\n cookieStore.set({\n name,\n value,\n path: attributes.path,\n domain: attributes.domain,\n expires: attributes.expires,\n sameSite: attributes.sameSite,\n }),\n setCookieString: (_name, cookie) => {\n // biome-ignore lint/suspicious/noDocumentCookie: set cookie fallback\n document.cookie = cookie;\n },\n setSessionStorage: (name, value) => sessionStorage.setItem(name, value),\n setLocaleStorage: (name, value) => localStorage.setItem(name, value),\n};\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Storage,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n htmlTag: typeof document !== 'undefined' ? document.documentElement : null,\n };\n};\n\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locale | undefined> => {\n const detected: Record<LanguageDetector, Locale | undefined> = {} as Record<\n LanguageDetector,\n Locale | undefined\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locale;\n }\n };\n\n const storageDetector = () => {\n if (typeof window === 'undefined') return;\n\n const locale = getLocaleFromStorage({\n getCookie: (name: string) => {\n try {\n const cookies = document.cookie.split(';');\n const cookieName = `${name}=`;\n\n const cookie = cookies.find((cookie) =>\n cookie.trim().startsWith(cookieName)\n );\n\n if (cookie) {\n return cookie.split('=')[1].trim();\n }\n } catch {}\n return undefined;\n },\n getSessionStorage: (name: string) => {\n try {\n return window.sessionStorage.getItem(name) ?? undefined;\n } catch {}\n return undefined;\n },\n getLocaleStorage: (name: string) => {\n try {\n return window.localStorage.getItem(name) ?? undefined;\n } catch {}\n return undefined;\n },\n });\n\n if (locale) {\n detected[LanguageDetector.Storage] = locale;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n const { internationalization } = configuration;\n const languages = navigator.languages ?? [navigator.language];\n\n // Use localeDetector to find the best matching locale\n const locale = localeDetector(\n { 'accept-language': languages.join(',') },\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n if (locale) {\n detected[LanguageDetector.Navigator] = locale;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n const { internationalization } = configuration;\n\n // Validate and resolve the locale\n const locale = localeDetector(\n { 'accept-language': lang },\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n detected[LanguageDetector.HtmlTag] = locale;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Storage]: storageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locale | undefined>,\n order: LanguageDetector[]\n): Locale => {\n const { internationalization } = configuration;\n\n for (const detector of order) {\n const locale = locales[detector];\n\n if (locale && internationalization.locales.includes(locale)) {\n return locale;\n }\n }\n\n return internationalization?.defaultLocale ?? Locales.ENGLISH;\n};\n\n/**\n * Core language detector function for browser environments.\n *\n * Detects the user's preferred locale by checking multiple sources in order:\n * 1. Query string parameter\n * 2. Storage (cookies, localStorage, sessionStorage) - uses getLocaleFromStorage\n * 3. Navigator languages - uses localeDetector\n * 4. HTML lang attribute - uses localeDetector\n *\n * @param userOptions - Optional configuration for detection order and lookup keys\n * @returns The detected locale or the default locale\n *\n * @example\n * const locale = getBrowserLocale({ order: [LanguageDetector.Storage, LanguageDetector.Navigator] });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locale => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import*as e from"@intlayer/types/locales";const t=t=>{switch(t){case e.ARABIC:case e.ARABIC_UNITED_ARAB_EMIRATES:case e.ARABIC_BAHRAIN:case e.ARABIC_ALGERIA:case e.ARABIC_EGYPT:case e.ARABIC_IRAQ:case e.ARABIC_JORDAN:case e.ARABIC_KUWAIT:case e.ARABIC_LEBANON:case e.ARABIC_LIBYA:case e.ARABIC_MOROCCO:case e.ARABIC_OMAN:case e.ARABIC_QATAR:case e.ARABIC_SAUDI_ARABIA:case e.ARABIC_SYRIA:case e.ARABIC_TUNISIA:case e.ARABIC_YEMEN:case e.ARABIC_MAURITANIA:case e.ARABIC_PALESTINE:case e.ARABIC_SUDAN:case e.ARABIC_DJIBOUTI:case e.ARABIC_SOMALIA:case e.ARABIC_CHAD:case e.ARABIC_COMOROS:case e.HEBREW:case e.HEBREW_ISRAEL:case e.FARSI:case e.FARSI_IRAN:case e.URDU:case e.URDU_ISLAMIC_REPUBLIC_OF_PAKISTAN:case e.PASHTO:case e.PASHTO_AFGHANISTAN:case e.SYRIAC:case e.SYRIAC_SYRIA:case e.DIVEHI:case e.DIVEHI_MALDIVES:case e.YIDDISH:case e.YIDDISH_WORLD:return`rtl`;default:return`ltr`}};export{t as getHTMLTextDir};
|
|
2
2
|
//# sourceMappingURL=getHTMLTextDir.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHTMLTextDir.mjs","names":[],"sources":["../../../src/localization/getHTMLTextDir.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"getHTMLTextDir.mjs","names":[],"sources":["../../../src/localization/getHTMLTextDir.ts"],"sourcesContent":["import * as Locales from '@intlayer/types/locales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\ntype Dir = 'ltr' | 'rtl' | 'auto';\n\n/**\n * Returns the text direction of the given locale.\n *\n * Example:\n *\n * getHTMLTextDir('en-US') // 'ltr'\n * getHTMLTextDir('en') // 'ltr'\n * getHTMLTextDir('fr-CA') // 'ltr'\n * getHTMLTextDir('fr') // 'ltr'\n *\n * @param locale The locale to get the text direction for.\n * @returns The text direction of the given locale.\n */\nexport const getHTMLTextDir = (locale?: LocalesValues): Dir => {\n switch (locale) {\n // Arabic (uses Arabic script)\n case Locales.ARABIC:\n case Locales.ARABIC_UNITED_ARAB_EMIRATES:\n case Locales.ARABIC_BAHRAIN:\n case Locales.ARABIC_ALGERIA:\n case Locales.ARABIC_EGYPT:\n case Locales.ARABIC_IRAQ:\n case Locales.ARABIC_JORDAN:\n case Locales.ARABIC_KUWAIT:\n case Locales.ARABIC_LEBANON:\n case Locales.ARABIC_LIBYA:\n case Locales.ARABIC_MOROCCO:\n case Locales.ARABIC_OMAN:\n case Locales.ARABIC_QATAR:\n case Locales.ARABIC_SAUDI_ARABIA:\n case Locales.ARABIC_SYRIA:\n case Locales.ARABIC_TUNISIA:\n case Locales.ARABIC_YEMEN:\n case Locales.ARABIC_MAURITANIA:\n case Locales.ARABIC_PALESTINE:\n case Locales.ARABIC_SUDAN:\n case Locales.ARABIC_DJIBOUTI:\n case Locales.ARABIC_SOMALIA:\n case Locales.ARABIC_CHAD:\n case Locales.ARABIC_COMOROS:\n // Hebrew (uses Hebrew script)\n case Locales.HEBREW:\n case Locales.HEBREW_ISRAEL:\n // Farsi/Persian (uses Arabic script)\n case Locales.FARSI:\n case Locales.FARSI_IRAN:\n // Urdu (uses Arabic script)\n case Locales.URDU:\n case Locales.URDU_ISLAMIC_REPUBLIC_OF_PAKISTAN:\n // Pashto (uses Arabic script)\n case Locales.PASHTO:\n case Locales.PASHTO_AFGHANISTAN:\n // Syriac (uses Syriac script)\n case Locales.SYRIAC:\n case Locales.SYRIAC_SYRIA:\n // Divehi (uses Thaana script)\n case Locales.DIVEHI:\n case Locales.DIVEHI_MALDIVES:\n // Yiddish (uses Hebrew script)\n case Locales.YIDDISH:\n case Locales.YIDDISH_WORLD:\n return 'rtl';\n\n default:\n return 'ltr';\n }\n};\n"],"mappings":"0CAkBA,MAAa,EAAkB,GAAgC,CAC7D,OAAQ,EAAR,CAEE,KAAK,EAAQ,OACb,KAAK,EAAQ,4BACb,KAAK,EAAQ,eACb,KAAK,EAAQ,eACb,KAAK,EAAQ,aACb,KAAK,EAAQ,YACb,KAAK,EAAQ,cACb,KAAK,EAAQ,cACb,KAAK,EAAQ,eACb,KAAK,EAAQ,aACb,KAAK,EAAQ,eACb,KAAK,EAAQ,YACb,KAAK,EAAQ,aACb,KAAK,EAAQ,oBACb,KAAK,EAAQ,aACb,KAAK,EAAQ,eACb,KAAK,EAAQ,aACb,KAAK,EAAQ,kBACb,KAAK,EAAQ,iBACb,KAAK,EAAQ,aACb,KAAK,EAAQ,gBACb,KAAK,EAAQ,eACb,KAAK,EAAQ,YACb,KAAK,EAAQ,eAEb,KAAK,EAAQ,OACb,KAAK,EAAQ,cAEb,KAAK,EAAQ,MACb,KAAK,EAAQ,WAEb,KAAK,EAAQ,KACb,KAAK,EAAQ,kCAEb,KAAK,EAAQ,OACb,KAAK,EAAQ,mBAEb,KAAK,EAAQ,OACb,KAAK,EAAQ,aAEb,KAAK,EAAQ,OACb,KAAK,EAAQ,gBAEb,KAAK,EAAQ,QACb,KAAK,EAAQ,cACX,MAAO,MAET,QACE,MAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.mjs","names":[],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { Locale } from '@intlayer/types';\nimport { getLocaleFromStorage } from '../utils/localeStorage';\nimport { getPreferredLanguages } from './localeDetector';\nimport { localeResolver } from './localeResolver';\n\nexport type RequestContext = {\n getHeader?: (name: string) => string | null | undefined;\n getCookie?: (name: string) => string | null | undefined;\n};\n\nexport const getLocale = async (ctx: RequestContext = {}): Promise<Locale> => {\n const defaultLocale =\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE;\n const availableLocales =\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES;\n\n // Try locale from storage (cookie or header)\n const storedLocale = getLocaleFromStorage({\n getCookie: ctx.getCookie,\n getHeader: ctx.getHeader,\n });\n\n if (storedLocale) {\n return storedLocale;\n }\n\n // Fallback to Accept-Language negotiation\n const acceptLanguageHeader = ctx.getHeader?.('accept-language');\n\n if (!acceptLanguageHeader) {\n return defaultLocale;\n }\n\n const preferredLocaleStrings = getPreferredLanguages(\n acceptLanguageHeader,\n availableLocales\n );\n\n const userFallbackLocale = localeResolver(\n preferredLocaleStrings,\n availableLocales,\n defaultLocale\n );\n\n if (userFallbackLocale) {\n return userFallbackLocale;\n }\n\n // Default locale\n return defaultLocale;\n};\n"],"mappings":"mRAYA,MAAa,EAAY,MAAO,EAAsB,EAAE,GAAsB,CAC5E,IAAM,EACJ,GAAe,sBAAsB,eACrC,EAAc,qBAAqB,eAC/B,EACJ,GAAe,sBAAsB,SACrC,EAAc,qBAAqB,QAG/B,EAAe,EAAqB,CACxC,UAAW,EAAI,UACf,UAAW,EAAI,UAChB,CAAC,CAEF,GAAI,EACF,OAAO,EAIT,IAAM,EAAuB,EAAI,YAAY,kBAAkB,CAsB/D,OApBK,GASsB,EALI,EAC7B,EACA,EACD,CAIC,EACA,EACD,EAZQ"}
|
|
1
|
+
{"version":3,"file":"getLocale.mjs","names":[],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getLocaleFromStorage } from '../utils/localeStorage';\nimport { getPreferredLanguages } from './localeDetector';\nimport { localeResolver } from './localeResolver';\n\nexport type RequestContext = {\n getHeader?: (name: string) => string | null | undefined;\n getCookie?: (name: string) => string | null | undefined;\n};\n\nexport const getLocale = async (ctx: RequestContext = {}): Promise<Locale> => {\n const defaultLocale =\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE;\n const availableLocales =\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES;\n\n // Try locale from storage (cookie or header)\n const storedLocale = getLocaleFromStorage({\n getCookie: ctx.getCookie,\n getHeader: ctx.getHeader,\n });\n\n if (storedLocale) {\n return storedLocale;\n }\n\n // Fallback to Accept-Language negotiation\n const acceptLanguageHeader = ctx.getHeader?.('accept-language');\n\n if (!acceptLanguageHeader) {\n return defaultLocale;\n }\n\n const preferredLocaleStrings = getPreferredLanguages(\n acceptLanguageHeader,\n availableLocales\n );\n\n const userFallbackLocale = localeResolver(\n preferredLocaleStrings,\n availableLocales,\n defaultLocale\n );\n\n if (userFallbackLocale) {\n return userFallbackLocale;\n }\n\n // Default locale\n return defaultLocale;\n};\n"],"mappings":"mRAYA,MAAa,EAAY,MAAO,EAAsB,EAAE,GAAsB,CAC5E,IAAM,EACJ,GAAe,sBAAsB,eACrC,EAAc,qBAAqB,eAC/B,EACJ,GAAe,sBAAsB,SACrC,EAAc,qBAAqB,QAG/B,EAAe,EAAqB,CACxC,UAAW,EAAI,UACf,UAAW,EAAI,UAChB,CAAC,CAEF,GAAI,EACF,OAAO,EAIT,IAAM,EAAuB,EAAI,YAAY,kBAAkB,CAsB/D,OApBK,GASsB,EALI,EAC7B,EACA,EACD,CAIC,EACA,EACD,EAZQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromPath.mjs","names":[],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type {
|
|
1
|
+
{"version":3,"file":"getLocaleFromPath.mjs","names":[],"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\ntype GetLocaleFromPathOptions = {\n defaultLocale?: LocalesValues;\n locales?: LocalesValues[];\n mode?: RoutingConfig['mode'];\n};\n\n/**\n * Extracts the locale segment from the given URL or pathname based on the routing mode.\n *\n * Mode Behaviors:\n * - 'prefix-no-default': Checks path prefiIf no prefix found, assumes default locale.\n * - 'prefix-all': Checks path prefix.\n * - 'search-params': Checks for 'locale' query parameter.\n * - 'no-prefix': Returns undefined (or default if fallback is true).\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @returns The detected locale, default locale (if fallback/implicit), or undefined.\n */\nexport const getLocaleFromPath = (\n inputUrl: string = '/',\n options?: GetLocaleFromPathOptions\n): Locale | undefined => {\n const { defaultLocale, locales, mode } = {\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 (!defaultLocale || !locales) {\n return DefaultValues.Internationalization.DEFAULT_LOCALE;\n }\n\n // Prepare the URL object\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n let fixedInputUrl = inputUrl;\n\n if (inputUrl?.endsWith('/') && inputUrl.length > 1) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n // Handle 'search-params' mode\n // Example: /dashboard?locale=fr\n if (mode === 'search-params') {\n const localeParam = url.searchParams.get('locale');\n\n if (localeParam && locales.includes(localeParam)) {\n return localeParam as Locale;\n }\n\n return defaultLocale as Locale;\n }\n\n // Handle 'no-prefix' mode\n // The locale is not stored in the URL path.\n if (mode === 'no-prefix') {\n return defaultLocale as Locale;\n }\n\n // Handle Prefix Modes ('prefix-all' | 'prefix-no-default')\n const pathname = url.pathname;\n\n // Split the pathname to extract the first segment\n // pathSegments[0] is empty string because path starts with /\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1];\n\n // Check if the first segment is a valid supported locale\n const isSegmentLocale = firstSegment && locales.includes(firstSegment);\n\n if (isSegmentLocale) {\n return firstSegment as Locale;\n }\n\n // If the first segment is NOT a locale (e./dashboard), handle based on mode\n if (mode === 'prefix-no-default') {\n // In this mode, absence of a prefix implies the default locale\n return defaultLocale as Locale;\n }\n\n return undefined;\n};\n"],"mappings":"mKAyBA,MAAa,GACX,EAAmB,IACnB,IACuB,CACvB,GAAM,CAAE,gBAAe,UAAS,QAAS,CACvC,cACE,GAAe,sBAAsB,eACrC,EAAc,qBAAqB,eACrC,KAAM,GAAe,SAAS,MAAQ,EAAc,QAAQ,aAC5D,QACE,GAAe,sBAAsB,SACrC,EAAc,qBAAqB,QACrC,GAAG,EACJ,CAED,GAAI,CAAC,GAAiB,CAAC,EACrB,OAAO,EAAc,qBAAqB,eAI5C,IAAM,EAAgB,EAAmB,EAAS,CAC9C,EAAgB,EAEhB,GAAU,SAAS,IAAI,EAAI,EAAS,OAAS,IAC/C,EAAgB,EAAS,MAAM,EAAG,GAAG,EAIvC,IAAM,EAAM,EACR,IAAI,IAAI,EAAc,CACtB,IAAI,IAAI,EAAe,qBAAqB,CAIhD,GAAI,IAAS,gBAAiB,CAC5B,IAAM,EAAc,EAAI,aAAa,IAAI,SAAS,CAMlD,OAJI,GAAe,EAAQ,SAAS,EAAY,CACvC,EAGF,EAKT,GAAI,IAAS,YACX,OAAO,EAST,IAAM,EALW,EAAI,SAIS,MAAM,IAAI,CACN,GAKlC,GAFwB,GAAgB,EAAQ,SAAS,EAAa,CAGpE,OAAO,EAIT,GAAI,IAAS,oBAEX,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleLang.mjs","names":[],"sources":["../../../src/localization/getLocaleLang.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types';\n\n/**\n * Returns the language code of the given locale for locales including the country code.\n *\n * Example:\n *\n * getLocaleLang('en-US') // 'en'\n * getLocaleLang('en') // 'en'\n * getLocaleLang('fr-CA') // 'fr'\n * getLocaleLang('fr') // 'fr'\n *\n * @param locale The locale to get the language code for.\n * @returns The language code of the given locale.\n */\nexport const getLocaleLang = (locale?: LocalesValues): string =>\n locale?.split('-')[0] ?? '';\n"],"mappings":"AAeA,MAAa,EAAiB,GAC5B,GAAQ,MAAM,IAAI,CAAC,IAAM"}
|
|
1
|
+
{"version":3,"file":"getLocaleLang.mjs","names":[],"sources":["../../../src/localization/getLocaleLang.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Returns the language code of the given locale for locales including the country code.\n *\n * Example:\n *\n * getLocaleLang('en-US') // 'en'\n * getLocaleLang('en') // 'en'\n * getLocaleLang('fr-CA') // 'fr'\n * getLocaleLang('fr') // 'fr'\n *\n * @param locale The locale to get the language code for.\n * @returns The language code of the given locale.\n */\nexport const getLocaleLang = (locale?: LocalesValues): string =>\n locale?.split('-')[0] ?? '';\n"],"mappings":"AAeA,MAAa,EAAiB,GAC5B,GAAQ,MAAM,IAAI,CAAC,IAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleName.mjs","names":[],"sources":["../../../src/localization/getLocaleName.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types';\nimport { CachedIntl } from '../utils/intl';\n\nexport const getLocaleName = (\n displayLocale: LocalesValues,\n targetLocale: LocalesValues = displayLocale\n): string => {\n // new Intl.DisplayNames() is fairly heavy: under the hood every call parses CLDR data and builds a resolver table. In your LocaleSwitcher it’s invoked:\n const displayNames = new CachedIntl.DisplayNames(targetLocale, {\n type: 'language',\n });\n\n return displayNames.of(displayLocale) ?? 'Unknown locale';\n};\n"],"mappings":"+CAGA,MAAa,GACX,EACA,EAA8B,IAGT,IAAI,EAAW,aAAa,EAAc,CAC7D,KAAM,WACP,CAAC,CAEkB,GAAG,EAAc,EAAI"}
|
|
1
|
+
{"version":3,"file":"getLocaleName.mjs","names":[],"sources":["../../../src/localization/getLocaleName.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { CachedIntl } from '../utils/intl';\n\nexport const getLocaleName = (\n displayLocale: LocalesValues,\n targetLocale: LocalesValues = displayLocale\n): string => {\n // new Intl.DisplayNames() is fairly heavy: under the hood every call parses CLDR data and builds a resolver table. In your LocaleSwitcher it’s invoked:\n const displayNames = new CachedIntl.DisplayNames(targetLocale, {\n type: 'language',\n });\n\n return displayNames.of(displayLocale) ?? 'Unknown locale';\n};\n"],"mappings":"+CAGA,MAAa,GACX,EACA,EAA8B,IAGT,IAAI,EAAW,aAAa,EAAc,CAC7D,KAAM,WACP,CAAC,CAEkB,GAAG,EAAc,EAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocalizedUrl.mjs","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type {
|
|
1
|
+
{"version":3,"file":"getLocalizedUrl.mjs","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\nimport { getPrefix } from './getPrefix';\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\n} from './rewriteUtils';\n\n/**\n * Generate URL by prefixing the given URL with the referenced locale or adding search parameters\n * based on the routing mode. Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-no-default' });\n * // Returns '/fr/about' for the French locale\n * // Returns '/about' for the English locale (default)\n *\n * // prefix-all mode\n * getLocalizedUrl('/about', 'en', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-all' });\n * // Returns '/en/about' for the English locale\n * // Returns '/fr/about' for the French locale\n *\n * // search-params mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'search-params' });\n * // Returns '/about?locale=fr' for the French locale\n *\n * // no-prefix mode\n * getLocalizedUrl('/about', 'fr', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'no-prefix' });\n * // Returns '/about' for any locale\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param currentLocale - The current locale.\n * @param options - Configuration options\n * @param options.locales - Optional array of supported locales. Defaults to configured locales.\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns The localized URL for the current locale.\n */\nexport const getLocalizedUrl = (\n url: string,\n currentLocale: LocalesValues = configuration?.internationalization\n ?.defaultLocale,\n options: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n } = {}\n): string => {\n const { defaultLocale, mode, locales, rewrite } = {\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 rewrite: configuration?.routing?.rewrite,\n ...options,\n };\n\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n const urlRewriteRules = getRewriteRules(rewrite, 'url');\n\n if (mode === 'no-prefix') {\n // Resolve to canonical path first from the potentially localized input URL\n const canonicalPathname = getCanonicalPath(\n urlWithoutLocale,\n undefined,\n urlRewriteRules\n );\n\n // Localize the canonical path for the target locale\n return getLocalizedPath(\n canonicalPathname,\n currentLocale as Locale,\n urlRewriteRules\n ).path;\n }\n\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Resolve to canonical path first\n const canonicalPathname = getCanonicalPath(\n parsedUrl.pathname,\n undefined,\n urlRewriteRules\n );\n\n // Localize the canonical path for the target locale\n const translatedPathname = getLocalizedPath(\n canonicalPathname,\n currentLocale as Locale,\n urlRewriteRules\n ).path;\n\n if (mode === 'search-params') {\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', currentLocale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${translatedPathname}?${queryString}`\n : translatedPathname;\n\n return isAbsoluteUrl\n ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}`\n : `${pathWithQuery}${parsedUrl.hash}`;\n }\n\n const { prefix } = getPrefix(currentLocale, {\n defaultLocale,\n mode,\n locales,\n });\n\n let localizedPath = `/${prefix}${translatedPathname}`;\n\n localizedPath = localizedPath.replaceAll(/\\/+/g, '/');\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n const finalUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n\n return finalUrl;\n};\n"],"mappings":"kXAkDA,MAAa,GACX,EACA,EAA+B,GAAe,sBAC1C,cACJ,EAKI,EAAE,GACK,CACX,GAAM,CAAE,gBAAe,OAAM,UAAS,WAAY,CAChD,cACE,GAAe,sBAAsB,eACrC,EAAc,qBAAqB,eACrC,KAAM,GAAe,SAAS,MAAQ,EAAc,QAAQ,aAC5D,QACE,GAAe,sBAAsB,SACrC,EAAc,qBAAqB,QACrC,QAAS,GAAe,SAAS,QACjC,GAAG,EACJ,CAEK,EAAmB,EAAqB,EAAK,EAAQ,CAErD,EAAkB,EAAgB,EAAS,MAAM,CAEvD,GAAI,IAAS,YASX,OAAO,EAPmB,EACxB,EACA,IAAA,GACA,EACD,CAKC,EACA,EACD,CAAC,KAGJ,IAAM,EAAgB,EAAmB,EAAiB,CAEpD,EAAY,EACd,IAAI,IAAI,EAAiB,CACzB,IAAI,IAAI,EAAkB,qBAAqB,CAE7C,EAAU,EACZ,GAAG,EAAU,SAAS,IAAI,EAAU,OACpC,GAUE,EAAqB,EAPD,EACxB,EAAU,SACV,IAAA,GACA,EACD,CAKC,EACA,EACD,CAAC,KAEF,GAAI,IAAS,gBAAiB,CAC5B,IAAM,EAAe,IAAI,gBAAgB,EAAU,OAAO,CAC1D,EAAa,IAAI,SAAU,EAAc,UAAU,CAAC,CAEpD,IAAM,EAAc,EAAa,UAAU,CACrC,EAAgB,EAClB,GAAG,EAAmB,GAAG,IACzB,EAEJ,OAAO,EACH,GAAG,IAAU,IAAgB,EAAU,OACvC,GAAG,IAAgB,EAAU,OAGnC,GAAM,CAAE,UAAW,EAAU,EAAe,CAC1C,gBACA,OACA,UACD,CAAC,CAEE,EAAgB,IAAI,IAAS,IAYjC,MAVA,GAAgB,EAAc,WAAW,OAAQ,IAAI,CAEjD,EAAc,OAAS,GAAK,EAAc,SAAS,IAAI,GACzD,EAAgB,EAAc,MAAM,EAAG,GAAG,EAG3B,EACb,GAAG,IAAU,IAAgB,EAAU,SAAS,EAAU,OAC1D,GAAG,IAAgB,EAAU,SAAS,EAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMultilingualUrls.mjs","names":[],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type {
|
|
1
|
+
{"version":3,"file":"getMultilingualUrls.mjs","names":[],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport { getLocalizedUrl } from './getLocalizedUrl';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale\n * or adding search parameters based on the routing mode.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n *\n * // prefix-all mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'prefix-all' })\n * // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }\n *\n * // search-params mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'search-params' })\n * // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }\n *\n * // no-prefix mode\n * getMultilingualUrls('/dashboard', { locales: ['en', 'fr'], defaultLocale: 'en', mode: 'no-prefix' })\n * // Returns { en: '/dashboard', fr: '/dashboard' }\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param options - Configuration options\n * @param options.locales - Optional array of supported locales. Defaults to configured locales.\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n options: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n } = {}\n): StrictModeLocaleMap<string> => {\n const { defaultLocale, mode, locales, rewrite } = {\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 rewrite: configuration?.routing?.rewrite,\n ...options,\n };\n\n // Generate multilingual URLs by iterating over each locale and calling getLocalizedUrl\n const multilingualUrls = (locales ?? []).reduce<StrictModeLocaleMap<string>>(\n (acc, locale) => {\n // Get the localized URL for this locale\n const localizedUrl = getLocalizedUrl(url, locale, {\n locales,\n defaultLocale,\n mode,\n rewrite,\n });\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as StrictModeLocaleMap<string>\n );\n\n return multilingualUrls;\n};\n"],"mappings":"sJAwCA,MAAa,GACX,EACA,EAKI,EAAE,GAC0B,CAChC,GAAM,CAAE,gBAAe,OAAM,UAAS,WAAY,CAChD,cACE,GAAe,sBAAsB,eACrC,EAAc,qBAAqB,eACrC,KAAM,GAAe,SAAS,MAAQ,EAAc,QAAQ,aAC5D,QACE,GAAe,sBAAsB,SACrC,EAAc,qBAAqB,QACrC,QAAS,GAAe,SAAS,QACjC,GAAG,EACJ,CAqBD,OAlB0B,GAAW,EAAE,EAAE,QACtC,EAAK,KAUJ,EAAI,GARiB,EAAgB,EAAK,EAAQ,CAChD,UACA,gBACA,OACA,UACD,CAAC,CAKK,GAET,EAAE,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPathWithoutLocale.mjs","names":[],"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n * Also removes locale from search parameters if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('/dashboard?locale=fr') // Returns '/dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard?locale=fr') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment or locale search parameter.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl?.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales?.includes(firstSegment as LocalesValues)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n // Remove locale from search parameters if present\n const searchParams = new URLSearchParams(url.search);\n if (searchParams.has('locale')) {\n searchParams.delete('locale');\n url.search = searchParams.toString();\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":"2GA6BA,MAAa,GACX,EACA,EAA2B,GAAe,sBAAsB,UACrD,CAEX,IAAM,EAAgB,EAAmB,EAAS,CAE9C,EAAgB,EAEhB,GAAU,SAAS,IAAI,GACzB,EAAgB,EAAS,MAAM,EAAG,GAAG,EAKvC,IAAM,EAAM,EACR,IAAI,IAAI,EAAc,CACtB,IAAI,IAAI,EAAe,qBAAqB,CAE1C,EAAW,EAAI,SAGhB,EAAS,WAAW,IAAI,GAE3B,EAAI,SAAW,IAAI,KAIrB,IAAM,EAAe,EAAS,MAAM,IAAI,CAClC,EAAe,EAAa,GAG9B,GAAS,SAAS,EAA8B,GAElD,EAAa,OAAO,EAAG,EAAE,CAIzB,EAAI,SADgB,EAAa,KAAK,IAAI,EAAI,KAKhD,IAAM,EAAe,IAAI,gBAAgB,EAAI,OAAO,CAYpD,OAXI,EAAa,IAAI,SAAS,GAC5B,EAAa,OAAO,SAAS,CAC7B,EAAI,OAAS,EAAa,UAAU,EAGlC,EAEK,EAAI,UAAU,CAIhB,EAAI,UAAU,CAAC,QAAQ,qBAAsB,GAAG"}
|
|
1
|
+
{"version":3,"file":"getPathWithoutLocale.mjs","names":[],"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n * Also removes locale from search parameters if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('/dashboard?locale=fr') // Returns '/dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard?locale=fr') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment or locale search parameter.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl?.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales?.includes(firstSegment as LocalesValues)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n // Remove locale from search parameters if present\n const searchParams = new URLSearchParams(url.search);\n if (searchParams.has('locale')) {\n searchParams.delete('locale');\n url.search = searchParams.toString();\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":"2GA6BA,MAAa,GACX,EACA,EAA2B,GAAe,sBAAsB,UACrD,CAEX,IAAM,EAAgB,EAAmB,EAAS,CAE9C,EAAgB,EAEhB,GAAU,SAAS,IAAI,GACzB,EAAgB,EAAS,MAAM,EAAG,GAAG,EAKvC,IAAM,EAAM,EACR,IAAI,IAAI,EAAc,CACtB,IAAI,IAAI,EAAe,qBAAqB,CAE1C,EAAW,EAAI,SAGhB,EAAS,WAAW,IAAI,GAE3B,EAAI,SAAW,IAAI,KAIrB,IAAM,EAAe,EAAS,MAAM,IAAI,CAClC,EAAe,EAAa,GAG9B,GAAS,SAAS,EAA8B,GAElD,EAAa,OAAO,EAAG,EAAE,CAIzB,EAAI,SADgB,EAAa,KAAK,IAAI,EAAI,KAKhD,IAAM,EAAe,IAAI,gBAAgB,EAAI,OAAO,CAYpD,OAXI,EAAa,IAAI,SAAS,GAC5B,EAAa,OAAO,SAAS,CAC7B,EAAI,OAAS,EAAa,UAAU,EAGlC,EAEK,EAAI,UAAU,CAIhB,EAAI,UAAU,CAAC,QAAQ,qBAAsB,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrefix.mjs","names":[],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type {
|
|
1
|
+
{"version":3,"file":"getPrefix.mjs","names":[],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { Locale } from '@intlayer/types/allLocales';\n\nexport type GetPrefixOptions = {\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n};\n\nexport type GetPrefixResult = {\n /**\n * The complete base URL path with leading and trailing slashes.\n *\n * @example\n * // https://example.com/fr/about -> '/fr'\n * // https://example.com/about -> ''\n */\n prefix: string;\n /**\n * The locale identifier without slashes.\n *\n * @example\n * // https://example.com/fr/about -> 'fr'\n * // https://example.com/about -> undefined\n */\n localePrefix: Locale | undefined;\n};\n\n/**\n * Determines the URL prefix for a given locale based on the routing mode configuration.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode with default locale\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // prefix-no-default mode with non-default locale\n * getPrefix('fr', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '/fr', localePrefix: 'fr' }\n *\n * // prefix-all mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-all' })\n * // Returns { prefix: '/en', localePrefix: locale }\n *\n * // search-params mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'search-params' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // no-prefix mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'no-prefix' })\n * // Returns { prefix: '', localePrefix: undefined }\n * ```\n *\n * @param locale - The locale to check for prefix. If not provided, uses configured default locale.\n * @param options - Configuration options\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object containing pathPrefix, prefix, and localePrefix for the given locale.\n */\nexport const getPrefix = (\n locale: LocalesValues | undefined,\n options: {\n defaultLocale?: LocalesValues;\n locales?: LocalesValues[];\n mode?: RoutingConfig['mode'];\n } = {}\n): GetPrefixResult => {\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 (!locale || !locales.includes(locale)) {\n return {\n prefix: '',\n localePrefix: undefined,\n };\n }\n\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n mode === 'prefix-all' ||\n (mode === 'prefix-no-default' && defaultLocale !== locale);\n\n if (shouldPrefix) {\n return {\n prefix: `${locale}/`,\n localePrefix: locale as Locale,\n };\n }\n\n return {\n prefix: '',\n localePrefix: undefined,\n };\n};\n"],"mappings":"8FA+DA,MAAa,GACX,EACA,EAII,EAAE,GACc,CACpB,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,CAqBD,MAnBI,CAAC,GAAU,CAAC,EAAQ,SAAS,EAAO,CAC/B,CACL,OAAQ,GACR,aAAc,IAAA,GACf,CAKD,IAAS,cACR,IAAS,qBAAuB,IAAkB,EAG5C,CACL,OAAQ,GAAG,EAAO,GAClB,aAAc,EACf,CAGI,CACL,OAAQ,GACR,aAAc,IAAA,GACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeDetector.mjs","names":[],"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Constants\n */\nconst LANGUAGE_FORMAT_REGULAR_EXPRESSION =\n /^\\s*([^\\s\\-;]+)(?:-([^\\s;]+))?\\s*(?:;(.*))?$/;\nconst DEFAULT_QUALITY_SCORE = 1;\n\n/**\n * Enumeration for specificity weights.\n * Higher values indicate a more precise match.\n */\nenum SpecificityWeight {\n None = 0,\n Broad = 1, // Matches prefix (e.g., 'en' matches 'en-US')\n Prefix = 2, // Matches prefix in reverse (e.g., 'en-US' matches 'en')\n Exact = 4, // Matches exact string (e.g., 'en-US' matches 'en-US')\n}\n\n/**\n * Represents a parsed language tag from the header.\n */\ntype LanguagePreference = {\n languageCode: string;\n regionCode?: string;\n fullLocale: string;\n qualityScore: number;\n originalIndex: number;\n};\n\n/**\n * Represents the result of matching a requested language against an available language.\n */\ntype MatchResult = {\n providedIndex: number;\n headerIndex: number;\n qualityScore: number;\n specificityScore: number;\n};\n\n/**\n * Parses a single language tag string from the Accept-Language header.\n * Example input: \"en-US;q=0.8\"\n */\nconst parseLanguageTag = (\n tagString: string,\n index: number\n): LanguagePreference | null => {\n const match = LANGUAGE_FORMAT_REGULAR_EXPRESSION.exec(tagString);\n if (!match) {\n return null;\n }\n\n const languageCode = match[1];\n const regionCode = match[2];\n const parameters = match[3];\n\n // Construct the full locale string (e.g., \"en-US\" or \"en\")\n const fullLocale = regionCode\n ? `${languageCode}-${regionCode}`\n : languageCode;\n\n let qualityScore = DEFAULT_QUALITY_SCORE;\n\n // Parse parameters to find the quality score (\"q\")\n if (parameters) {\n const parameterList = parameters.split(';');\n for (const parameter of parameterList) {\n const [key, value] = parameter.split('=');\n if (key === 'q') {\n qualityScore = parseFloat(value);\n }\n }\n }\n\n return {\n languageCode,\n regionCode,\n qualityScore,\n originalIndex: index,\n fullLocale,\n };\n};\n\n/**\n * Parses the entire Accept-Language header string into a list of preferences.\n */\nconst parseAcceptLanguageHeader = (\n headerValue: string\n): LanguagePreference[] => {\n const rawTags = headerValue.split(',');\n const preferences: LanguagePreference[] = [];\n\n for (let index = 0; index < rawTags.length; index++) {\n const tag = rawTags[index].trim();\n const parsedLanguage = parseLanguageTag(tag, index);\n\n if (parsedLanguage) {\n preferences.push(parsedLanguage);\n }\n }\n\n return preferences;\n};\n\n/**\n * Calculates the specificity of a match between a provided language and a requested preference.\n */\nconst calculateMatchSpecificity = (\n providedLanguage: string,\n preference: LanguagePreference,\n providedIndex: number\n): MatchResult | null => {\n const parsedProvided = parseLanguageTag(providedLanguage, providedIndex);\n if (!parsedProvided) {\n return null;\n }\n\n let specificityScore = SpecificityWeight.None;\n\n const preferenceFullLower = preference.fullLocale.toLowerCase();\n const preferencePrefixLower = preference.languageCode.toLowerCase();\n const providedFullLower = parsedProvided.fullLocale.toLowerCase();\n const providedPrefixLower = parsedProvided.languageCode.toLowerCase();\n\n if (preferenceFullLower === providedFullLower) {\n specificityScore |= SpecificityWeight.Exact;\n } else if (preferencePrefixLower === providedFullLower) {\n specificityScore |= SpecificityWeight.Prefix;\n } else if (preferenceFullLower === providedPrefixLower) {\n specificityScore |= SpecificityWeight.Broad;\n } else if (preference.fullLocale !== '*') {\n return null;\n }\n\n return {\n providedIndex,\n headerIndex: preference.originalIndex,\n qualityScore: preference.qualityScore,\n specificityScore,\n };\n};\n\n/**\n * Determines the best match for a specific available language against the list of user accepted languages.\n */\nconst getBestMatchForLanguage = (\n providedLanguage: string,\n acceptedPreferences: LanguagePreference[],\n providedIndex: number\n): MatchResult => {\n // Initialize with a non-match priority\n let bestMatch: MatchResult = {\n headerIndex: -1,\n qualityScore: 0,\n specificityScore: 0,\n providedIndex,\n };\n\n for (const preference of acceptedPreferences) {\n const matchSpec = calculateMatchSpecificity(\n providedLanguage,\n preference,\n providedIndex\n );\n\n if (matchSpec) {\n // Compare current best match with new match\n const scoreDifference =\n bestMatch.specificityScore - matchSpec.specificityScore ||\n bestMatch.qualityScore - matchSpec.qualityScore ||\n bestMatch.headerIndex - matchSpec.headerIndex;\n\n // If the new match is better (difference < 0), update priority\n if (scoreDifference < 0) {\n bestMatch = matchSpec;\n }\n }\n }\n\n return bestMatch;\n};\n\n/**\n * Comparator function to sort language matches.\n * Sorting order:\n * 1. Quality Score (Descending)\n * 2. Specificity Score (Descending)\n * 3. Order in Header (Ascending - lower index is better)\n * 4. Order in Provided List (Ascending)\n */\nconst compareMatchResults = (a: MatchResult, b: MatchResult): number => {\n return (\n b.qualityScore - a.qualityScore ||\n b.specificityScore - a.specificityScore ||\n a.headerIndex - b.headerIndex ||\n a.providedIndex - b.providedIndex ||\n 0\n );\n};\n\n/**\n * Derives the list of preferred languages based on the Accept-Language header\n * and an optional list of available languages.\n */\nexport const getPreferredLanguages = (\n acceptHeader: string | undefined,\n availableLanguages?: string[]\n): string[] => {\n // RFC 2616 sec 14.4: no header implies '*'\n const headerValue = acceptHeader === undefined ? '*' : acceptHeader || '';\n const acceptedPreferences = parseAcceptLanguageHeader(headerValue);\n\n // If no specific languages are provided to filter against, return the header languages sorted by quality\n if (!availableLanguages) {\n return acceptedPreferences\n .filter((preference) => preference.qualityScore > 0)\n .sort((a, b) => b.qualityScore - a.qualityScore) // Simple sort by quality\n .map((preference) => preference.fullLocale);\n }\n\n // Map available languages to their match priority against the header\n const matchResults = availableLanguages.map((language, index) =>\n getBestMatchForLanguage(language, acceptedPreferences, index)\n );\n\n return matchResults\n .filter((result) => result.qualityScore > 0)\n .sort(compareMatchResults)\n .map((result) => availableLanguages[result.providedIndex]);\n};\n\n/**\n * Detects the locale from the request headers.\n *\n * Headers are provided by the browser/client and can be used to determine the user's preferred language.\n * This function intersects the user's `Accept-Language` header with the application's available locales.\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n availableLocales?: Locale[],\n defaultLocale?: Locale\n): Locale => {\n const acceptLanguageHeader = headers['accept-language'];\n\n const preferredLocaleStrings = getPreferredLanguages(\n acceptLanguageHeader,\n availableLocales as string[]\n );\n\n return localeResolver(\n preferredLocaleStrings as Locale[],\n availableLocales,\n defaultLocale\n );\n};\n"],"mappings":"sDAMA,MAAM,EACJ,+CAOF,IAAK,EAAL,SAAA,EAAA,OACE,GAAA,EAAA,KAAA,GAAA,OACA,EAAA,EAAA,MAAA,GAAA,QACA,EAAA,EAAA,OAAA,GAAA,SACA,EAAA,EAAA,MAAA,GAAA,WAJG,GAAA,EAAA,CAKJ,CA2BD,MAAM,GACJ,EACA,IAC8B,CAC9B,IAAM,EAAQ,EAAmC,KAAK,EAAU,CAChE,GAAI,CAAC,EACH,OAAO,KAGT,IAAM,EAAe,EAAM,GACrB,EAAa,EAAM,GACnB,EAAa,EAAM,GAGnB,EAAa,EACf,GAAG,EAAa,GAAG,IACnB,EAEA,EAAe,EAGnB,GAAI,EAAY,CACd,IAAM,EAAgB,EAAW,MAAM,IAAI,CAC3C,IAAK,IAAM,KAAa,EAAe,CACrC,GAAM,CAAC,EAAK,GAAS,EAAU,MAAM,IAAI,CACrC,IAAQ,MACV,EAAe,WAAW,EAAM,GAKtC,MAAO,CACL,eACA,aACA,eACA,cAAe,EACf,aACD,EAMG,EACJ,GACyB,CACzB,IAAM,EAAU,EAAY,MAAM,IAAI,CAChC,EAAoC,EAAE,CAE5C,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAQ,OAAQ,IAAS,CAEnD,IAAM,EAAiB,EADX,EAAQ,GAAO,MAAM,CACY,EAAM,CAE/C,GACF,EAAY,KAAK,EAAe,CAIpC,OAAO,GAMH,GACJ,EACA,EACA,IACuB,CACvB,IAAM,EAAiB,EAAiB,EAAkB,EAAc,CACxE,GAAI,CAAC,EACH,OAAO,KAGT,IAAI,EAAmB,EAAkB,KAEnC,EAAsB,EAAW,WAAW,aAAa,CACzD,EAAwB,EAAW,aAAa,aAAa,CAC7D,EAAoB,EAAe,WAAW,aAAa,CAC3D,EAAsB,EAAe,aAAa,aAAa,CAErE,GAAI,IAAwB,EAC1B,GAAoB,EAAkB,cAC7B,IAA0B,EACnC,GAAoB,EAAkB,eAC7B,IAAwB,EACjC,GAAoB,EAAkB,cAC7B,EAAW,aAAe,IACnC,OAAO,KAGT,MAAO,CACL,gBACA,YAAa,EAAW,cACxB,aAAc,EAAW,aACzB,mBACD,EAMG,GACJ,EACA,EACA,IACgB,CAEhB,IAAI,EAAyB,CAC3B,YAAa,GACb,aAAc,EACd,iBAAkB,EAClB,gBACD,CAED,IAAK,IAAM,KAAc,EAAqB,CAC5C,IAAM,EAAY,EAChB,EACA,EACA,EACD,CAEG,IAGA,EAAU,iBAAmB,EAAU,kBACvC,EAAU,aAAe,EAAU,cACnC,EAAU,YAAc,EAAU,aAGd,IACpB,EAAY,GAKlB,OAAO,GAWH,GAAuB,EAAgB,IAEzC,EAAE,aAAe,EAAE,cACnB,EAAE,iBAAmB,EAAE,kBACvB,EAAE,YAAc,EAAE,aAClB,EAAE,cAAgB,EAAE,eACpB,EAQS,GACX,EACA,IACa,CAGb,IAAM,EAAsB,EADR,IAAiB,IAAA,GAAY,IAAM,GAAgB,GACL,CAelE,OAZK,EAQgB,EAAmB,KAAK,EAAU,IACrD,EAAwB,EAAU,EAAqB,EAAM,CAC9D,CAGE,OAAQ,GAAW,EAAO,aAAe,EAAE,CAC3C,KAAK,EAAoB,CACzB,IAAK,GAAW,EAAmB,EAAO,eAAe,CAdnD,EACJ,OAAQ,GAAe,EAAW,aAAe,EAAE,CACnD,MAAM,EAAG,IAAM,EAAE,aAAe,EAAE,aAAa,CAC/C,IAAK,GAAe,EAAW,WAAW,EAoBpC,GACX,EACA,EACA,IACW,CACX,IAAM,EAAuB,EAAQ,mBAOrC,OAAO,EALwB,EAC7B,EACA,EACD,CAIC,EACA,EACD"}
|
|
1
|
+
{"version":3,"file":"localeDetector.mjs","names":[],"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Constants\n */\nconst LANGUAGE_FORMAT_REGULAR_EXPRESSION =\n /^\\s*([^\\s\\-;]+)(?:-([^\\s;]+))?\\s*(?:;(.*))?$/;\nconst DEFAULT_QUALITY_SCORE = 1;\n\n/**\n * Enumeration for specificity weights.\n * Higher values indicate a more precise match.\n */\nenum SpecificityWeight {\n None = 0,\n Broad = 1, // Matches prefix (e.g., 'en' matches 'en-US')\n Prefix = 2, // Matches prefix in reverse (e.g., 'en-US' matches 'en')\n Exact = 4, // Matches exact string (e.g., 'en-US' matches 'en-US')\n}\n\n/**\n * Represents a parsed language tag from the header.\n */\ntype LanguagePreference = {\n languageCode: string;\n regionCode?: string;\n fullLocale: string;\n qualityScore: number;\n originalIndex: number;\n};\n\n/**\n * Represents the result of matching a requested language against an available language.\n */\ntype MatchResult = {\n providedIndex: number;\n headerIndex: number;\n qualityScore: number;\n specificityScore: number;\n};\n\n/**\n * Parses a single language tag string from the Accept-Language header.\n * Example input: \"en-US;q=0.8\"\n */\nconst parseLanguageTag = (\n tagString: string,\n index: number\n): LanguagePreference | null => {\n const match = LANGUAGE_FORMAT_REGULAR_EXPRESSION.exec(tagString);\n if (!match) {\n return null;\n }\n\n const languageCode = match[1];\n const regionCode = match[2];\n const parameters = match[3];\n\n // Construct the full locale string (e.g., \"en-US\" or \"en\")\n const fullLocale = regionCode\n ? `${languageCode}-${regionCode}`\n : languageCode;\n\n let qualityScore = DEFAULT_QUALITY_SCORE;\n\n // Parse parameters to find the quality score (\"q\")\n if (parameters) {\n const parameterList = parameters.split(';');\n for (const parameter of parameterList) {\n const [key, value] = parameter.split('=');\n if (key === 'q') {\n qualityScore = parseFloat(value);\n }\n }\n }\n\n return {\n languageCode,\n regionCode,\n qualityScore,\n originalIndex: index,\n fullLocale,\n };\n};\n\n/**\n * Parses the entire Accept-Language header string into a list of preferences.\n */\nconst parseAcceptLanguageHeader = (\n headerValue: string\n): LanguagePreference[] => {\n const rawTags = headerValue.split(',');\n const preferences: LanguagePreference[] = [];\n\n for (let index = 0; index < rawTags.length; index++) {\n const tag = rawTags[index].trim();\n const parsedLanguage = parseLanguageTag(tag, index);\n\n if (parsedLanguage) {\n preferences.push(parsedLanguage);\n }\n }\n\n return preferences;\n};\n\n/**\n * Calculates the specificity of a match between a provided language and a requested preference.\n */\nconst calculateMatchSpecificity = (\n providedLanguage: string,\n preference: LanguagePreference,\n providedIndex: number\n): MatchResult | null => {\n const parsedProvided = parseLanguageTag(providedLanguage, providedIndex);\n if (!parsedProvided) {\n return null;\n }\n\n let specificityScore = SpecificityWeight.None;\n\n const preferenceFullLower = preference.fullLocale.toLowerCase();\n const preferencePrefixLower = preference.languageCode.toLowerCase();\n const providedFullLower = parsedProvided.fullLocale.toLowerCase();\n const providedPrefixLower = parsedProvided.languageCode.toLowerCase();\n\n if (preferenceFullLower === providedFullLower) {\n specificityScore |= SpecificityWeight.Exact;\n } else if (preferencePrefixLower === providedFullLower) {\n specificityScore |= SpecificityWeight.Prefix;\n } else if (preferenceFullLower === providedPrefixLower) {\n specificityScore |= SpecificityWeight.Broad;\n } else if (preference.fullLocale !== '*') {\n return null;\n }\n\n return {\n providedIndex,\n headerIndex: preference.originalIndex,\n qualityScore: preference.qualityScore,\n specificityScore,\n };\n};\n\n/**\n * Determines the best match for a specific available language against the list of user accepted languages.\n */\nconst getBestMatchForLanguage = (\n providedLanguage: string,\n acceptedPreferences: LanguagePreference[],\n providedIndex: number\n): MatchResult => {\n // Initialize with a non-match priority\n let bestMatch: MatchResult = {\n headerIndex: -1,\n qualityScore: 0,\n specificityScore: 0,\n providedIndex,\n };\n\n for (const preference of acceptedPreferences) {\n const matchSpec = calculateMatchSpecificity(\n providedLanguage,\n preference,\n providedIndex\n );\n\n if (matchSpec) {\n // Compare current best match with new match\n const scoreDifference =\n bestMatch.specificityScore - matchSpec.specificityScore ||\n bestMatch.qualityScore - matchSpec.qualityScore ||\n bestMatch.headerIndex - matchSpec.headerIndex;\n\n // If the new match is better (difference < 0), update priority\n if (scoreDifference < 0) {\n bestMatch = matchSpec;\n }\n }\n }\n\n return bestMatch;\n};\n\n/**\n * Comparator function to sort language matches.\n * Sorting order:\n * 1. Quality Score (Descending)\n * 2. Specificity Score (Descending)\n * 3. Order in Header (Ascending - lower index is better)\n * 4. Order in Provided List (Ascending)\n */\nconst compareMatchResults = (a: MatchResult, b: MatchResult): number => {\n return (\n b.qualityScore - a.qualityScore ||\n b.specificityScore - a.specificityScore ||\n a.headerIndex - b.headerIndex ||\n a.providedIndex - b.providedIndex ||\n 0\n );\n};\n\n/**\n * Derives the list of preferred languages based on the Accept-Language header\n * and an optional list of available languages.\n */\nexport const getPreferredLanguages = (\n acceptHeader: string | undefined,\n availableLanguages?: string[]\n): string[] => {\n // RFC 2616 sec 14.4: no header implies '*'\n const headerValue = acceptHeader === undefined ? '*' : acceptHeader || '';\n const acceptedPreferences = parseAcceptLanguageHeader(headerValue);\n\n // If no specific languages are provided to filter against, return the header languages sorted by quality\n if (!availableLanguages) {\n return acceptedPreferences\n .filter((preference) => preference.qualityScore > 0)\n .sort((a, b) => b.qualityScore - a.qualityScore) // Simple sort by quality\n .map((preference) => preference.fullLocale);\n }\n\n // Map available languages to their match priority against the header\n const matchResults = availableLanguages.map((language, index) =>\n getBestMatchForLanguage(language, acceptedPreferences, index)\n );\n\n return matchResults\n .filter((result) => result.qualityScore > 0)\n .sort(compareMatchResults)\n .map((result) => availableLanguages[result.providedIndex]);\n};\n\n/**\n * Detects the locale from the request headers.\n *\n * Headers are provided by the browser/client and can be used to determine the user's preferred language.\n * This function intersects the user's `Accept-Language` header with the application's available locales.\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n availableLocales?: Locale[],\n defaultLocale?: Locale\n): Locale => {\n const acceptLanguageHeader = headers['accept-language'];\n\n const preferredLocaleStrings = getPreferredLanguages(\n acceptLanguageHeader,\n availableLocales as string[]\n );\n\n return localeResolver(\n preferredLocaleStrings as Locale[],\n availableLocales,\n defaultLocale\n );\n};\n"],"mappings":"sDAMA,MAAM,EACJ,+CAOF,IAAK,EAAL,SAAA,EAAA,OACE,GAAA,EAAA,KAAA,GAAA,OACA,EAAA,EAAA,MAAA,GAAA,QACA,EAAA,EAAA,OAAA,GAAA,SACA,EAAA,EAAA,MAAA,GAAA,WAJG,GAAA,EAAA,CAKJ,CA2BD,MAAM,GACJ,EACA,IAC8B,CAC9B,IAAM,EAAQ,EAAmC,KAAK,EAAU,CAChE,GAAI,CAAC,EACH,OAAO,KAGT,IAAM,EAAe,EAAM,GACrB,EAAa,EAAM,GACnB,EAAa,EAAM,GAGnB,EAAa,EACf,GAAG,EAAa,GAAG,IACnB,EAEA,EAAe,EAGnB,GAAI,EAAY,CACd,IAAM,EAAgB,EAAW,MAAM,IAAI,CAC3C,IAAK,IAAM,KAAa,EAAe,CACrC,GAAM,CAAC,EAAK,GAAS,EAAU,MAAM,IAAI,CACrC,IAAQ,MACV,EAAe,WAAW,EAAM,GAKtC,MAAO,CACL,eACA,aACA,eACA,cAAe,EACf,aACD,EAMG,EACJ,GACyB,CACzB,IAAM,EAAU,EAAY,MAAM,IAAI,CAChC,EAAoC,EAAE,CAE5C,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAQ,OAAQ,IAAS,CAEnD,IAAM,EAAiB,EADX,EAAQ,GAAO,MAAM,CACY,EAAM,CAE/C,GACF,EAAY,KAAK,EAAe,CAIpC,OAAO,GAMH,GACJ,EACA,EACA,IACuB,CACvB,IAAM,EAAiB,EAAiB,EAAkB,EAAc,CACxE,GAAI,CAAC,EACH,OAAO,KAGT,IAAI,EAAmB,EAAkB,KAEnC,EAAsB,EAAW,WAAW,aAAa,CACzD,EAAwB,EAAW,aAAa,aAAa,CAC7D,EAAoB,EAAe,WAAW,aAAa,CAC3D,EAAsB,EAAe,aAAa,aAAa,CAErE,GAAI,IAAwB,EAC1B,GAAoB,EAAkB,cAC7B,IAA0B,EACnC,GAAoB,EAAkB,eAC7B,IAAwB,EACjC,GAAoB,EAAkB,cAC7B,EAAW,aAAe,IACnC,OAAO,KAGT,MAAO,CACL,gBACA,YAAa,EAAW,cACxB,aAAc,EAAW,aACzB,mBACD,EAMG,GACJ,EACA,EACA,IACgB,CAEhB,IAAI,EAAyB,CAC3B,YAAa,GACb,aAAc,EACd,iBAAkB,EAClB,gBACD,CAED,IAAK,IAAM,KAAc,EAAqB,CAC5C,IAAM,EAAY,EAChB,EACA,EACA,EACD,CAEG,IAGA,EAAU,iBAAmB,EAAU,kBACvC,EAAU,aAAe,EAAU,cACnC,EAAU,YAAc,EAAU,aAGd,IACpB,EAAY,GAKlB,OAAO,GAWH,GAAuB,EAAgB,IAEzC,EAAE,aAAe,EAAE,cACnB,EAAE,iBAAmB,EAAE,kBACvB,EAAE,YAAc,EAAE,aAClB,EAAE,cAAgB,EAAE,eACpB,EAQS,GACX,EACA,IACa,CAGb,IAAM,EAAsB,EADR,IAAiB,IAAA,GAAY,IAAM,GAAgB,GACL,CAelE,OAZK,EAQgB,EAAmB,KAAK,EAAU,IACrD,EAAwB,EAAU,EAAqB,EAAM,CAC9D,CAGE,OAAQ,GAAW,EAAO,aAAe,EAAE,CAC3C,KAAK,EAAoB,CACzB,IAAK,GAAW,EAAmB,EAAO,eAAe,CAdnD,EACJ,OAAQ,GAAe,EAAW,aAAe,EAAE,CACnD,MAAM,EAAG,IAAM,EAAE,aAAe,EAAE,aAAa,CAC/C,IAAK,GAAe,EAAW,WAAW,EAoBpC,GACX,EACA,EACA,IACW,CACX,IAAM,EAAuB,EAAQ,mBAOrC,OAAO,EALwB,EAC7B,EACA,EACD,CAIC,EACA,EACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{DefaultValues as e}from"@intlayer/config/client";import t from"@intlayer/config/built";const n=(e,t,n)=>n===`no-prefix`||n===`search-params`?!1:n===`prefix-all`?!0:e!==t,r=(r,i=t?.internationalization.locales??[],a=t?.internationalization.defaultLocale??e.Internationalization.DEFAULT_LOCALE,o=t?.routing?.mode??`prefix-no-default`)=>(i??[]).map(e=>r({locale:e,defaultLocale:a,locales:i,isDefault:e===a,urlPrefix:n(e,a,o)?`/${e}`:``})),i=(r,i=t?.internationalization.locales??[],a=t?.internationalization.defaultLocale??e.Internationalization.DEFAULT_LOCALE,o=t?.routing?.mode??`prefix-no-default`)=>i.flatMap(e=>r({locale:e,defaultLocale:a,locales:i,isDefault:e===a,urlPrefix:n(e,a,o)?`/${e}`:``})),a=(r,i=t?.internationalization.locales??[],a=t?.internationalization.defaultLocale??e.Internationalization.DEFAULT_LOCALE,o=t?.routing?.mode??`prefix-no-default`)=>(i??[]).reduce((e,t)=>(e[t]=r({locale:t,defaultLocale:a,locales:i,isDefault:t===a,urlPrefix:n(t,a,o)?`/${t}`:``}),e),{});export{i as localeFlatMap,r as localeMap,a as localeRecord};
|
|
2
2
|
//# sourceMappingURL=localeMapper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeMapper.mjs","names":[],"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {
|
|
1
|
+
{"version":3,"file":"localeMapper.mjs","names":[],"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { Locale } from '@intlayer/types/allLocales';\n\nexport type LocaleData = {\n locale: Locale;\n defaultLocale: Locale;\n isDefault: boolean;\n locales: Locale[];\n urlPrefix: string;\n};\n\n/**\n * Determine if the locale should be prefixed in the URL based on routing mode\n */\nconst shouldPrefixLocale = (\n locale: LocalesValues,\n defaultLocale: LocalesValues,\n mode: 'prefix-no-default' | 'prefix-all' | 'no-prefix' | 'search-params'\n): boolean => {\n if (mode === 'no-prefix' || mode === 'search-params') {\n return false;\n }\n if (mode === 'prefix-all') {\n return true;\n }\n // 'prefix-no-default'\n return locale !== defaultLocale;\n};\n\n/**\n * Map the locale data to an array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * ({\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }),\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an object\n * @returns An array of objects\n */\nexport const localeMap = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n (locales ?? []).map((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' ,\n * path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' ,\n * path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' ,\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(\n mapper: (locale: LocaleData) => T[],\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n locales.flatMap((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Creates a record object mapping locales to values transformed by the mapper function\n *\n * @example\n * ```ts\n * const translations = localeRecord(({ locale }) =>\n * require(`./translations/${locale}.json`)\n * );\n *\n * // Result\n *\n * en: ... , // Content of translations/en.json\n * fr: ... , // Content of translations/fr.json\n * es: ...\n *\n * ```\n *\n * @param mapper - Function that takes locale data and returns a value for that locale\n * @param locales - Array of locale codes to map over (defaults to configured locales)\n * @param defaultLocale - The default locale (defaults to configured default)\n * @param mode - URL routing mode for locale handling (defaults to configured value)\n * @returns Record mapping locale codes to mapped values\n */\nexport const localeRecord = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): Record<LocalesValues, T> =>\n (locales ?? []).reduce(\n (acc, locale) => {\n acc[locale] = mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData);\n return acc;\n },\n {} as Record<LocalesValues, T>\n );\n"],"mappings":"8FAgBA,MAAM,GACJ,EACA,EACA,IAEI,IAAS,aAAe,IAAS,gBAC5B,GAEL,IAAS,aACJ,GAGF,IAAW,EA6BP,GACX,EACA,EAA2B,GAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+B,GAAe,qBAC3C,eAAiB,EAAc,qBAAqB,eACvD,EAIsB,GAAe,SAAS,MAAQ,uBAErD,GAAW,EAAE,EAAE,IAAK,GACnB,EAAO,CACL,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACjB,CA4BU,GACX,EACA,EAA2B,GAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+B,GAAe,qBAC3C,eAAiB,EAAc,qBAAqB,eACvD,EAIsB,GAAe,SAAS,MAAQ,sBAEtD,EAAQ,QAAS,GACf,EAAO,CACL,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACjB,CAyBU,GACX,EACA,EAA2B,GAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+B,GAAe,qBAC3C,eAAiB,EAAc,qBAAqB,eACvD,EAIsB,GAAe,SAAS,MAAQ,uBAErD,GAAW,EAAE,EAAE,QACb,EAAK,KACJ,EAAI,GAAU,EAAO,CACnB,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACT,GAET,EAAE,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeResolver.mjs","names":[],"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {
|
|
1
|
+
{"version":3,"file":"localeResolver.mjs","names":[],"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { Locale } from '@intlayer/types/allLocales';\n\n/**\n * Resolves the most specific locale from a user-provided list,\n * or falls back to the default locale if no match is found.\n */\nexport const localeResolver = (\n selectedLocale: LocalesValues | LocalesValues[],\n locales: LocalesValues[] = configuration?.internationalization?.locales,\n defaultLocale: LocalesValues = configuration?.internationalization\n ?.defaultLocale\n): Locale => {\n // Ensure we can handle both a single locale or an array of locales uniformly\n const requestedLocales = [selectedLocale].flat();\n\n // Simple helper to normalize locale strings (e.g. \"en-US\" => \"en-us\")\n const normalize = (locale: string): string => locale.trim().toLowerCase();\n\n try {\n // Check each requested locale in order\n for (const requested of requestedLocales) {\n const normalizedRequested = normalize(requested);\n\n // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch as Locale;\n }\n\n // 2) Attempt partial match on language subtag\n // e.g. if requested is \"en-US\" and not found,\n // see if \"en\" is available among locales\n const [requestedLang] = normalizedRequested.split('-');\n const partialMatch = locales.find(\n (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch as Locale;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale as Locale;\n};\n"],"mappings":"sCAQA,MAAa,GACX,EACA,EAA2B,GAAe,sBAAsB,QAChE,EAA+B,GAAe,sBAC1C,gBACO,CAEX,IAAM,EAAmB,CAAC,EAAe,CAAC,MAAM,CAG1C,EAAa,GAA2B,EAAO,MAAM,CAAC,aAAa,CAEzE,GAAI,CAEF,IAAK,IAAM,KAAa,EAAkB,CACxC,IAAM,EAAsB,EAAU,EAAU,CAG1C,EAAa,EAAQ,KACxB,GAAQ,EAAU,EAAI,GAAK,EAC7B,CACD,GAAI,EACF,OAAO,EAMT,GAAM,CAAC,GAAiB,EAAoB,MAAM,IAAI,CAChD,EAAe,EAAQ,KAC1B,GAAQ,EAAU,EAAI,CAAC,MAAM,IAAI,CAAC,KAAO,EAC3C,CACD,GAAI,EACF,OAAO,QAGI,EAKjB,OAAO"}
|