@intlayer/core 8.1.2 → 8.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +1 -212
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +1 -94
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs +1 -45
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs +1 -33
- package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMaskContent.cjs +1 -27
- package/dist/cjs/deepTransformPlugins/getMaskContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +1 -82
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs +1 -87
- package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs +1 -60
- package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs +1 -122
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/index.cjs +1 -32
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs +1 -106
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +1 -64
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -18
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +1 -55
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +1 -26
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -23
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs +1 -36
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/index.cjs +1 -27
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs +1 -69
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs +1 -30
- package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs +1 -48
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +1 -31
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +1 -39
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +1 -38
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
- package/dist/cjs/formatters/compact.cjs +1 -25
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs +1 -29
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs +1 -60
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/index.cjs +1 -18
- package/dist/cjs/formatters/list.cjs +1 -30
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs +1 -18
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs +1 -25
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs +1 -33
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs +1 -23
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/getStorageAttributes.cjs +1 -134
- package/dist/cjs/getStorageAttributes.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -300
- package/dist/cjs/interpreter/getCondition.cjs +1 -27
- package/dist/cjs/interpreter/getCondition.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs +1 -41
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs +1 -34
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/index.cjs +1 -14
- package/dist/cjs/interpreter/getContent/plugins.cjs +1 -161
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionary.cjs +1 -24
- package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getEnumeration.cjs +1 -72
- package/dist/cjs/interpreter/getEnumeration.cjs.map +1 -1
- package/dist/cjs/interpreter/getGender.cjs +1 -38
- package/dist/cjs/interpreter/getGender.cjs.map +1 -1
- package/dist/cjs/interpreter/getHTML.cjs +1 -121
- package/dist/cjs/interpreter/getHTML.cjs.map +1 -1
- package/dist/cjs/interpreter/getInsertion.cjs +1 -22
- package/dist/cjs/interpreter/getInsertion.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs +1 -40
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getNesting.cjs +1 -36
- package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs +1 -112
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/interpreter/index.cjs +1 -31
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs +1 -55
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs +1 -143
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getHTMLTextDir.cjs +1 -64
- package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs +1 -27
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs +1 -45
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleLang.cjs +1 -20
- package/dist/cjs/localization/getLocaleLang.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleName.cjs +1 -10
- package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +1 -82
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs +1 -63
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs +1 -55
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs +1 -63
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/localization/index.cjs +1 -39
- package/dist/cjs/localization/localeDetector.cjs +1 -133
- package/dist/cjs/localization/localeDetector.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs +1 -119
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/localization/localeResolver.cjs +1 -28
- package/dist/cjs/localization/localeResolver.cjs.map +1 -1
- package/dist/cjs/localization/rewriteUtils.cjs +1 -110
- package/dist/cjs/localization/rewriteUtils.cjs.map +1 -1
- package/dist/cjs/localization/validatePrefix.cjs +1 -54
- package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +10 -810
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/constants.cjs +1 -328
- package/dist/cjs/markdown/constants.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +1 -120
- package/dist/cjs/markdown/parser.cjs +1 -66
- package/dist/cjs/markdown/parser.cjs.map +1 -1
- package/dist/cjs/markdown/renderer.cjs +1 -61
- package/dist/cjs/markdown/renderer.cjs.map +1 -1
- package/dist/cjs/markdown/utils.cjs +6 -391
- package/dist/cjs/markdown/utils.cjs.map +1 -1
- package/dist/cjs/messageFormat/ICU.cjs +1 -319
- package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
- package/dist/cjs/messageFormat/i18next.cjs +1 -330
- package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
- package/dist/cjs/messageFormat/index.cjs +1 -11
- package/dist/cjs/messageFormat/verify-icu-format.cjs +2 -64
- package/dist/cjs/messageFormat/verify-icu-format.cjs.map +1 -1
- package/dist/cjs/messageFormat/vue-i18n.cjs +1 -166
- package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/condition.cjs +1 -26
- package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/index.cjs +1 -4
- package/dist/cjs/transpiler/enumeration/enumeration.cjs +1 -28
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/index.cjs +1 -4
- package/dist/cjs/transpiler/file/file.cjs +1 -52
- package/dist/cjs/transpiler/file/file.cjs.map +1 -1
- package/dist/cjs/transpiler/file/fileBrowser.cjs +1 -25
- package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
- package/dist/cjs/transpiler/file/index.cjs +1 -5
- package/dist/cjs/transpiler/gender/gender.cjs +1 -26
- package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
- package/dist/cjs/transpiler/gender/index.cjs +1 -4
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs +1 -44
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
- package/dist/cjs/transpiler/html/html.cjs +1 -37
- package/dist/cjs/transpiler/html/html.cjs.map +1 -1
- package/dist/cjs/transpiler/html/htmlTags.cjs +1 -116
- package/dist/cjs/transpiler/html/htmlTags.cjs.map +1 -1
- package/dist/cjs/transpiler/html/index.cjs +1 -6
- package/dist/cjs/transpiler/index.cjs +1 -24
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs +1 -11
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/index.cjs +1 -6
- package/dist/cjs/transpiler/insertion/insertion.cjs +1 -36
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs +2 -23
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/index.cjs +1 -6
- package/dist/cjs/transpiler/markdown/markdown.cjs +1 -54
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/nesting/index.cjs +1 -4
- package/dist/cjs/transpiler/nesting/nesting.cjs +1 -27
- package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/index.cjs +1 -4
- package/dist/cjs/transpiler/translation/translation.cjs +1 -29
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/utils/checkIsURLAbsolute.cjs +1 -7
- package/dist/cjs/utils/checkIsURLAbsolute.cjs.map +1 -1
- package/dist/cjs/utils/getCookie.cjs +1 -32
- package/dist/cjs/utils/getCookie.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +1 -0
- package/dist/cjs/utils/intl.cjs +1 -91
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/isSameKeyPath.cjs +1 -7
- package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -1
- package/dist/cjs/utils/isValidReactElement.cjs +1 -14
- package/dist/cjs/utils/isValidReactElement.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs +1 -140
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/cjs/utils/parseYaml.cjs +16 -322
- package/dist/cjs/utils/parseYaml.cjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs +1 -207
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs +1 -89
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs +1 -42
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs +1 -31
- package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMaskContent.mjs +1 -25
- package/dist/esm/deepTransformPlugins/getMaskContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs +1 -77
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs +1 -86
- package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs +1 -59
- package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getSplittedContent.mjs +1 -119
- package/dist/esm/deepTransformPlugins/getSplittedContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/index.mjs +1 -12
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs +1 -104
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +1 -62
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -16
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +1 -53
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +1 -24
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -21
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeType.mjs +1 -34
- package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/index.mjs +1 -14
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs +1 -66
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs +1 -28
- package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs +1 -45
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +1 -29
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +1 -37
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +1 -36
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
- package/dist/esm/formatters/compact.mjs +1 -22
- package/dist/esm/formatters/compact.mjs.map +1 -1
- package/dist/esm/formatters/currency.mjs +1 -26
- package/dist/esm/formatters/currency.mjs.map +1 -1
- package/dist/esm/formatters/date.mjs +1 -57
- package/dist/esm/formatters/date.mjs.map +1 -1
- package/dist/esm/formatters/index.mjs +1 -10
- package/dist/esm/formatters/list.mjs +1 -27
- package/dist/esm/formatters/list.mjs.map +1 -1
- package/dist/esm/formatters/number.mjs +1 -15
- package/dist/esm/formatters/number.mjs.map +1 -1
- package/dist/esm/formatters/percentage.mjs +1 -22
- package/dist/esm/formatters/percentage.mjs.map +1 -1
- package/dist/esm/formatters/relativeTime.mjs +1 -30
- package/dist/esm/formatters/relativeTime.mjs.map +1 -1
- package/dist/esm/formatters/units.mjs +1 -20
- package/dist/esm/formatters/units.mjs.map +1 -1
- package/dist/esm/getStorageAttributes.mjs +1 -132
- package/dist/esm/getStorageAttributes.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -82
- package/dist/esm/interpreter/getCondition.mjs +1 -25
- package/dist/esm/interpreter/getCondition.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/deepTransform.mjs +1 -39
- package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs +1 -31
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/index.mjs +1 -5
- package/dist/esm/interpreter/getContent/plugins.mjs +1 -153
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionary.mjs +1 -23
- package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getEnumeration.mjs +1 -69
- package/dist/esm/interpreter/getEnumeration.mjs.map +1 -1
- package/dist/esm/interpreter/getGender.mjs +1 -36
- package/dist/esm/interpreter/getGender.mjs.map +1 -1
- package/dist/esm/interpreter/getHTML.mjs +1 -119
- package/dist/esm/interpreter/getHTML.mjs.map +1 -1
- package/dist/esm/interpreter/getInsertion.mjs +1 -20
- package/dist/esm/interpreter/getInsertion.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.mjs +1 -36
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getNesting.mjs +1 -35
- package/dist/esm/interpreter/getNesting.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs +1 -110
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/interpreter/index.mjs +1 -13
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs +1 -53
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
- package/dist/esm/localization/getBrowserLocale.mjs +1 -138
- package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/localization/getHTMLTextDir.mjs +1 -62
- package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs +1 -24
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocaleFromPath.mjs +1 -42
- package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
- package/dist/esm/localization/getLocaleLang.mjs +1 -18
- package/dist/esm/localization/getLocaleLang.mjs.map +1 -1
- package/dist/esm/localization/getLocaleName.mjs +1 -9
- package/dist/esm/localization/getLocaleName.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +1 -79
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs +1 -60
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs +1 -52
- package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs +1 -60
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/localization/index.mjs +1 -17
- package/dist/esm/localization/localeDetector.mjs +1 -131
- package/dist/esm/localization/localeDetector.mjs.map +1 -1
- package/dist/esm/localization/localeMapper.mjs +1 -114
- package/dist/esm/localization/localeMapper.mjs.map +1 -1
- package/dist/esm/localization/localeResolver.mjs +1 -25
- package/dist/esm/localization/localeResolver.mjs.map +1 -1
- package/dist/esm/localization/rewriteUtils.mjs +1 -104
- package/dist/esm/localization/rewriteUtils.mjs.map +1 -1
- package/dist/esm/localization/validatePrefix.mjs +1 -51
- package/dist/esm/localization/validatePrefix.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +10 -786
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/constants.mjs +1 -247
- package/dist/esm/markdown/constants.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +1 -7
- package/dist/esm/markdown/parser.mjs +1 -65
- package/dist/esm/markdown/parser.mjs.map +1 -1
- package/dist/esm/markdown/renderer.mjs +1 -59
- package/dist/esm/markdown/renderer.mjs.map +1 -1
- package/dist/esm/markdown/utils.mjs +6 -361
- package/dist/esm/markdown/utils.mjs.map +1 -1
- package/dist/esm/messageFormat/ICU.mjs +1 -316
- package/dist/esm/messageFormat/ICU.mjs.map +1 -1
- package/dist/esm/messageFormat/i18next.mjs +1 -327
- package/dist/esm/messageFormat/i18next.mjs.map +1 -1
- package/dist/esm/messageFormat/index.mjs +1 -5
- package/dist/esm/messageFormat/verify-icu-format.mjs +2 -64
- package/dist/esm/messageFormat/verify-icu-format.mjs.map +1 -1
- package/dist/esm/messageFormat/vue-i18n.mjs +1 -163
- package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
- package/dist/esm/transpiler/condition/condition.mjs +1 -24
- package/dist/esm/transpiler/condition/condition.mjs.map +1 -1
- package/dist/esm/transpiler/condition/index.mjs +1 -3
- package/dist/esm/transpiler/enumeration/enumeration.mjs +1 -26
- package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/enumeration/index.mjs +1 -3
- package/dist/esm/transpiler/file/file.mjs +1 -49
- package/dist/esm/transpiler/file/file.mjs.map +1 -1
- package/dist/esm/transpiler/file/fileBrowser.mjs +1 -24
- package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -1
- package/dist/esm/transpiler/file/index.mjs +1 -3
- package/dist/esm/transpiler/gender/gender.mjs +1 -24
- package/dist/esm/transpiler/gender/gender.mjs.map +1 -1
- package/dist/esm/transpiler/gender/index.mjs +1 -3
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs +1 -43
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
- package/dist/esm/transpiler/html/html.mjs +1 -35
- package/dist/esm/transpiler/html/html.mjs.map +1 -1
- package/dist/esm/transpiler/html/htmlTags.mjs +1 -114
- package/dist/esm/transpiler/html/htmlTags.mjs.map +1 -1
- package/dist/esm/transpiler/html/index.mjs +1 -4
- package/dist/esm/transpiler/index.mjs +1 -13
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs +1 -9
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/index.mjs +1 -4
- package/dist/esm/transpiler/insertion/insertion.mjs +1 -34
- package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs +2 -22
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/index.mjs +1 -4
- package/dist/esm/transpiler/markdown/markdown.mjs +1 -52
- package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
- package/dist/esm/transpiler/nesting/index.mjs +1 -3
- package/dist/esm/transpiler/nesting/nesting.mjs +1 -25
- package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
- package/dist/esm/transpiler/translation/index.mjs +1 -3
- package/dist/esm/transpiler/translation/translation.mjs +1 -27
- package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
- package/dist/esm/utils/checkIsURLAbsolute.mjs +1 -5
- package/dist/esm/utils/checkIsURLAbsolute.mjs.map +1 -1
- package/dist/esm/utils/getCookie.mjs +1 -30
- package/dist/esm/utils/getCookie.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +1 -0
- package/dist/esm/utils/intl.mjs +1 -86
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/esm/utils/isSameKeyPath.mjs +1 -5
- package/dist/esm/utils/isSameKeyPath.mjs.map +1 -1
- package/dist/esm/utils/isValidReactElement.mjs +1 -12
- package/dist/esm/utils/isValidReactElement.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs +1 -135
- package/dist/esm/utils/localeStorage.mjs.map +1 -1
- package/dist/esm/utils/parseYaml.mjs +16 -320
- package/dist/esm/utils/parseYaml.mjs.map +1 -1
- package/dist/types/formatters/index.d.ts +2 -1
- package/dist/types/index.d.ts +8 -2
- package/dist/types/interpreter/getContent/plugins.d.ts +4 -4
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/localization/index.d.ts +2 -1
- package/dist/types/markdown/index.d.ts +4 -1
- package/dist/types/markdown/types.d.ts +1 -1
- package/dist/types/markdown/types.d.ts.map +1 -1
- package/dist/types/transpiler/translation/translation.d.ts +1 -1
- package/dist/types/utils/index.d.ts +8 -0
- package/package.json +65 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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":"
|
|
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,13 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { deepTransformNode } from "./getContent/deepTransform.mjs";
|
|
3
|
-
import { findMatchingCondition, getEnumeration } from "./getEnumeration.mjs";
|
|
4
|
-
import { getDictionary } from "./getDictionary.mjs";
|
|
5
|
-
import { getIntlayer } from "./getIntlayer.mjs";
|
|
6
|
-
import { getNesting } from "./getNesting.mjs";
|
|
7
|
-
import { getTranslation } from "./getTranslation.mjs";
|
|
8
|
-
import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, translationPlugin } from "./getContent/plugins.mjs";
|
|
9
|
-
import { getContent } from "./getContent/getContent.mjs";
|
|
10
|
-
import { getHTML } from "./getHTML.mjs";
|
|
11
|
-
import { splitInsertionTemplate } from "./splitAndJoinInsertion.mjs";
|
|
12
|
-
|
|
13
|
-
export { conditionPlugin, deepTransformNode, enumerationPlugin, filePlugin, findMatchingCondition, genderPlugin, getCondition, getContent, getDictionary, getEnumeration, getHTML, getIntlayer, getNesting, getTranslation, insertionPlugin, nestedPlugin, splitInsertionTemplate, translationPlugin };
|
|
1
|
+
import{getCondition as e}from"./getCondition.mjs";import{deepTransformNode as t}from"./getContent/deepTransform.mjs";import{findMatchingCondition as n,getEnumeration as r}from"./getEnumeration.mjs";import{getDictionary as i}from"./getDictionary.mjs";import{getIntlayer as a}from"./getIntlayer.mjs";import{getNesting as o}from"./getNesting.mjs";import{getTranslation as s}from"./getTranslation.mjs";import{conditionPlugin as c,enumerationPlugin as l,filePlugin as u,genderPlugin as d,insertionPlugin as f,nestedPlugin as p,translationPlugin as m}from"./getContent/plugins.mjs";import{getContent as h}from"./getContent/getContent.mjs";import{getHTML as g}from"./getHTML.mjs";import{splitInsertionTemplate as _}from"./splitAndJoinInsertion.mjs";export{c as conditionPlugin,t as deepTransformNode,l as enumerationPlugin,u as filePlugin,n as findMatchingCondition,d as genderPlugin,e as getCondition,h as getContent,i as getDictionary,r as getEnumeration,g as getHTML,a as getIntlayer,o as getNesting,s as getTranslation,f as insertionPlugin,p as nestedPlugin,_ as splitInsertionTemplate,m as translationPlugin};
|
|
@@ -1,54 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Check if a value is a complex object (not a primitive)
|
|
4
|
-
* Used to determine if values need to be wrapped in fragments
|
|
5
|
-
*/
|
|
6
|
-
const isComplexValue = (value) => {
|
|
7
|
-
return value !== null && value !== void 0 && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean";
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Core logic for splitting insertion strings and joining with values.
|
|
11
|
-
* Returns an array of parts that can be wrapped by framework-specific Fragment implementations.
|
|
12
|
-
*
|
|
13
|
-
* @param template - The template string with {{ placeholder }} syntax
|
|
14
|
-
* @param values - Map of placeholder names to their replacement values
|
|
15
|
-
* @returns Object with `isSimple` flag and `parts` array
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const result = splitInsertionTemplate('Hello {{ name }}!', { name: 'World' });
|
|
20
|
-
* // { isSimple: true, parts: 'Hello World!' }
|
|
21
|
-
*
|
|
22
|
-
* const result = splitInsertionTemplate('Hello {{ name }}!', { name: <Component /> });
|
|
23
|
-
* // { isSimple: false, parts: ['Hello ', <Component />, '!'] }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
const splitInsertionTemplate = (template, values = {}) => {
|
|
27
|
-
const safeValues = values ?? {};
|
|
28
|
-
if (!Object.values(safeValues).some(isComplexValue)) return {
|
|
29
|
-
isSimple: true,
|
|
30
|
-
parts: template.replace(/\{\{\s*(.*?)\s*\}\}/g, (_, key) => {
|
|
31
|
-
return (safeValues[key.trim()] ?? "").toString();
|
|
32
|
-
})
|
|
33
|
-
};
|
|
34
|
-
const parts = [];
|
|
35
|
-
let lastIndex = 0;
|
|
36
|
-
const regex = /\{\{\s*(.*?)\s*\}\}/g;
|
|
37
|
-
let match = regex.exec(template);
|
|
38
|
-
while (match !== null) {
|
|
39
|
-
if (match.index > lastIndex) parts.push(template.substring(lastIndex, match.index));
|
|
40
|
-
const value = safeValues[match[1].trim()];
|
|
41
|
-
if (value !== void 0 && value !== null) parts.push(value);
|
|
42
|
-
lastIndex = match.index + match[0].length;
|
|
43
|
-
match = regex.exec(template);
|
|
44
|
-
}
|
|
45
|
-
if (lastIndex < template.length) parts.push(template.substring(lastIndex));
|
|
46
|
-
return {
|
|
47
|
-
isSimple: false,
|
|
48
|
-
parts
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
|
-
export { splitInsertionTemplate };
|
|
1
|
+
const e=e=>e!=null&&typeof e!=`string`&&typeof e!=`number`&&typeof e!=`boolean`,t=(t,n={})=>{let r=n??{};if(!Object.values(r).some(e))return{isSimple:!0,parts:t.replace(/\{\{\s*(.*?)\s*\}\}/g,(e,t)=>(r[t.trim()]??``).toString())};let i=[],a=0,o=/\{\{\s*(.*?)\s*\}\}/g,s=o.exec(t);for(;s!==null;){s.index>a&&i.push(t.substring(a,s.index));let e=r[s[1].trim()];e!=null&&i.push(e),a=s.index+s[0].length,s=o.exec(t)}return a<t.length&&i.push(t.substring(a)),{isSimple:!1,parts:i}};export{t as splitInsertionTemplate};
|
|
54
2
|
//# sourceMappingURL=splitAndJoinInsertion.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitAndJoinInsertion.mjs","names":[],"sources":["../../../src/interpreter/splitAndJoinInsertion.ts"],"sourcesContent":["/**\n * Check if a value is a complex object (not a primitive)\n * Used to determine if values need to be wrapped in fragments\n */\nconst isComplexValue = (value: any): boolean => {\n return (\n value !== null &&\n value !== undefined &&\n typeof value !== 'string' &&\n typeof value !== 'number' &&\n typeof value !== 'boolean'\n );\n};\n\n/**\n * Core logic for splitting insertion strings and joining with values.\n * Returns an array of parts that can be wrapped by framework-specific Fragment implementations.\n *\n * @param template - The template string with {{ placeholder }} syntax\n * @param values - Map of placeholder names to their replacement values\n * @returns Object with `isSimple` flag and `parts` array\n *\n * @example\n * ```ts\n * const result = splitInsertionTemplate('Hello {{ name }}!', { name: 'World' });\n * // { isSimple: true, parts: 'Hello World!' }\n *\n * const result = splitInsertionTemplate('Hello {{ name }}!', { name: <Component /> });\n * // { isSimple: false, parts: ['Hello ', <Component />, '!'] }\n * ```\n */\nexport const splitInsertionTemplate = <T = any>(\n template: string,\n values: Record<string, T> = {}\n): { isSimple: boolean; parts: string | T[] } => {\n const safeValues = values ?? {};\n\n // Check if any value is a complex object (React/Vue node, etc.)\n const hasComplexValue = Object.values(safeValues).some(isComplexValue);\n\n if (!hasComplexValue) {\n // Simple string replacement\n const result = template.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, key) => {\n const trimmedKey = key.trim();\n return (safeValues[trimmedKey] ?? '').toString();\n });\n return { isSimple: true, parts: result };\n }\n\n // Split the template by placeholders while keeping the structure\n const parts: any[] = [];\n let lastIndex = 0;\n const regex = /\\{\\{\\s*(.*?)\\s*\\}\\}/g;\n let match: RegExpExecArray | null = regex.exec(template);\n\n while (match !== null) {\n // Add text before the placeholder\n if (match.index > lastIndex) {\n parts.push(template.substring(lastIndex, match.index));\n }\n\n // Add the replaced value\n const key = match[1].trim();\n const value = safeValues[key];\n if (value !== undefined && value !== null) {\n parts.push(value);\n }\n\n lastIndex = match.index + match[0].length;\n match = regex.exec(template);\n }\n\n // Add remaining text\n if (lastIndex < template.length) {\n parts.push(template.substring(lastIndex));\n }\n\n return { isSimple: false, parts };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"splitAndJoinInsertion.mjs","names":[],"sources":["../../../src/interpreter/splitAndJoinInsertion.ts"],"sourcesContent":["/**\n * Check if a value is a complex object (not a primitive)\n * Used to determine if values need to be wrapped in fragments\n */\nconst isComplexValue = (value: any): boolean => {\n return (\n value !== null &&\n value !== undefined &&\n typeof value !== 'string' &&\n typeof value !== 'number' &&\n typeof value !== 'boolean'\n );\n};\n\n/**\n * Core logic for splitting insertion strings and joining with values.\n * Returns an array of parts that can be wrapped by framework-specific Fragment implementations.\n *\n * @param template - The template string with {{ placeholder }} syntax\n * @param values - Map of placeholder names to their replacement values\n * @returns Object with `isSimple` flag and `parts` array\n *\n * @example\n * ```ts\n * const result = splitInsertionTemplate('Hello {{ name }}!', { name: 'World' });\n * // { isSimple: true, parts: 'Hello World!' }\n *\n * const result = splitInsertionTemplate('Hello {{ name }}!', { name: <Component /> });\n * // { isSimple: false, parts: ['Hello ', <Component />, '!'] }\n * ```\n */\nexport const splitInsertionTemplate = <T = any>(\n template: string,\n values: Record<string, T> = {}\n): { isSimple: boolean; parts: string | T[] } => {\n const safeValues = values ?? {};\n\n // Check if any value is a complex object (React/Vue node, etc.)\n const hasComplexValue = Object.values(safeValues).some(isComplexValue);\n\n if (!hasComplexValue) {\n // Simple string replacement\n const result = template.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, key) => {\n const trimmedKey = key.trim();\n return (safeValues[trimmedKey] ?? '').toString();\n });\n return { isSimple: true, parts: result };\n }\n\n // Split the template by placeholders while keeping the structure\n const parts: any[] = [];\n let lastIndex = 0;\n const regex = /\\{\\{\\s*(.*?)\\s*\\}\\}/g;\n let match: RegExpExecArray | null = regex.exec(template);\n\n while (match !== null) {\n // Add text before the placeholder\n if (match.index > lastIndex) {\n parts.push(template.substring(lastIndex, match.index));\n }\n\n // Add the replaced value\n const key = match[1].trim();\n const value = safeValues[key];\n if (value !== undefined && value !== null) {\n parts.push(value);\n }\n\n lastIndex = match.index + match[0].length;\n match = regex.exec(template);\n }\n\n // Add remaining text\n if (lastIndex < template.length) {\n parts.push(template.substring(lastIndex));\n }\n\n return { isSimple: false, parts };\n};\n"],"mappings":"AAIA,MAAM,EAAkB,GAEpB,GAAU,MAEV,OAAO,GAAU,UACjB,OAAO,GAAU,UACjB,OAAO,GAAU,UAqBR,GACX,EACA,EAA4B,EAAE,GACiB,CAC/C,IAAM,EAAa,GAAU,EAAE,CAK/B,GAAI,CAFoB,OAAO,OAAO,EAAW,CAAC,KAAK,EAAe,CAQpE,MAAO,CAAE,SAAU,GAAM,MAJV,EAAS,QAAQ,wBAAyB,EAAG,KAElD,EADW,EAAI,MAAM,GACK,IAAI,UAAU,CAChD,CACsC,CAI1C,IAAM,EAAe,EAAE,CACnB,EAAY,EACV,EAAQ,uBACV,EAAgC,EAAM,KAAK,EAAS,CAExD,KAAO,IAAU,MAAM,CAEjB,EAAM,MAAQ,GAChB,EAAM,KAAK,EAAS,UAAU,EAAW,EAAM,MAAM,CAAC,CAKxD,IAAM,EAAQ,EADF,EAAM,GAAG,MAAM,EAEvB,GAAiC,MACnC,EAAM,KAAK,EAAM,CAGnB,EAAY,EAAM,MAAQ,EAAM,GAAG,OACnC,EAAQ,EAAM,KAAK,EAAS,CAQ9B,OAJI,EAAY,EAAS,QACvB,EAAM,KAAK,EAAS,UAAU,EAAU,CAAC,CAGpC,CAAE,SAAU,GAAO,QAAO"}
|
|
@@ -1,139 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { localeDetector } from "./localeDetector.mjs";
|
|
3
|
-
import { Locales } from "@intlayer/types";
|
|
4
|
-
import configuration from "@intlayer/config/built";
|
|
5
|
-
|
|
6
|
-
//#region src/localization/getBrowserLocale.tsx
|
|
7
|
-
let LanguageDetector = /* @__PURE__ */ function(LanguageDetector) {
|
|
8
|
-
LanguageDetector["Querystring"] = "querystring";
|
|
9
|
-
LanguageDetector["Storage"] = "storage";
|
|
10
|
-
LanguageDetector["Navigator"] = "navigator";
|
|
11
|
-
LanguageDetector["HtmlTag"] = "htmlTag";
|
|
12
|
-
return LanguageDetector;
|
|
13
|
-
}({});
|
|
14
|
-
const localeStorageOptions = {
|
|
15
|
-
getCookie: (name) => document.cookie.split(";").find((c) => c.trim().startsWith(`${name}=`))?.split("=")[1],
|
|
16
|
-
getLocaleStorage: (name) => localStorage.getItem(name),
|
|
17
|
-
getSessionStorage: (name) => sessionStorage.getItem(name),
|
|
18
|
-
isCookieEnabled: true,
|
|
19
|
-
setCookieStore: (name, value, attributes) => cookieStore.set({
|
|
20
|
-
name,
|
|
21
|
-
value,
|
|
22
|
-
path: attributes.path,
|
|
23
|
-
domain: attributes.domain,
|
|
24
|
-
expires: attributes.expires,
|
|
25
|
-
sameSite: attributes.sameSite
|
|
26
|
-
}),
|
|
27
|
-
setCookieString: (cookie) => {
|
|
28
|
-
document.cookie = cookie;
|
|
29
|
-
},
|
|
30
|
-
setSessionStorage: (name, value) => sessionStorage.setItem(name, value),
|
|
31
|
-
setLocaleStorage: (name, value) => localStorage.setItem(name, value)
|
|
32
|
-
};
|
|
33
|
-
const getDefaultsOptions = () => {
|
|
34
|
-
return {
|
|
35
|
-
order: [
|
|
36
|
-
LanguageDetector.Querystring,
|
|
37
|
-
LanguageDetector.Storage,
|
|
38
|
-
LanguageDetector.Navigator,
|
|
39
|
-
LanguageDetector.HtmlTag
|
|
40
|
-
],
|
|
41
|
-
lookupQuerystring: "locale",
|
|
42
|
-
htmlTag: typeof document !== "undefined" ? document.documentElement : null
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
const detectLanguage = (order, options) => {
|
|
46
|
-
const detected = {};
|
|
47
|
-
const queryStringDetector = () => {
|
|
48
|
-
if (typeof window === "undefined") return;
|
|
49
|
-
const search = window.location.search || "";
|
|
50
|
-
const value = new URLSearchParams(search).get(options.lookupQuerystring ?? "");
|
|
51
|
-
if (value) detected[LanguageDetector.Querystring] = value;
|
|
52
|
-
};
|
|
53
|
-
const storageDetector = () => {
|
|
54
|
-
if (typeof window === "undefined") return;
|
|
55
|
-
const locale = getLocaleFromStorage({
|
|
56
|
-
getCookie: (name) => {
|
|
57
|
-
try {
|
|
58
|
-
const cookies = document.cookie.split(";");
|
|
59
|
-
const cookieName = `${name}=`;
|
|
60
|
-
const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
|
|
61
|
-
if (cookie) return cookie.split("=")[1].trim();
|
|
62
|
-
} catch {}
|
|
63
|
-
},
|
|
64
|
-
getSessionStorage: (name) => {
|
|
65
|
-
try {
|
|
66
|
-
return window.sessionStorage.getItem(name) ?? void 0;
|
|
67
|
-
} catch {}
|
|
68
|
-
},
|
|
69
|
-
getLocaleStorage: (name) => {
|
|
70
|
-
try {
|
|
71
|
-
return window.localStorage.getItem(name) ?? void 0;
|
|
72
|
-
} catch {}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
if (locale) detected[LanguageDetector.Storage] = locale;
|
|
76
|
-
};
|
|
77
|
-
const navigatorDetector = () => {
|
|
78
|
-
if (typeof navigator === "undefined") return;
|
|
79
|
-
const { internationalization } = configuration;
|
|
80
|
-
const languages = navigator.languages ?? [navigator.language];
|
|
81
|
-
const locale = localeDetector({ "accept-language": languages.join(",") }, internationalization.locales, internationalization.defaultLocale);
|
|
82
|
-
if (locale) detected[LanguageDetector.Navigator] = locale;
|
|
83
|
-
};
|
|
84
|
-
const htmlTagDetector = () => {
|
|
85
|
-
const htmlTag = options.htmlTag;
|
|
86
|
-
if (htmlTag && typeof htmlTag.getAttribute === "function") {
|
|
87
|
-
const lang = htmlTag.getAttribute("lang");
|
|
88
|
-
if (lang) {
|
|
89
|
-
const { internationalization } = configuration;
|
|
90
|
-
const locale = localeDetector({ "accept-language": lang }, internationalization.locales, internationalization.defaultLocale);
|
|
91
|
-
detected[LanguageDetector.HtmlTag] = locale;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const detectors = {
|
|
96
|
-
[LanguageDetector.Querystring]: queryStringDetector,
|
|
97
|
-
[LanguageDetector.Storage]: storageDetector,
|
|
98
|
-
[LanguageDetector.Navigator]: navigatorDetector,
|
|
99
|
-
[LanguageDetector.HtmlTag]: htmlTagDetector
|
|
100
|
-
};
|
|
101
|
-
order.forEach((detectorName) => {
|
|
102
|
-
detectors[detectorName]?.();
|
|
103
|
-
});
|
|
104
|
-
return detected;
|
|
105
|
-
};
|
|
106
|
-
const getFirstAvailableLocale = (locales, order) => {
|
|
107
|
-
const { internationalization } = configuration;
|
|
108
|
-
for (const detector of order) {
|
|
109
|
-
const locale = locales[detector];
|
|
110
|
-
if (locale && internationalization.locales.includes(locale)) return locale;
|
|
111
|
-
}
|
|
112
|
-
return internationalization?.defaultLocale ?? Locales.ENGLISH;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Core language detector function for browser environments.
|
|
116
|
-
*
|
|
117
|
-
* Detects the user's preferred locale by checking multiple sources in order:
|
|
118
|
-
* 1. Query string parameter
|
|
119
|
-
* 2. Storage (cookies, localStorage, sessionStorage) - uses getLocaleFromStorage
|
|
120
|
-
* 3. Navigator languages - uses localeDetector
|
|
121
|
-
* 4. HTML lang attribute - uses localeDetector
|
|
122
|
-
*
|
|
123
|
-
* @param userOptions - Optional configuration for detection order and lookup keys
|
|
124
|
-
* @returns The detected locale or the default locale
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* const locale = getBrowserLocale({ order: [LanguageDetector.Storage, LanguageDetector.Navigator] });
|
|
128
|
-
*/
|
|
129
|
-
const getBrowserLocale = (userOptions = {}) => {
|
|
130
|
-
const options = {
|
|
131
|
-
...getDefaultsOptions(),
|
|
132
|
-
...userOptions
|
|
133
|
-
};
|
|
134
|
-
return getFirstAvailableLocale(detectLanguage(options.order ?? [], options), options.order ?? []);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
//#endregion
|
|
138
|
-
export { LanguageDetector, getBrowserLocale, localeStorageOptions };
|
|
1
|
+
import{getLocaleFromStorage as e}from"../utils/localeStorage.mjs";import{localeDetector as t}from"./localeDetector.mjs";import{Locales as n}from"@intlayer/types";import r from"@intlayer/config/built";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=>{document.cookie=e},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=(n,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}=r,n=navigator.languages??[navigator.language],a=t({"accept-language":n.join(`,`)},e.locales,e.defaultLocale);a&&(o[i.Navigator]=a)},u=()=>{let e=a.htmlTag;if(e&&typeof e.getAttribute==`function`){let n=e.getAttribute(`lang`);if(n){let{internationalization:e}=r,a=t({"accept-language":n},e.locales,e.defaultLocale);o[i.HtmlTag]=a}}},d={[i.Querystring]:s,[i.Storage]:c,[i.Navigator]:l,[i.HtmlTag]:u};return n.forEach(e=>{d[e]?.()}),o},c=(e,t)=>{let{internationalization:i}=r;for(let n of t){let t=e[n];if(t&&i.locales.includes(t))return t}return i?.defaultLocale??n.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};
|
|
139
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 { type Locale, Locales } from '@intlayer/types';\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: (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 const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\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":"
|
|
1
|
+
{"version":3,"file":"getBrowserLocale.mjs","names":[],"sources":["../../../src/localization/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locale, Locales } from '@intlayer/types';\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: (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 const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\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":"wMAQA,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,YAAA,cACA,EAAA,QAAA,UACA,EAAA,UAAA,YACA,EAAA,QAAA,iBAGF,MAAa,EAA6C,CACxD,UAAY,GACV,SAAS,OACN,MAAM,IAAI,CACV,KAAM,GAAM,EAAE,MAAM,CAAC,WAAW,GAAG,EAAK,GAAG,CAAC,EAC3C,MAAM,IAAI,CAAC,GACjB,iBAAmB,GAAiB,aAAa,QAAQ,EAAK,CAC9D,kBAAoB,GAAiB,eAAe,QAAQ,EAAK,CACjE,gBAAiB,GACjB,gBAAiB,EAAM,EAAO,IAC5B,YAAY,IAAI,CACd,OACA,QACA,KAAM,EAAW,KACjB,OAAQ,EAAW,OACnB,QAAS,EAAW,QACpB,SAAU,EAAW,SACtB,CAAC,CACJ,gBAAkB,GAAW,CAE3B,SAAS,OAAS,GAEpB,mBAAoB,EAAM,IAAU,eAAe,QAAQ,EAAM,EAAM,CACvE,kBAAmB,EAAM,IAAU,aAAa,QAAQ,EAAM,EAAM,CACrE,CASK,OACG,CACL,MAAO,CACL,EAAiB,YACjB,EAAiB,QACjB,EAAiB,UACjB,EAAiB,QAClB,CACD,kBAAmB,SACnB,QAAS,OAAO,SAAa,IAAc,SAAS,gBAAkB,KACvE,EAGG,GACJ,EACA,IACiD,CACjD,IAAM,EAAyD,EAAE,CAK3D,MAA4B,CAChC,GAAI,OAAO,OAAW,IAAa,OACnC,IAAM,EAAS,OAAO,SAAS,QAAU,GAEnC,EADS,IAAI,gBAAgB,EAAO,CACrB,IAAI,EAAQ,mBAAqB,GAAG,CACrD,IACF,EAAS,EAAiB,aAAe,IAIvC,MAAwB,CAC5B,GAAI,OAAO,OAAW,IAAa,OAEnC,IAAM,EAAS,EAAqB,CAClC,UAAY,GAAiB,CAC3B,GAAI,CACF,IAAM,EAAU,SAAS,OAAO,MAAM,IAAI,CACpC,EAAa,GAAG,EAAK,GACrB,EAAS,EAAQ,KAAM,GAAM,EAAE,MAAM,CAAC,WAAW,EAAW,CAAC,CACnE,GAAI,EACF,OAAO,EAAO,MAAM,IAAI,CAAC,GAAG,MAAM,MAE9B,IAGV,kBAAoB,GAAiB,CACnC,GAAI,CACF,OAAO,OAAO,eAAe,QAAQ,EAAK,EAAI,IAAA,QACxC,IAGV,iBAAmB,GAAiB,CAClC,GAAI,CACF,OAAO,OAAO,aAAa,QAAQ,EAAK,EAAI,IAAA,QACtC,IAGX,CAAC,CAEE,IACF,EAAS,EAAiB,SAAW,IAInC,MAA0B,CAC9B,GAAI,OAAO,UAAc,IAAa,OAEtC,GAAM,CAAE,wBAAyB,EAC3B,EAAY,UAAU,WAAa,CAAC,UAAU,SAAS,CAGvD,EAAS,EACb,CAAE,kBAAmB,EAAU,KAAK,IAAI,CAAE,CAC1C,EAAqB,QACrB,EAAqB,cACtB,CAEG,IACF,EAAS,EAAiB,WAAa,IAIrC,MAAwB,CAC5B,IAAM,EAAU,EAAQ,QACxB,GAAI,GAAW,OAAO,EAAQ,cAAiB,WAAY,CACzD,IAAM,EAAO,EAAQ,aAAa,OAAO,CACzC,GAAI,EAAM,CACR,GAAM,CAAE,wBAAyB,EAG3B,EAAS,EACb,CAAE,kBAAmB,EAAM,CAC3B,EAAqB,QACrB,EAAqB,cACtB,CAED,EAAS,EAAiB,SAAW,KAMrC,EAAwC,EAC3C,EAAiB,aAAc,GAC/B,EAAiB,SAAU,GAC3B,EAAiB,WAAY,GAC7B,EAAiB,SAAU,EAC7B,CAOD,OAJA,EAAM,QAAS,GAAiB,CAC9B,EAAU,MAAiB,EAC3B,CAEK,GAGH,GACJ,EACA,IACW,CACX,GAAM,CAAE,wBAAyB,EAEjC,IAAK,IAAM,KAAY,EAAO,CAC5B,IAAM,EAAS,EAAQ,GAEvB,GAAI,GAAU,EAAqB,QAAQ,SAAS,EAAO,CACzD,OAAO,EAIX,OAAO,GAAsB,eAAiB,EAAQ,SAkB3C,GACX,EAAmD,EAAE,GAC1C,CACX,IAAM,EAAU,CAAE,GAAG,GAAoB,CAAE,GAAG,EAAa,CAI3D,OAAO,EAFS,EAAe,EAAQ,OAAS,EAAE,CAAE,EAAQ,CAEpB,EAAQ,OAAS,EAAE,CAAC"}
|
|
@@ -1,63 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/localization/getHTMLTextDir.ts
|
|
4
|
-
/**
|
|
5
|
-
* Returns the text direction of the given locale.
|
|
6
|
-
*
|
|
7
|
-
* Example:
|
|
8
|
-
*
|
|
9
|
-
* getHTMLTextDir('en-US') // 'ltr'
|
|
10
|
-
* getHTMLTextDir('en') // 'ltr'
|
|
11
|
-
* getHTMLTextDir('fr-CA') // 'ltr'
|
|
12
|
-
* getHTMLTextDir('fr') // 'ltr'
|
|
13
|
-
*
|
|
14
|
-
* @param locale The locale to get the text direction for.
|
|
15
|
-
* @returns The text direction of the given locale.
|
|
16
|
-
*/
|
|
17
|
-
const getHTMLTextDir = (locale) => {
|
|
18
|
-
switch (locale) {
|
|
19
|
-
case Locales.ARABIC:
|
|
20
|
-
case Locales.ARABIC_UNITED_ARAB_EMIRATES:
|
|
21
|
-
case Locales.ARABIC_BAHRAIN:
|
|
22
|
-
case Locales.ARABIC_ALGERIA:
|
|
23
|
-
case Locales.ARABIC_EGYPT:
|
|
24
|
-
case Locales.ARABIC_IRAQ:
|
|
25
|
-
case Locales.ARABIC_JORDAN:
|
|
26
|
-
case Locales.ARABIC_KUWAIT:
|
|
27
|
-
case Locales.ARABIC_LEBANON:
|
|
28
|
-
case Locales.ARABIC_LIBYA:
|
|
29
|
-
case Locales.ARABIC_MOROCCO:
|
|
30
|
-
case Locales.ARABIC_OMAN:
|
|
31
|
-
case Locales.ARABIC_QATAR:
|
|
32
|
-
case Locales.ARABIC_SAUDI_ARABIA:
|
|
33
|
-
case Locales.ARABIC_SYRIA:
|
|
34
|
-
case Locales.ARABIC_TUNISIA:
|
|
35
|
-
case Locales.ARABIC_YEMEN:
|
|
36
|
-
case Locales.ARABIC_MAURITANIA:
|
|
37
|
-
case Locales.ARABIC_PALESTINE:
|
|
38
|
-
case Locales.ARABIC_SUDAN:
|
|
39
|
-
case Locales.ARABIC_DJIBOUTI:
|
|
40
|
-
case Locales.ARABIC_SOMALIA:
|
|
41
|
-
case Locales.ARABIC_CHAD:
|
|
42
|
-
case Locales.ARABIC_COMOROS:
|
|
43
|
-
case Locales.HEBREW:
|
|
44
|
-
case Locales.HEBREW_ISRAEL:
|
|
45
|
-
case Locales.FARSI:
|
|
46
|
-
case Locales.FARSI_IRAN:
|
|
47
|
-
case Locales.URDU:
|
|
48
|
-
case Locales.URDU_ISLAMIC_REPUBLIC_OF_PAKISTAN:
|
|
49
|
-
case Locales.PASHTO:
|
|
50
|
-
case Locales.PASHTO_AFGHANISTAN:
|
|
51
|
-
case Locales.SYRIAC:
|
|
52
|
-
case Locales.SYRIAC_SYRIA:
|
|
53
|
-
case Locales.DIVEHI:
|
|
54
|
-
case Locales.DIVEHI_MALDIVES:
|
|
55
|
-
case Locales.YIDDISH:
|
|
56
|
-
case Locales.YIDDISH_WORLD: return "rtl";
|
|
57
|
-
default: return "ltr";
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
export { getHTMLTextDir };
|
|
1
|
+
import{Locales as e}from"@intlayer/types";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};
|
|
63
2
|
//# sourceMappingURL=getHTMLTextDir.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHTMLTextDir.mjs","names":[],"sources":["../../../src/localization/getHTMLTextDir.ts"],"sourcesContent":["import { Locales, type LocalesValues } from '@intlayer/types';\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":"
|
|
1
|
+
{"version":3,"file":"getHTMLTextDir.mjs","names":[],"sources":["../../../src/localization/getHTMLTextDir.ts"],"sourcesContent":["import { Locales, type LocalesValues } from '@intlayer/types';\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":"0CAiBA,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,25 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { localeResolver } from "./localeResolver.mjs";
|
|
3
|
-
import { getPreferredLanguages } from "./localeDetector.mjs";
|
|
4
|
-
import { DefaultValues } from "@intlayer/config/client";
|
|
5
|
-
import configuration from "@intlayer/config/built";
|
|
6
|
-
|
|
7
|
-
//#region src/localization/getLocale.ts
|
|
8
|
-
const getLocale = async (ctx = {}) => {
|
|
9
|
-
const defaultLocale = configuration?.internationalization?.defaultLocale ?? DefaultValues.Internationalization.DEFAULT_LOCALE;
|
|
10
|
-
const availableLocales = configuration?.internationalization?.locales ?? DefaultValues.Internationalization.LOCALES;
|
|
11
|
-
const storedLocale = getLocaleFromStorage({
|
|
12
|
-
getCookie: ctx.getCookie,
|
|
13
|
-
getHeader: ctx.getHeader
|
|
14
|
-
});
|
|
15
|
-
if (storedLocale) return storedLocale;
|
|
16
|
-
const acceptLanguageHeader = ctx.getHeader?.("accept-language");
|
|
17
|
-
if (!acceptLanguageHeader) return defaultLocale;
|
|
18
|
-
const userFallbackLocale = localeResolver(getPreferredLanguages(acceptLanguageHeader, availableLocales), availableLocales, defaultLocale);
|
|
19
|
-
if (userFallbackLocale) return userFallbackLocale;
|
|
20
|
-
return defaultLocale;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
export { getLocale };
|
|
1
|
+
import{getLocaleFromStorage as e}from"../utils/localeStorage.mjs";import{localeResolver as t}from"./localeResolver.mjs";import{getPreferredLanguages as n}from"./localeDetector.mjs";import{DefaultValues as r}from"@intlayer/config/client";import i from"@intlayer/config/built";const a=async(a={})=>{let o=i?.internationalization?.defaultLocale??r.Internationalization.DEFAULT_LOCALE,s=i?.internationalization?.locales??r.Internationalization.LOCALES,c=e({getCookie:a.getCookie,getHeader:a.getHeader});if(c)return c;let l=a.getHeader?.(`accept-language`);return l&&t(n(l,s),s,o)||o};export{a as getLocale};
|
|
25
2
|
//# sourceMappingURL=getLocale.mjs.map
|
|
@@ -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":"
|
|
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,43 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DefaultValues } from "@intlayer/config/client";
|
|
3
|
-
import configuration from "@intlayer/config/built";
|
|
4
|
-
|
|
5
|
-
//#region src/localization/getLocaleFromPath.ts
|
|
6
|
-
/**
|
|
7
|
-
* Extracts the locale segment from the given URL or pathname based on the routing mode.
|
|
8
|
-
*
|
|
9
|
-
* Mode Behaviors:
|
|
10
|
-
* - 'prefix-no-default': Checks path prefiIf no prefix found, assumes default locale.
|
|
11
|
-
* - 'prefix-all': Checks path prefix.
|
|
12
|
-
* - 'search-params': Checks for 'locale' query parameter.
|
|
13
|
-
* - 'no-prefix': Returns undefined (or default if fallback is true).
|
|
14
|
-
*
|
|
15
|
-
* @param inputUrl - The complete URL string or pathname to process.
|
|
16
|
-
* @returns The detected locale, default locale (if fallback/implicit), or undefined.
|
|
17
|
-
*/
|
|
18
|
-
const getLocaleFromPath = (inputUrl = "/", options) => {
|
|
19
|
-
const { defaultLocale, locales, mode } = {
|
|
20
|
-
defaultLocale: configuration?.internationalization?.defaultLocale ?? DefaultValues.Internationalization.DEFAULT_LOCALE,
|
|
21
|
-
mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,
|
|
22
|
-
locales: configuration?.internationalization?.locales ?? DefaultValues.Internationalization.LOCALES,
|
|
23
|
-
...options
|
|
24
|
-
};
|
|
25
|
-
if (!defaultLocale || !locales) return DefaultValues.Internationalization.DEFAULT_LOCALE;
|
|
26
|
-
const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);
|
|
27
|
-
let fixedInputUrl = inputUrl;
|
|
28
|
-
if (inputUrl?.endsWith("/") && inputUrl.length > 1) fixedInputUrl = inputUrl.slice(0, -1);
|
|
29
|
-
const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
|
|
30
|
-
if (mode === "search-params") {
|
|
31
|
-
const localeParam = url.searchParams.get("locale");
|
|
32
|
-
if (localeParam && locales.includes(localeParam)) return localeParam;
|
|
33
|
-
return defaultLocale;
|
|
34
|
-
}
|
|
35
|
-
if (mode === "no-prefix") return defaultLocale;
|
|
36
|
-
const firstSegment = url.pathname.split("/")[1];
|
|
37
|
-
if (firstSegment && locales.includes(firstSegment)) return firstSegment;
|
|
38
|
-
if (mode === "prefix-no-default") return defaultLocale;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
export { getLocaleFromPath };
|
|
1
|
+
import{checkIsURLAbsolute as e}from"../utils/checkIsURLAbsolute.mjs";import{DefaultValues as t}from"@intlayer/config/client";import n from"@intlayer/config/built";const r=(r=`/`,i)=>{let{defaultLocale:a,locales:o,mode:s}={defaultLocale:n?.internationalization?.defaultLocale??t.Internationalization.DEFAULT_LOCALE,mode:n?.routing?.mode??t.Routing.ROUTING_MODE,locales:n?.internationalization?.locales??t.Internationalization.LOCALES,...i};if(!a||!o)return t.Internationalization.DEFAULT_LOCALE;let c=e(r),l=r;r?.endsWith(`/`)&&r.length>1&&(l=r.slice(0,-1));let u=c?new URL(l):new URL(l,`http://example.com`);if(s===`search-params`){let e=u.searchParams.get(`locale`);return e&&o.includes(e)?e:a}if(s===`no-prefix`)return a;let d=u.pathname.split(`/`)[1];if(d&&o.includes(d))return d;if(s===`prefix-no-default`)return a};export{r as getLocaleFromPath};
|
|
43
2
|
//# sourceMappingURL=getLocaleFromPath.mjs.map
|
|
@@ -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 { Locale, LocalesValues, RoutingConfig } from '@intlayer/types';\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":"
|
|
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 { Locale, LocalesValues, RoutingConfig } from '@intlayer/types';\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":"mKAuBA,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,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Returns the language code of the given locale for locales including the country code.
|
|
4
|
-
*
|
|
5
|
-
* Example:
|
|
6
|
-
*
|
|
7
|
-
* getLocaleLang('en-US') // 'en'
|
|
8
|
-
* getLocaleLang('en') // 'en'
|
|
9
|
-
* getLocaleLang('fr-CA') // 'fr'
|
|
10
|
-
* getLocaleLang('fr') // 'fr'
|
|
11
|
-
*
|
|
12
|
-
* @param locale The locale to get the language code for.
|
|
13
|
-
* @returns The language code of the given locale.
|
|
14
|
-
*/
|
|
15
|
-
const getLocaleLang = (locale) => locale?.split("-")[0] ?? "";
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { getLocaleLang };
|
|
1
|
+
const e=e=>e?.split(`-`)[0]??``;export{e as getLocaleLang};
|
|
19
2
|
//# sourceMappingURL=getLocaleLang.mjs.map
|
|
@@ -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":"
|
|
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,10 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/localization/getLocaleName.ts
|
|
4
|
-
const getLocaleName = (displayLocale, targetLocale = displayLocale) => {
|
|
5
|
-
return new CachedIntl.DisplayNames(targetLocale, { type: "language" }).of(displayLocale) ?? "Unknown locale";
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
//#endregion
|
|
9
|
-
export { getLocaleName };
|
|
1
|
+
import{CachedIntl as e}from"../utils/intl.mjs";const t=(t,n=t)=>new e.DisplayNames(n,{type:`language`}).of(t)??`Unknown locale`;export{t as getLocaleName};
|
|
10
2
|
//# sourceMappingURL=getLocaleName.mjs.map
|
|
@@ -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":"
|
|
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"}
|