@intlayer/core 6.1.6 → 7.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +213 -0
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -0
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +95 -0
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -0
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs +46 -0
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -0
- package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs +33 -0
- package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs.map +1 -0
- package/dist/cjs/deepTransformPlugins/getMaskContent.cjs +27 -0
- package/dist/cjs/deepTransformPlugins/getMaskContent.cjs.map +1 -0
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +45 -0
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -0
- package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs +60 -0
- package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs.map +1 -0
- package/dist/cjs/deepTransformPlugins/index.cjs +25 -0
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs +107 -0
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +59 -91
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +13 -39
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +48 -94
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +24 -68
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +21 -56
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs +32 -49
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getUnmergedDictionaryByKeyPath.cjs +18 -50
- package/dist/cjs/dictionaryManipulator/getUnmergedDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/index.cjs +28 -41
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs +69 -0
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs +30 -0
- package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs +48 -0
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +29 -54
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +37 -63
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +36 -76
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
- package/dist/cjs/formatters/compact.cjs +24 -46
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs +28 -50
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs +56 -79
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/index.cjs +17 -37
- package/dist/cjs/formatters/list.cjs +29 -47
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs +17 -43
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs +22 -51
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs +28 -70
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs +22 -48
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/getStorageAttributes.cjs +116 -0
- package/dist/cjs/getStorageAttributes.cjs.map +1 -0
- package/dist/cjs/index.cjs +154 -45
- package/dist/cjs/interpreter/getCondition.cjs +30 -30
- package/dist/cjs/interpreter/getCondition.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs +38 -63
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs +31 -54
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/index.cjs +13 -27
- package/dist/cjs/interpreter/getContent/plugins.cjs +135 -175
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionary.cjs +21 -39
- package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getEnumeration.cjs +69 -42
- package/dist/cjs/interpreter/getEnumeration.cjs.map +1 -1
- package/dist/cjs/interpreter/getGender.cjs +33 -34
- package/dist/cjs/interpreter/getGender.cjs.map +1 -1
- package/dist/cjs/interpreter/getInsertion.cjs +18 -27
- package/dist/cjs/interpreter/getInsertion.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs +13 -48
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getNesting.cjs +26 -41
- package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs +29 -32
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/interpreter/index.cjs +26 -39
- package/dist/cjs/localization/getBrowserLocale.cjs +144 -0
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -0
- package/dist/cjs/localization/getHTMLTextDir.cjs +49 -255
- package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs +40 -56
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleLang.cjs +18 -27
- package/dist/cjs/localization/getLocaleLang.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleName.cjs +7 -32
- package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +46 -47
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs +69 -65
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs +53 -61
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/localization/index.cjs +26 -63
- package/dist/cjs/localization/localeDetector.cjs +108 -39
- package/dist/cjs/localization/localeDetector.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs +118 -72
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/localization/localeResolver.cjs +26 -61
- package/dist/cjs/localization/localeResolver.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/condition.cjs +26 -29
- package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/index.cjs +3 -23
- package/dist/cjs/transpiler/enumeration/enumeration.cjs +28 -29
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/index.cjs +3 -23
- package/dist/cjs/transpiler/file/file.cjs +52 -71
- package/dist/cjs/transpiler/file/file.cjs.map +1 -1
- package/dist/cjs/transpiler/file/fileBrowser.cjs +24 -33
- package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
- package/dist/cjs/transpiler/file/index.cjs +4 -23
- package/dist/cjs/transpiler/gender/gender.cjs +26 -29
- package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
- package/dist/cjs/transpiler/gender/index.cjs +3 -23
- package/dist/cjs/transpiler/index.cjs +19 -35
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs +8 -31
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/index.cjs +5 -25
- package/dist/cjs/transpiler/insertion/insertion.cjs +34 -51
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs +53 -86
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/index.cjs +5 -25
- package/dist/cjs/transpiler/markdown/markdown.cjs +33 -52
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/nesting/index.cjs +3 -23
- package/dist/cjs/transpiler/nesting/nesting.cjs +26 -31
- package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/index.cjs +3 -23
- package/dist/cjs/transpiler/translation/translation.cjs +29 -29
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/utils/checkIsURLAbsolute.cjs +5 -27
- package/dist/cjs/utils/checkIsURLAbsolute.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +48 -74
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/isSameKeyPath.cjs +6 -30
- package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -1
- package/dist/cjs/utils/isValidReactElement.cjs +12 -27
- package/dist/cjs/utils/isValidReactElement.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs +143 -0
- package/dist/cjs/utils/localeStorage.cjs.map +1 -0
- package/dist/cjs/utils/parseYaml.cjs +185 -55
- package/dist/cjs/utils/parseYaml.cjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs +208 -0
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -0
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs +90 -0
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -0
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs +43 -0
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -0
- package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs +32 -0
- package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -0
- package/dist/esm/deepTransformPlugins/getMaskContent.mjs +26 -0
- package/dist/esm/deepTransformPlugins/getMaskContent.mjs.map +1 -0
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs +41 -0
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -0
- package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs +60 -0
- package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs.map +1 -0
- package/dist/esm/deepTransformPlugins/index.mjs +10 -0
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs +105 -0
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +57 -67
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +11 -15
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +46 -70
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +22 -44
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +19 -32
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeType.mjs +31 -26
- package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getUnmergedDictionaryByKeyPath.mjs +14 -15
- package/dist/esm/dictionaryManipulator/getUnmergedDictionaryByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/index.mjs +15 -11
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs +66 -0
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs +29 -0
- package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs +46 -0
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +27 -30
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +35 -39
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +34 -52
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
- package/dist/esm/formatters/compact.mjs +21 -11
- package/dist/esm/formatters/compact.mjs.map +1 -1
- package/dist/esm/formatters/currency.mjs +25 -15
- package/dist/esm/formatters/currency.mjs.map +1 -1
- package/dist/esm/formatters/date.mjs +53 -44
- package/dist/esm/formatters/date.mjs.map +1 -1
- package/dist/esm/formatters/index.mjs +10 -9
- package/dist/esm/formatters/list.mjs +26 -12
- package/dist/esm/formatters/list.mjs.map +1 -1
- package/dist/esm/formatters/number.mjs +14 -8
- package/dist/esm/formatters/number.mjs.map +1 -1
- package/dist/esm/formatters/percentage.mjs +19 -16
- package/dist/esm/formatters/percentage.mjs.map +1 -1
- package/dist/esm/formatters/relativeTime.mjs +25 -35
- package/dist/esm/formatters/relativeTime.mjs.map +1 -1
- package/dist/esm/formatters/units.mjs +19 -13
- package/dist/esm/formatters/units.mjs.map +1 -1
- package/dist/esm/getStorageAttributes.mjs +114 -0
- package/dist/esm/getStorageAttributes.mjs.map +1 -0
- package/dist/esm/index.mjs +67 -13
- package/dist/esm/interpreter/getCondition.mjs +29 -6
- package/dist/esm/interpreter/getCondition.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/deepTransform.mjs +36 -39
- package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs +28 -26
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/index.mjs +5 -4
- package/dist/esm/interpreter/getContent/plugins.mjs +121 -139
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionary.mjs +20 -14
- package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getEnumeration.mjs +67 -17
- package/dist/esm/interpreter/getEnumeration.mjs.map +1 -1
- package/dist/esm/interpreter/getGender.mjs +32 -10
- package/dist/esm/interpreter/getGender.mjs.map +1 -1
- package/dist/esm/interpreter/getInsertion.mjs +17 -3
- package/dist/esm/interpreter/getInsertion.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.mjs +10 -13
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getNesting.mjs +25 -16
- package/dist/esm/interpreter/getNesting.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs +28 -8
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/interpreter/index.mjs +11 -10
- package/dist/esm/localization/getBrowserLocale.mjs +139 -0
- package/dist/esm/localization/getBrowserLocale.mjs.map +1 -0
- package/dist/esm/localization/getHTMLTextDir.mjs +47 -231
- package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
- package/dist/esm/localization/getLocaleFromPath.mjs +36 -21
- package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
- package/dist/esm/localization/getLocaleLang.mjs +17 -3
- package/dist/esm/localization/getLocaleLang.mjs.map +1 -1
- package/dist/esm/localization/getLocaleName.mjs +7 -8
- package/dist/esm/localization/getLocaleName.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +43 -12
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs +65 -29
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs +50 -26
- package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
- package/dist/esm/localization/index.mjs +7 -21
- package/dist/esm/localization/localeDetector.mjs +109 -6
- package/dist/esm/localization/localeDetector.mjs.map +1 -1
- package/dist/esm/localization/localeMapper.mjs +112 -35
- package/dist/esm/localization/localeMapper.mjs.map +1 -1
- package/dist/esm/localization/localeResolver.mjs +23 -26
- package/dist/esm/localization/localeResolver.mjs.map +1 -1
- package/dist/esm/transpiler/condition/condition.mjs +23 -7
- package/dist/esm/transpiler/condition/condition.mjs.map +1 -1
- package/dist/esm/transpiler/condition/index.mjs +3 -2
- package/dist/esm/transpiler/enumeration/enumeration.mjs +25 -7
- package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/enumeration/index.mjs +3 -2
- package/dist/esm/transpiler/file/file.mjs +46 -40
- package/dist/esm/transpiler/file/file.mjs.map +1 -1
- package/dist/esm/transpiler/file/fileBrowser.mjs +22 -9
- package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -1
- package/dist/esm/transpiler/file/index.mjs +3 -2
- package/dist/esm/transpiler/gender/gender.mjs +23 -7
- package/dist/esm/transpiler/gender/gender.mjs.map +1 -1
- package/dist/esm/transpiler/gender/index.mjs +3 -2
- package/dist/esm/transpiler/index.mjs +11 -8
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs +7 -7
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/index.mjs +4 -3
- package/dist/esm/transpiler/insertion/insertion.mjs +31 -29
- package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs +52 -61
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/index.mjs +4 -3
- package/dist/esm/transpiler/markdown/markdown.mjs +29 -29
- package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
- package/dist/esm/transpiler/nesting/index.mjs +3 -2
- package/dist/esm/transpiler/nesting/nesting.mjs +23 -9
- package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
- package/dist/esm/transpiler/translation/index.mjs +3 -2
- package/dist/esm/transpiler/translation/translation.mjs +26 -7
- package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
- package/dist/esm/utils/checkIsURLAbsolute.mjs +4 -3
- package/dist/esm/utils/checkIsURLAbsolute.mjs.map +1 -1
- package/dist/esm/utils/intl.mjs +44 -49
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/esm/utils/isSameKeyPath.mjs +5 -6
- package/dist/esm/utils/isSameKeyPath.mjs.map +1 -1
- package/dist/esm/utils/isValidReactElement.mjs +11 -3
- package/dist/esm/utils/isValidReactElement.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs +139 -0
- package/dist/esm/utils/localeStorage.mjs.map +1 -0
- package/dist/esm/utils/parseYaml.mjs +184 -31
- package/dist/esm/utils/parseYaml.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +46 -0
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -0
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +38 -0
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -0
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +30 -0
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -0
- package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts +18 -0
- package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts.map +1 -0
- package/dist/types/deepTransformPlugins/getMaskContent.d.ts +10 -0
- package/dist/types/deepTransformPlugins/getMaskContent.d.ts.map +1 -0
- package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts +16 -0
- package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts.map +1 -0
- package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts +8 -0
- package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts.map +1 -0
- package/dist/types/deepTransformPlugins/index.d.ts +9 -0
- package/dist/types/deepTransformPlugins/insertContentInDictionary.d.ts +25 -0
- package/dist/types/deepTransformPlugins/insertContentInDictionary.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts +6 -3
- package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts +6 -3
- package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +6 -3
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getEmptyNode.d.ts +6 -2
- package/dist/types/dictionaryManipulator/getEmptyNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts +6 -2
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeType.d.ts +6 -3
- package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getUnmergedDictionaryByKeyPath.d.ts +8 -3
- package/dist/types/dictionaryManipulator/getUnmergedDictionaryByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/index.d.ts +14 -11
- package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts +7 -0
- package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/normalizeDictionary.d.ts +8 -0
- package/dist/types/dictionaryManipulator/normalizeDictionary.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +16 -0
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts +6 -3
- package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts +6 -3
- package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts +6 -2
- package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts.map +1 -1
- package/dist/types/formatters/compact.d.ts +8 -3
- package/dist/types/formatters/compact.d.ts.map +1 -1
- package/dist/types/formatters/currency.d.ts +8 -3
- package/dist/types/formatters/currency.d.ts.map +1 -1
- package/dist/types/formatters/date.d.ts +8 -3
- package/dist/types/formatters/date.d.ts.map +1 -1
- package/dist/types/formatters/index.d.ts +9 -9
- package/dist/types/formatters/list.d.ts +8 -3
- package/dist/types/formatters/list.d.ts.map +1 -1
- package/dist/types/formatters/number.d.ts +8 -3
- package/dist/types/formatters/number.d.ts.map +1 -1
- package/dist/types/formatters/percentage.d.ts +8 -3
- package/dist/types/formatters/percentage.d.ts.map +1 -1
- package/dist/types/formatters/relativeTime.d.ts +8 -5
- package/dist/types/formatters/relativeTime.d.ts.map +1 -1
- package/dist/types/formatters/units.d.ts +8 -3
- package/dist/types/formatters/units.d.ts.map +1 -1
- package/dist/types/getStorageAttributes.d.ts +25 -0
- package/dist/types/getStorageAttributes.d.ts.map +1 -0
- package/dist/types/index.d.ts +67 -13
- package/dist/types/interpreter/getCondition.d.ts +7 -2
- package/dist/types/interpreter/getCondition.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/deepTransform.d.ts +7 -2
- package/dist/types/interpreter/getContent/deepTransform.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/getContent.d.ts +8 -4
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/index.d.ts +4 -4
- package/dist/types/interpreter/getContent/plugins.d.ts +68 -66
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getDictionary.d.ts +8 -4
- package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
- package/dist/types/interpreter/getEnumeration.d.ts +8 -3
- package/dist/types/interpreter/getEnumeration.d.ts.map +1 -1
- package/dist/types/interpreter/getGender.d.ts +7 -4
- package/dist/types/interpreter/getGender.d.ts.map +1 -1
- package/dist/types/interpreter/getInsertion.d.ts +7 -2
- package/dist/types/interpreter/getInsertion.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts +7 -5
- package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
- package/dist/types/interpreter/getNesting.d.ts +9 -6
- package/dist/types/interpreter/getNesting.d.ts.map +1 -1
- package/dist/types/interpreter/getTranslation.d.ts +7 -3
- package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
- package/dist/types/interpreter/index.d.ts +10 -10
- package/dist/types/localization/getBrowserLocale.d.ts +35 -0
- package/dist/types/localization/getBrowserLocale.d.ts.map +1 -0
- package/dist/types/localization/getHTMLTextDir.d.ts +6 -3
- package/dist/types/localization/getHTMLTextDir.d.ts.map +1 -1
- package/dist/types/localization/getLocaleFromPath.d.ts +7 -2
- package/dist/types/localization/getLocaleFromPath.d.ts.map +1 -1
- package/dist/types/localization/getLocaleLang.d.ts +7 -2
- package/dist/types/localization/getLocaleLang.d.ts.map +1 -1
- package/dist/types/localization/getLocaleName.d.ts +6 -2
- package/dist/types/localization/getLocaleName.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts +30 -17
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/localization/getMultilingualUrls.d.ts +28 -12
- package/dist/types/localization/getMultilingualUrls.d.ts.map +1 -1
- package/dist/types/localization/getPathWithoutLocale.d.ts +11 -3
- package/dist/types/localization/getPathWithoutLocale.d.ts.map +1 -1
- package/dist/types/localization/index.d.ts +12 -12
- package/dist/types/localization/localeDetector.d.ts +7 -2
- package/dist/types/localization/localeDetector.d.ts.map +1 -1
- package/dist/types/localization/localeMapper.d.ts +23 -19
- package/dist/types/localization/localeMapper.d.ts.map +1 -1
- package/dist/types/localization/localeResolver.d.ts +7 -2
- package/dist/types/localization/localeResolver.d.ts.map +1 -1
- package/dist/types/transpiler/condition/condition.d.ts +8 -5
- package/dist/types/transpiler/condition/condition.d.ts.map +1 -1
- package/dist/types/transpiler/condition/index.d.ts +2 -2
- package/dist/types/transpiler/enumeration/enumeration.d.ts +9 -6
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/index.d.ts +2 -2
- package/dist/types/transpiler/file/file.d.ts +11 -6
- package/dist/types/transpiler/file/file.d.ts.map +1 -1
- package/dist/types/transpiler/file/fileBrowser.d.ts +7 -2
- package/dist/types/transpiler/file/fileBrowser.d.ts.map +1 -1
- package/dist/types/transpiler/file/index.d.ts +2 -2
- package/dist/types/transpiler/gender/gender.d.ts +9 -6
- package/dist/types/transpiler/gender/gender.d.ts.map +1 -1
- package/dist/types/transpiler/gender/index.d.ts +2 -2
- package/dist/types/transpiler/index.d.ts +11 -9
- package/dist/types/transpiler/insertion/getInsertionValues.d.ts +4 -1
- package/dist/types/transpiler/insertion/getInsertionValues.d.ts.map +1 -1
- package/dist/types/transpiler/insertion/index.d.ts +3 -3
- package/dist/types/transpiler/insertion/insertion.d.ts +8 -5
- package/dist/types/transpiler/insertion/insertion.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/getMarkdownMetadata.d.ts +4 -1
- package/dist/types/transpiler/markdown/getMarkdownMetadata.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/index.d.ts +3 -3
- package/dist/types/transpiler/markdown/markdown.d.ts +8 -5
- package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
- package/dist/types/transpiler/nesting/index.d.ts +2 -2
- package/dist/types/transpiler/nesting/nesting.d.ts +24 -25
- package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
- package/dist/types/transpiler/translation/index.d.ts +2 -2
- package/dist/types/transpiler/translation/translation.d.ts +9 -6
- package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
- package/dist/types/utils/checkIsURLAbsolute.d.ts +4 -1
- package/dist/types/utils/checkIsURLAbsolute.d.ts.map +1 -1
- package/dist/types/utils/intl.d.ts +9 -10
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/dist/types/utils/isSameKeyPath.d.ts +6 -2
- package/dist/types/utils/isSameKeyPath.d.ts.map +1 -1
- package/dist/types/utils/isValidReactElement.d.ts +4 -1
- package/dist/types/utils/isValidReactElement.d.ts.map +1 -1
- package/dist/types/utils/localeStorage.d.ts +105 -0
- package/dist/types/utils/localeStorage.d.ts.map +1 -0
- package/dist/types/utils/parseYaml.d.ts +4 -1
- package/dist/types/utils/parseYaml.d.ts.map +1 -1
- package/package.json +36 -121
- package/LICENSE +0 -202
- package/dist/cjs/deepTranformPlugins/getFilterTranslationsOnlyContent.cjs +0 -130
- package/dist/cjs/deepTranformPlugins/getFilterTranslationsOnlyContent.cjs.map +0 -1
- package/dist/cjs/deepTranformPlugins/getFilteredLocalesContent.cjs +0 -62
- package/dist/cjs/deepTranformPlugins/getFilteredLocalesContent.cjs.map +0 -1
- package/dist/cjs/deepTranformPlugins/getLocalisedContent.cjs +0 -51
- package/dist/cjs/deepTranformPlugins/getLocalisedContent.cjs.map +0 -1
- package/dist/cjs/deepTranformPlugins/getMaskContent.cjs +0 -49
- package/dist/cjs/deepTranformPlugins/getMaskContent.cjs.map +0 -1
- package/dist/cjs/deepTranformPlugins/getMissingLocalesContent.cjs +0 -78
- package/dist/cjs/deepTranformPlugins/getMissingLocalesContent.cjs.map +0 -1
- package/dist/cjs/deepTranformPlugins/getReplacedValuesContent.cjs +0 -82
- package/dist/cjs/deepTranformPlugins/getReplacedValuesContent.cjs.map +0 -1
- package/dist/cjs/deepTranformPlugins/index.cjs +0 -33
- package/dist/cjs/deepTranformPlugins/index.cjs.map +0 -1
- package/dist/cjs/dictionaryManipulator/index.cjs.map +0 -1
- package/dist/cjs/formatters/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/interpreter/getContent/index.cjs.map +0 -1
- package/dist/cjs/interpreter/getIntlayerAsync.cjs +0 -37
- package/dist/cjs/interpreter/getIntlayerAsync.cjs.map +0 -1
- package/dist/cjs/interpreter/index.cjs.map +0 -1
- package/dist/cjs/localization/index.cjs.map +0 -1
- package/dist/cjs/localization/localeList.cjs +0 -256
- package/dist/cjs/localization/localeList.cjs.map +0 -1
- package/dist/cjs/transpiler/condition/index.cjs.map +0 -1
- package/dist/cjs/transpiler/enumeration/index.cjs.map +0 -1
- package/dist/cjs/transpiler/file/index.cjs.map +0 -1
- package/dist/cjs/transpiler/gender/index.cjs.map +0 -1
- package/dist/cjs/transpiler/index.cjs.map +0 -1
- package/dist/cjs/transpiler/insertion/index.cjs.map +0 -1
- package/dist/cjs/transpiler/markdown/index.cjs.map +0 -1
- package/dist/cjs/transpiler/nesting/index.cjs.map +0 -1
- package/dist/cjs/transpiler/translation/index.cjs.map +0 -1
- package/dist/cjs/types/dictionary.cjs +0 -17
- package/dist/cjs/types/dictionary.cjs.map +0 -1
- package/dist/cjs/types/index.cjs +0 -29
- package/dist/cjs/types/index.cjs.map +0 -1
- package/dist/cjs/types/intlayer.cjs +0 -35
- package/dist/cjs/types/intlayer.cjs.map +0 -1
- package/dist/cjs/types/keyPath.cjs +0 -17
- package/dist/cjs/types/keyPath.cjs.map +0 -1
- package/dist/cjs/types/nodeType.cjs +0 -53
- package/dist/cjs/types/nodeType.cjs.map +0 -1
- package/dist/cjs/types/translation.cjs +0 -17
- package/dist/cjs/types/translation.cjs.map +0 -1
- package/dist/esm/deepTranformPlugins/getFilterTranslationsOnlyContent.mjs +0 -95
- package/dist/esm/deepTranformPlugins/getFilterTranslationsOnlyContent.mjs.map +0 -1
- package/dist/esm/deepTranformPlugins/getFilteredLocalesContent.mjs +0 -40
- package/dist/esm/deepTranformPlugins/getFilteredLocalesContent.mjs.map +0 -1
- package/dist/esm/deepTranformPlugins/getLocalisedContent.mjs +0 -19
- package/dist/esm/deepTranformPlugins/getLocalisedContent.mjs.map +0 -1
- package/dist/esm/deepTranformPlugins/getMaskContent.mjs +0 -24
- package/dist/esm/deepTranformPlugins/getMaskContent.mjs.map +0 -1
- package/dist/esm/deepTranformPlugins/getMissingLocalesContent.mjs +0 -43
- package/dist/esm/deepTranformPlugins/getMissingLocalesContent.mjs.map +0 -1
- package/dist/esm/deepTranformPlugins/getReplacedValuesContent.mjs +0 -60
- package/dist/esm/deepTranformPlugins/getReplacedValuesContent.mjs.map +0 -1
- package/dist/esm/deepTranformPlugins/index.mjs +0 -7
- package/dist/esm/deepTranformPlugins/index.mjs.map +0 -1
- package/dist/esm/dictionaryManipulator/index.mjs.map +0 -1
- package/dist/esm/formatters/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/interpreter/getContent/index.mjs.map +0 -1
- package/dist/esm/interpreter/getIntlayerAsync.mjs +0 -13
- package/dist/esm/interpreter/getIntlayerAsync.mjs.map +0 -1
- package/dist/esm/interpreter/index.mjs.map +0 -1
- package/dist/esm/localization/index.mjs.map +0 -1
- package/dist/esm/localization/localeList.mjs +0 -232
- package/dist/esm/localization/localeList.mjs.map +0 -1
- package/dist/esm/transpiler/condition/index.mjs.map +0 -1
- package/dist/esm/transpiler/enumeration/index.mjs.map +0 -1
- package/dist/esm/transpiler/file/index.mjs.map +0 -1
- package/dist/esm/transpiler/gender/index.mjs.map +0 -1
- package/dist/esm/transpiler/index.mjs.map +0 -1
- package/dist/esm/transpiler/insertion/index.mjs.map +0 -1
- package/dist/esm/transpiler/markdown/index.mjs.map +0 -1
- package/dist/esm/transpiler/nesting/index.mjs.map +0 -1
- package/dist/esm/transpiler/translation/index.mjs.map +0 -1
- package/dist/esm/types/dictionary.mjs +0 -1
- package/dist/esm/types/dictionary.mjs.map +0 -1
- package/dist/esm/types/index.mjs +0 -5
- package/dist/esm/types/index.mjs.map +0 -1
- package/dist/esm/types/intlayer.mjs +0 -13
- package/dist/esm/types/intlayer.mjs.map +0 -1
- package/dist/esm/types/keyPath.mjs +0 -1
- package/dist/esm/types/keyPath.mjs.map +0 -1
- package/dist/esm/types/nodeType.mjs +0 -28
- package/dist/esm/types/nodeType.mjs.map +0 -1
- package/dist/esm/types/translation.mjs +0 -1
- package/dist/esm/types/translation.mjs.map +0 -1
- package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.d.ts +0 -13
- package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.d.ts.map +0 -1
- package/dist/types/deepTranformPlugins/getFilteredLocalesContent.d.ts +0 -5
- package/dist/types/deepTranformPlugins/getFilteredLocalesContent.d.ts.map +0 -1
- package/dist/types/deepTranformPlugins/getLocalisedContent.d.ts +0 -13
- package/dist/types/deepTranformPlugins/getLocalisedContent.d.ts.map +0 -1
- package/dist/types/deepTranformPlugins/getMaskContent.d.ts +0 -6
- package/dist/types/deepTranformPlugins/getMaskContent.d.ts.map +0 -1
- package/dist/types/deepTranformPlugins/getMissingLocalesContent.d.ts +0 -13
- package/dist/types/deepTranformPlugins/getMissingLocalesContent.d.ts.map +0 -1
- package/dist/types/deepTranformPlugins/getReplacedValuesContent.d.ts +0 -4
- package/dist/types/deepTranformPlugins/getReplacedValuesContent.d.ts.map +0 -1
- package/dist/types/deepTranformPlugins/index.d.ts +0 -7
- package/dist/types/deepTranformPlugins/index.d.ts.map +0 -1
- package/dist/types/dictionaryManipulator/index.d.ts.map +0 -1
- package/dist/types/formatters/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/interpreter/getContent/index.d.ts.map +0 -1
- package/dist/types/interpreter/getIntlayerAsync.d.ts +0 -13
- package/dist/types/interpreter/getIntlayerAsync.d.ts.map +0 -1
- package/dist/types/interpreter/index.d.ts.map +0 -1
- package/dist/types/localization/index.d.ts.map +0 -1
- package/dist/types/localization/localeList.d.ts +0 -3
- package/dist/types/localization/localeList.d.ts.map +0 -1
- package/dist/types/transpiler/condition/index.d.ts.map +0 -1
- package/dist/types/transpiler/enumeration/index.d.ts.map +0 -1
- package/dist/types/transpiler/file/index.d.ts.map +0 -1
- package/dist/types/transpiler/gender/index.d.ts.map +0 -1
- package/dist/types/transpiler/index.d.ts.map +0 -1
- package/dist/types/transpiler/insertion/index.d.ts.map +0 -1
- package/dist/types/transpiler/markdown/index.d.ts.map +0 -1
- package/dist/types/transpiler/nesting/index.d.ts.map +0 -1
- package/dist/types/transpiler/translation/index.d.ts.map +0 -1
- package/dist/types/types/dictionary.d.ts +0 -307
- package/dist/types/types/dictionary.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -5
- package/dist/types/types/index.d.ts.map +0 -1
- package/dist/types/types/intlayer.d.ts +0 -5
- package/dist/types/types/intlayer.d.ts.map +0 -1
- package/dist/types/types/keyPath.d.ts +0 -47
- package/dist/types/types/keyPath.d.ts.map +0 -1
- package/dist/types/types/nodeType.d.ts +0 -30
- package/dist/types/types/nodeType.d.ts.map +0 -1
- package/dist/types/types/translation.d.ts +0 -25
- package/dist/types/types/translation.d.ts.map +0 -1
|
@@ -1,15 +1,46 @@
|
|
|
1
|
-
import configuration from "@intlayer/config/built";
|
|
2
1
|
import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import configuration from "@intlayer/config/built";
|
|
3
|
+
|
|
4
|
+
//#region src/localization/getLocalizedUrl.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generate URL by prefixing the given URL with the referenced locale or adding search parameters
|
|
7
|
+
* based on the routing mode. Handles both absolute and relative URLs appropriately.
|
|
8
|
+
*
|
|
9
|
+
* This function gets the locales, default locale, and routing mode from the configuration if not provided.
|
|
10
|
+
*
|
|
11
|
+
* Example:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* // prefix-no-default mode
|
|
15
|
+
* getLocalizedUrl('/about', 'fr', ['en', 'fr'], 'en', 'prefix-no-default');
|
|
16
|
+
* // Returns '/fr/about' for the French locale
|
|
17
|
+
* // Returns '/about' for the English locale (default)
|
|
18
|
+
*
|
|
19
|
+
* // prefix-all mode
|
|
20
|
+
* getLocalizedUrl('/about', 'en', ['en', 'fr'], 'en', 'prefix-all');
|
|
21
|
+
* // Returns '/en/about' for the English locale
|
|
22
|
+
* // Returns '/fr/about' for the French locale
|
|
23
|
+
*
|
|
24
|
+
* // search-params mode
|
|
25
|
+
* getLocalizedUrl('/about', 'fr', ['en', 'fr'], 'en', 'search-params');
|
|
26
|
+
* // Returns '/about?locale=fr' for the French locale
|
|
27
|
+
*
|
|
28
|
+
* // no-prefix mode
|
|
29
|
+
* getLocalizedUrl('/about', 'fr', ['en', 'fr'], 'en', 'no-prefix');
|
|
30
|
+
* // Returns '/about' for any locale
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param url - The original URL string to be processed.
|
|
34
|
+
* @param currentLocale - The current locale.
|
|
35
|
+
* @param locales - Optional array of supported locales. Defaults to configured locales.
|
|
36
|
+
* @param defaultLocale - The default locale. Defaults to configured default locale.
|
|
37
|
+
* @param mode - URL routing mode for locale handling. Defaults to configured mode.
|
|
38
|
+
* @returns The localized URL for the current locale.
|
|
39
|
+
*/
|
|
40
|
+
const getLocalizedUrl = (url, currentLocale, locales = configuration?.internationalization?.locales, defaultLocale = configuration?.internationalization?.defaultLocale, mode = configuration?.routing?.mode) => {
|
|
41
|
+
return getMultilingualUrls(url, locales, defaultLocale, mode)[currentLocale] ?? url;
|
|
14
42
|
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { getLocalizedUrl };
|
|
15
46
|
//# sourceMappingURL=getLocalizedUrl.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"getLocalizedUrl.mjs","names":[],"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\n\nimport { getMultilingualUrls } from './getMultilingualUrls';\n\n/**\n * Generate URL by prefixing the given URL with the referenced locale or adding search parameters\n * based on the routing mode. Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getLocalizedUrl('/about', 'fr', ['en', 'fr'], 'en', 'prefix-no-default');\n * // Returns '/fr/about' for the French locale\n * // Returns '/about' for the English locale (default)\n *\n * // prefix-all mode\n * getLocalizedUrl('/about', 'en', ['en', 'fr'], 'en', 'prefix-all');\n * // Returns '/en/about' for the English locale\n * // Returns '/fr/about' for the French locale\n *\n * // search-params mode\n * getLocalizedUrl('/about', 'fr', ['en', 'fr'], 'en', 'search-params');\n * // Returns '/about?locale=fr' for the French locale\n *\n * // no-prefix mode\n * getLocalizedUrl('/about', 'fr', ['en', 'fr'], 'en', 'no-prefix');\n * // Returns '/about' for any locale\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param currentLocale - The current locale.\n * @param locales - Optional array of supported locales. Defaults to configured locales.\n * @param defaultLocale - The default locale. Defaults to configured default locale.\n * @param mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns The localized URL for the current locale.\n */\nexport const getLocalizedUrl = (\n url: string,\n currentLocale: LocalesValues,\n locales: LocalesValues[] | undefined = configuration?.internationalization\n ?.locales,\n defaultLocale: LocalesValues | undefined = configuration?.internationalization\n ?.defaultLocale,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params'\n | undefined = configuration?.routing?.mode\n): string => {\n // Get all multilingual URLs\n const urlWithoutLocale = getMultilingualUrls(\n url,\n locales,\n defaultLocale,\n mode\n );\n\n return (\n urlWithoutLocale[\n currentLocale as unknown as keyof typeof urlWithoutLocale\n ] ?? url\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,mBACX,KACA,eACA,UAAuC,eAAe,sBAClD,SACJ,gBAA2C,eAAe,sBACtD,eACJ,OAKgB,eAAe,SAAS,SAC7B;AASX,QAPyB,oBACvB,KACA,SACA,eACA,KACD,CAIG,kBACG"}
|
|
@@ -1,33 +1,69 @@
|
|
|
1
|
-
import configuration from "@intlayer/config/built";
|
|
2
1
|
import { checkIsURLAbsolute } from "../utils/checkIsURLAbsolute.mjs";
|
|
3
2
|
import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
3
|
+
import configuration from "@intlayer/config/built";
|
|
4
|
+
|
|
5
|
+
//#region src/localization/getMultilingualUrls.ts
|
|
6
|
+
/**
|
|
7
|
+
* Generates multilingual URLs by prefixing the given URL with each supported locale
|
|
8
|
+
* or adding search parameters based on the routing mode.
|
|
9
|
+
* Handles both absolute and relative URLs appropriately.
|
|
10
|
+
*
|
|
11
|
+
* This function gets the locales, default locale, and routing mode from the configuration if not provided.
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* // prefix-no-default mode
|
|
17
|
+
* getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-no-default')
|
|
18
|
+
* // Returns { en: '/dashboard', fr: '/fr/dashboard' }
|
|
19
|
+
*
|
|
20
|
+
* // prefix-all mode
|
|
21
|
+
* getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-all')
|
|
22
|
+
* // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }
|
|
23
|
+
*
|
|
24
|
+
* // search-params mode
|
|
25
|
+
* getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'search-params')
|
|
26
|
+
* // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }
|
|
27
|
+
*
|
|
28
|
+
* // no-prefix mode
|
|
29
|
+
* getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'no-prefix')
|
|
30
|
+
* // Returns { en: '/dashboard', fr: '/dashboard' }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param url - The original URL string to be processed.
|
|
34
|
+
* @param locales - Optional array of supported locales. Defaults to configured locales.
|
|
35
|
+
* @param defaultLocale - The default locale. Defaults to configured default locale.
|
|
36
|
+
* @param mode - URL routing mode for locale handling. Defaults to configured mode.
|
|
37
|
+
* @returns An object mapping each locale to its corresponding multilingual URL.
|
|
38
|
+
*/
|
|
39
|
+
const getMultilingualUrls = (url, locales = configuration?.internationalization?.locales, defaultLocale = configuration?.internationalization?.defaultLocale, mode = configuration?.routing?.mode) => {
|
|
40
|
+
const urlWithoutLocale = getPathWithoutLocale(url, locales);
|
|
41
|
+
const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);
|
|
42
|
+
const parsedUrl = isAbsoluteUrl ? new URL(urlWithoutLocale) : new URL(urlWithoutLocale, "http://example.com");
|
|
43
|
+
let pathname = parsedUrl.pathname;
|
|
44
|
+
if (!pathname.startsWith("/")) pathname = `/${pathname}`;
|
|
45
|
+
const baseUrl = isAbsoluteUrl ? `${parsedUrl.protocol}//${parsedUrl.host}` : "";
|
|
46
|
+
const routingMode = mode ?? "prefix-no-default";
|
|
47
|
+
return (locales ?? []).reduce((acc, locale) => {
|
|
48
|
+
const isDefaultLocale = locale?.toString() === defaultLocale?.toString();
|
|
49
|
+
let localizedUrl;
|
|
50
|
+
if (routingMode === "search-params") {
|
|
51
|
+
const searchParams = new URLSearchParams(parsedUrl.search);
|
|
52
|
+
searchParams.set("locale", locale.toString());
|
|
53
|
+
const queryString = searchParams.toString();
|
|
54
|
+
const pathWithQuery = queryString ? `${pathname}?${queryString}` : pathname;
|
|
55
|
+
localizedUrl = isAbsoluteUrl ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}` : `${pathWithQuery}${parsedUrl.hash}`;
|
|
56
|
+
} else if (routingMode === "no-prefix") localizedUrl = isAbsoluteUrl ? `${baseUrl}${pathname}${parsedUrl.search}${parsedUrl.hash}` : `${pathname}${parsedUrl.search}${parsedUrl.hash}`;
|
|
57
|
+
else {
|
|
58
|
+
let localizedPath = routingMode === "prefix-all" || routingMode === "prefix-no-default" && !isDefaultLocale ? `/${locale}${pathname}` : pathname;
|
|
59
|
+
if (localizedPath.length > 1 && localizedPath.endsWith("/")) localizedPath = localizedPath.slice(0, -1);
|
|
60
|
+
localizedUrl = isAbsoluteUrl ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}` : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;
|
|
61
|
+
}
|
|
62
|
+
acc[locale] = localizedUrl;
|
|
63
|
+
return acc;
|
|
64
|
+
}, {});
|
|
32
65
|
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { getMultilingualUrls };
|
|
33
69
|
//# sourceMappingURL=getMultilingualUrls.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"getMultilingualUrls.mjs","names":["localizedUrl: string"],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale\n * or adding search parameters based on the routing mode.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-no-default')\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n *\n * // prefix-all mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-all')\n * // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }\n *\n * // search-params mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'search-params')\n * // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }\n *\n * // no-prefix mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'no-prefix')\n * // Returns { en: '/dashboard', fr: '/dashboard' }\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param locales - Optional array of supported locales. Defaults to configured locales.\n * @param defaultLocale - The default locale. Defaults to configured default locale.\n * @param mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n locales: LocalesValues[] | undefined = configuration?.internationalization\n ?.locales,\n defaultLocale: LocalesValues | undefined = configuration?.internationalization\n ?.defaultLocale,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params'\n | undefined = configuration?.routing?.mode\n): StrictModeLocaleMap<string> => {\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n // Extract the pathname from the parsed URL\n let pathname = parsedUrl.pathname;\n\n // Ensure the pathname starts with a '/'\n if (!pathname.startsWith('/')) {\n pathname = `/${pathname}`;\n }\n\n // Prepare the base URL (protocol + host) if it's absolute\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Default mode to 'prefix-no-default' if not provided\n const routingMode = mode ?? 'prefix-no-default';\n\n // Generate multilingual URLs by iterating over each locale\n const multilingualUrls = (locales ?? []).reduce<StrictModeLocaleMap<string>>(\n (acc, locale) => {\n // Determine if the current locale is the default locale\n const isDefaultLocale = locale?.toString() === defaultLocale?.toString();\n\n let localizedUrl: string;\n\n if (routingMode === 'search-params') {\n // Use search parameters for locale handling\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', locale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${pathname}?${queryString}`\n : pathname;\n\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}`\n : `${pathWithQuery}${parsedUrl.hash}`;\n } else if (routingMode === 'no-prefix') {\n // No locale prefixing\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathname}${parsedUrl.search}${parsedUrl.hash}`\n : `${pathname}${parsedUrl.search}${parsedUrl.hash}`;\n } else {\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n routingMode === 'prefix-all' ||\n (routingMode === 'prefix-no-default' && !isDefaultLocale);\n\n // Construct the new pathname with or without the locale prefix\n let localizedPath = shouldPrefix ? `/${locale}${pathname}` : pathname;\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n // Combine with the base URL if the original URL was absolute\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n }\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as StrictModeLocaleMap<string>\n );\n\n return multilingualUrls;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,uBACX,KACA,UAAuC,eAAe,sBAClD,SACJ,gBAA2C,eAAe,sBACtD,eACJ,OAKgB,eAAe,SAAS,SACR;CAEhC,MAAM,mBAAmB,qBAAqB,KAAK,QAAQ;CAG3D,MAAM,gBAAgB,mBAAmB,iBAAiB;CAI1D,MAAM,YAAY,gBACd,IAAI,IAAI,iBAAiB,GACzB,IAAI,IAAI,kBAAkB,qBAAqB;CAGnD,IAAI,WAAW,UAAU;AAGzB,KAAI,CAAC,SAAS,WAAW,IAAI,CAC3B,YAAW,IAAI;CAIjB,MAAM,UAAU,gBACZ,GAAG,UAAU,SAAS,IAAI,UAAU,SACpC;CAGJ,MAAM,cAAc,QAAQ;AAuD5B,SApD0B,WAAW,EAAE,EAAE,QACtC,KAAK,WAAW;EAEf,MAAM,kBAAkB,QAAQ,UAAU,KAAK,eAAe,UAAU;EAExE,IAAIA;AAEJ,MAAI,gBAAgB,iBAAiB;GAEnC,MAAM,eAAe,IAAI,gBAAgB,UAAU,OAAO;AAC1D,gBAAa,IAAI,UAAU,OAAO,UAAU,CAAC;GAE7C,MAAM,cAAc,aAAa,UAAU;GAC3C,MAAM,gBAAgB,cAClB,GAAG,SAAS,GAAG,gBACf;AAEJ,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SACvC,GAAG,gBAAgB,UAAU;aACxB,gBAAgB,YAEzB,gBAAe,gBACX,GAAG,UAAU,WAAW,UAAU,SAAS,UAAU,SACrD,GAAG,WAAW,UAAU,SAAS,UAAU;OAC1C;GAOL,IAAI,gBAJF,gBAAgB,gBACf,gBAAgB,uBAAuB,CAAC,kBAGR,IAAI,SAAS,aAAa;AAE7D,OAAI,cAAc,SAAS,KAAK,cAAc,SAAS,IAAI,CACzD,iBAAgB,cAAc,MAAM,GAAG,GAAG;AAI5C,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SAAS,UAAU,SAC1D,GAAG,gBAAgB,UAAU,SAAS,UAAU;;AAItD,MAAI,UAAyC;AAE7C,SAAO;IAET,EAAE,CACH"}
|
|
@@ -1,29 +1,53 @@
|
|
|
1
|
-
import configuration from "@intlayer/config/built";
|
|
2
1
|
import { checkIsURLAbsolute } from "../utils/checkIsURLAbsolute.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
2
|
+
import configuration from "@intlayer/config/built";
|
|
3
|
+
|
|
4
|
+
//#region src/localization/getPathWithoutLocale.ts
|
|
5
|
+
/**
|
|
6
|
+
* Removes the locale segment from the given URL or pathname if present.
|
|
7
|
+
* Also removes locale from search parameters if present.
|
|
8
|
+
*
|
|
9
|
+
* This function get the locales from the configuration if not provided.
|
|
10
|
+
*
|
|
11
|
+
* Example:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'
|
|
15
|
+
* getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'
|
|
16
|
+
* getPathWithoutLocale('/dashboard') // Returns '/dashboard'
|
|
17
|
+
* getPathWithoutLocale('dashboard') // Returns 'dashboard'
|
|
18
|
+
* getPathWithoutLocale('/dashboard?locale=fr') // Returns '/dashboard'
|
|
19
|
+
* getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'
|
|
20
|
+
* getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'
|
|
21
|
+
* getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'
|
|
22
|
+
* getPathWithoutLocale('https://example.com/dashboard?locale=fr') // Returns 'https://example.com/dashboard'
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param inputUrl - The complete URL string or pathname to process.
|
|
26
|
+
* @param locales - Optional array of supported locales. Defaults to `localesDefault`.
|
|
27
|
+
* @returns The URL string or pathname without the locale segment or locale search parameter.
|
|
28
|
+
*/
|
|
29
|
+
const getPathWithoutLocale = (inputUrl, locales = configuration?.internationalization?.locales) => {
|
|
30
|
+
const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);
|
|
31
|
+
let fixedInputUrl = inputUrl;
|
|
32
|
+
if (inputUrl.endsWith("/")) fixedInputUrl = inputUrl.slice(0, -1);
|
|
33
|
+
const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
|
|
34
|
+
const pathname = url.pathname;
|
|
35
|
+
if (!pathname.startsWith("/")) url.pathname = `/${pathname}`;
|
|
36
|
+
const pathSegments = pathname.split("/");
|
|
37
|
+
const firstSegment = pathSegments[1];
|
|
38
|
+
if (locales?.includes(firstSegment)) {
|
|
39
|
+
pathSegments.splice(1, 1);
|
|
40
|
+
url.pathname = pathSegments.join("/") ?? "/";
|
|
41
|
+
}
|
|
42
|
+
const searchParams = new URLSearchParams(url.search);
|
|
43
|
+
if (searchParams.has("locale")) {
|
|
44
|
+
searchParams.delete("locale");
|
|
45
|
+
url.search = searchParams.toString();
|
|
46
|
+
}
|
|
47
|
+
if (isAbsoluteUrl) return url.toString();
|
|
48
|
+
return url.toString().replace("http://example.com", "");
|
|
28
49
|
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { getPathWithoutLocale };
|
|
29
53
|
//# sourceMappingURL=getPathWithoutLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport
|
|
1
|
+
{"version":3,"file":"getPathWithoutLocale.mjs","names":[],"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n * Also removes locale from search parameters if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('/dashboard?locale=fr') // Returns '/dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard?locale=fr') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment or locale search parameter.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales?.includes(firstSegment as LocalesValues)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n // Remove locale from search parameters if present\n const searchParams = new URLSearchParams(url.search);\n if (searchParams.has('locale')) {\n searchParams.delete('locale');\n url.search = searchParams.toString();\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,wBACX,UACA,UAA2B,eAAe,sBAAsB,YACrD;CAEX,MAAM,gBAAgB,mBAAmB,SAAS;CAElD,IAAI,gBAAgB;AAEpB,KAAI,SAAS,SAAS,IAAI,CACxB,iBAAgB,SAAS,MAAM,GAAG,GAAG;CAKvC,MAAM,MAAM,gBACR,IAAI,IAAI,cAAc,GACtB,IAAI,IAAI,eAAe,qBAAqB;CAEhD,MAAM,WAAW,IAAI;AAGrB,KAAI,CAAC,SAAS,WAAW,IAAI,CAE3B,KAAI,WAAW,IAAI;CAIrB,MAAM,eAAe,SAAS,MAAM,IAAI;CACxC,MAAM,eAAe,aAAa;AAGlC,KAAI,SAAS,SAAS,aAA8B,EAAE;AAEpD,eAAa,OAAO,GAAG,EAAE;AAIzB,MAAI,WADgB,aAAa,KAAK,IAAI,IAAI;;CAKhD,MAAM,eAAe,IAAI,gBAAgB,IAAI,OAAO;AACpD,KAAI,aAAa,IAAI,SAAS,EAAE;AAC9B,eAAa,OAAO,SAAS;AAC7B,MAAI,SAAS,aAAa,UAAU;;AAGtC,KAAI,cAEF,QAAO,IAAI,UAAU;AAIvB,QAAO,IAAI,UAAU,CAAC,QAAQ,sBAAsB,GAAG"}
|
|
@@ -1,27 +1,13 @@
|
|
|
1
|
+
import { localeResolver } from "./localeResolver.mjs";
|
|
2
|
+
import { localeDetector } from "./localeDetector.mjs";
|
|
3
|
+
import { getBrowserLocale, localeStorageOptions } from "./getBrowserLocale.mjs";
|
|
1
4
|
import { getHTMLTextDir } from "./getHTMLTextDir.mjs";
|
|
2
5
|
import { getLocaleFromPath } from "./getLocaleFromPath.mjs";
|
|
3
6
|
import { getLocaleLang } from "./getLocaleLang.mjs";
|
|
4
7
|
import { getLocaleName } from "./getLocaleName.mjs";
|
|
5
|
-
import { getLocalizedUrl } from "./getLocalizedUrl.mjs";
|
|
6
|
-
import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
|
|
7
8
|
import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
9
|
+
import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
|
|
10
|
+
import { getLocalizedUrl } from "./getLocalizedUrl.mjs";
|
|
10
11
|
import { localeFlatMap, localeMap, localeRecord } from "./localeMapper.mjs";
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
getHTMLTextDir,
|
|
14
|
-
getLocaleFromPath,
|
|
15
|
-
getLocaleLang,
|
|
16
|
-
getLocaleName,
|
|
17
|
-
getLocalizedUrl,
|
|
18
|
-
getMultilingualUrls,
|
|
19
|
-
getPathWithoutLocale,
|
|
20
|
-
localeDetector,
|
|
21
|
-
localeFlatMap,
|
|
22
|
-
localeList,
|
|
23
|
-
localeMap,
|
|
24
|
-
localeRecord,
|
|
25
|
-
localeResolver
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=index.mjs.map
|
|
12
|
+
|
|
13
|
+
export { getBrowserLocale, getHTMLTextDir, getLocaleFromPath, getLocaleLang, getLocaleName, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions };
|
|
@@ -1,10 +1,113 @@
|
|
|
1
|
-
import Negotiator from "negotiator";
|
|
2
1
|
import { localeResolver } from "./localeResolver.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/localization/localeDetector.ts
|
|
4
|
+
/**
|
|
5
|
+
* Module variables.
|
|
6
|
+
*/
|
|
7
|
+
const simpleLanguageRegExp = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/;
|
|
8
|
+
/**
|
|
9
|
+
* Parse the Accept-Language header.
|
|
10
|
+
*/
|
|
11
|
+
const parseAcceptLanguage = (accept) => {
|
|
12
|
+
const rawAccepts = accept.split(",");
|
|
13
|
+
const accepts = [];
|
|
14
|
+
for (let i = 0; i < rawAccepts.length; i++) {
|
|
15
|
+
const language = parseLanguage(rawAccepts[i].trim(), i);
|
|
16
|
+
if (language) accepts.push(language);
|
|
17
|
+
}
|
|
18
|
+
return accepts;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Parse a language from the Accept-Language header.
|
|
22
|
+
*/
|
|
23
|
+
const parseLanguage = (str, i) => {
|
|
24
|
+
const match = simpleLanguageRegExp.exec(str);
|
|
25
|
+
if (!match) return null;
|
|
26
|
+
const prefix = match[1];
|
|
27
|
+
const suffix = match[2];
|
|
28
|
+
let full = prefix;
|
|
29
|
+
if (suffix) full = `${prefix}-${suffix}`;
|
|
30
|
+
let q = 1;
|
|
31
|
+
if (match[3]) {
|
|
32
|
+
const params = match[3].split(";");
|
|
33
|
+
for (let j = 0; j < params.length; j++) {
|
|
34
|
+
const p = params[j].split("=");
|
|
35
|
+
if (p[0] === "q") q = parseFloat(p[1]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
prefix,
|
|
40
|
+
suffix,
|
|
41
|
+
q,
|
|
42
|
+
i,
|
|
43
|
+
full
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Get the priority of a language.
|
|
48
|
+
*/
|
|
49
|
+
const getLanguagePriority = (language, accepted, index) => {
|
|
50
|
+
let priority = {
|
|
51
|
+
o: -1,
|
|
52
|
+
q: 0,
|
|
53
|
+
s: 0,
|
|
54
|
+
i: index
|
|
55
|
+
};
|
|
56
|
+
for (let i = 0; i < accepted.length; i++) {
|
|
57
|
+
const spec = specify(language, accepted[i], index);
|
|
58
|
+
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) priority = spec;
|
|
59
|
+
}
|
|
60
|
+
return priority;
|
|
6
61
|
};
|
|
7
|
-
|
|
8
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Get the specificity of the language.
|
|
64
|
+
*/
|
|
65
|
+
const specify = (language, spec, index) => {
|
|
66
|
+
const p = parseLanguage(language, index);
|
|
67
|
+
if (!p) return null;
|
|
68
|
+
let s = 0;
|
|
69
|
+
if (spec.full.toLowerCase() === p.full.toLowerCase()) s |= 4;
|
|
70
|
+
else if (spec.prefix.toLowerCase() === p.full.toLowerCase()) s |= 2;
|
|
71
|
+
else if (spec.full.toLowerCase() === p.prefix.toLowerCase()) s |= 1;
|
|
72
|
+
else if (spec.full !== "*") return null;
|
|
73
|
+
return {
|
|
74
|
+
i: index,
|
|
75
|
+
o: spec.i,
|
|
76
|
+
q: spec.q,
|
|
77
|
+
s
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Get the preferred languages from an Accept-Language header.
|
|
82
|
+
*/
|
|
83
|
+
const preferredLanguages = (accept, provided) => {
|
|
84
|
+
const accepts = parseAcceptLanguage(accept === void 0 ? "*" : accept ?? "");
|
|
85
|
+
if (!provided) return accepts.filter(isQuality).sort(compareSpecs).map(getFullLanguage);
|
|
86
|
+
const priorities = provided.map((type, index) => getLanguagePriority(type, accepts, index));
|
|
87
|
+
return priorities.filter(isQuality).sort(compareSpecs).map((priority) => provided[priorities.indexOf(priority)]);
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Compare two specs.
|
|
91
|
+
*/
|
|
92
|
+
const compareSpecs = (a, b) => b.q - a.q || (b.s ?? 0) - (a.s ?? 0) || (a.o ?? 0) - (b.o ?? 0) || a.i - b.i || 0;
|
|
93
|
+
/**
|
|
94
|
+
* Get full language string.
|
|
95
|
+
*/
|
|
96
|
+
const getFullLanguage = (spec) => spec.full;
|
|
97
|
+
/**
|
|
98
|
+
* Check if a spec has any quality.
|
|
99
|
+
*/
|
|
100
|
+
const isQuality = (spec) => spec.q > 0;
|
|
101
|
+
/**
|
|
102
|
+
* Detects the locale from the request headers
|
|
103
|
+
*
|
|
104
|
+
* Headers are provided by the browser and can be used to determine the user's preferred language
|
|
105
|
+
*/
|
|
106
|
+
const localeDetector = (headers, locales, defaultLocale) => {
|
|
107
|
+
const accept = headers["accept-language"];
|
|
108
|
+
return localeResolver(preferredLanguages(accept), locales, defaultLocale);
|
|
9
109
|
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { localeDetector };
|
|
10
113
|
//# sourceMappingURL=localeDetector.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"localeDetector.mjs","names":["accepts: LanguageSpec[]","priority: PrioritySpec"],"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Module variables.\n */\nconst simpleLanguageRegExp = /^\\s*([^\\s\\-;]+)(?:-([^\\s;]+))?\\s*(?:;(.*))?$/;\n\ntype LanguageSpec = {\n prefix: string;\n suffix?: string;\n q: number;\n i: number;\n full: string;\n};\n\ntype PrioritySpec = {\n i: number;\n o: number;\n q: number;\n s: number;\n};\n\ntype ComparableSpec = {\n q: number;\n s?: number;\n o?: number;\n i: number;\n};\n\n/**\n * Parse the Accept-Language header.\n */\nconst parseAcceptLanguage = (accept: string): LanguageSpec[] => {\n const rawAccepts = accept.split(',');\n const accepts: LanguageSpec[] = [];\n\n for (let i = 0; i < rawAccepts.length; i++) {\n const language = parseLanguage(rawAccepts[i].trim(), i);\n if (language) accepts.push(language);\n }\n\n return accepts;\n};\n\n/**\n * Parse a language from the Accept-Language header.\n */\nconst parseLanguage = (str: string, i: number): LanguageSpec | null => {\n const match = simpleLanguageRegExp.exec(str);\n if (!match) return null;\n\n const prefix = match[1];\n const suffix = match[2];\n let full = prefix;\n\n if (suffix) full = `${prefix}-${suffix}`;\n\n let q = 1;\n if (match[3]) {\n const params = match[3].split(';');\n for (let j = 0; j < params.length; j++) {\n const p = params[j].split('=');\n if (p[0] === 'q') q = parseFloat(p[1]);\n }\n }\n\n return {\n prefix,\n suffix,\n q,\n i,\n full,\n };\n};\n\n/**\n * Get the priority of a language.\n */\nconst getLanguagePriority = (\n language: string,\n accepted: LanguageSpec[],\n index: number\n): PrioritySpec => {\n let priority: PrioritySpec = { o: -1, q: 0, s: 0, i: index };\n\n for (let i = 0; i < accepted.length; i++) {\n const spec = specify(language, accepted[i], index);\n if (\n spec &&\n (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0\n ) {\n priority = spec;\n }\n }\n\n return priority;\n};\n\n/**\n * Get the specificity of the language.\n */\nconst specify = (\n language: string,\n spec: LanguageSpec,\n index: number\n): PrioritySpec | null => {\n const p = parseLanguage(language, index);\n if (!p) return null;\n let s = 0;\n if (spec.full.toLowerCase() === p.full.toLowerCase()) {\n s |= 4;\n } else if (spec.prefix.toLowerCase() === p.full.toLowerCase()) {\n s |= 2;\n } else if (spec.full.toLowerCase() === p.prefix.toLowerCase()) {\n s |= 1;\n } else if (spec.full !== '*') {\n return null;\n }\n\n return {\n i: index,\n o: spec.i,\n q: spec.q,\n s,\n };\n};\n\n/**\n * Get the preferred languages from an Accept-Language header.\n */\nconst preferredLanguages = (\n accept: string | undefined,\n provided?: string[]\n): string[] => {\n // RFC 2616 sec 14.4: no header = *\n const accepts = parseAcceptLanguage(\n accept === undefined ? '*' : (accept ?? '')\n );\n\n if (!provided) {\n return accepts.filter(isQuality).sort(compareSpecs).map(getFullLanguage);\n }\n\n const priorities = provided.map((type, index) =>\n getLanguagePriority(type, accepts, index)\n );\n\n return priorities\n .filter(isQuality)\n .sort(compareSpecs)\n .map((priority) => provided[priorities.indexOf(priority)]);\n};\n\n/**\n * Compare two specs.\n */\nconst compareSpecs = (a: ComparableSpec, b: ComparableSpec): number =>\n b.q - a.q ||\n (b.s ?? 0) - (a.s ?? 0) ||\n (a.o ?? 0) - (b.o ?? 0) ||\n a.i - b.i ||\n 0;\n\n/**\n * Get full language string.\n */\nconst getFullLanguage = (spec: LanguageSpec): string => spec.full;\n\n/**\n * Check if a spec has any quality.\n */\nconst isQuality = (spec: { q: number }): boolean => spec.q > 0;\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n locales?: Locale[],\n defaultLocale?: Locale\n): Locale => {\n const accept = headers['accept-language'];\n const languages = preferredLanguages(accept);\n\n return localeResolver(languages as Locale[], locales, defaultLocale);\n};\n"],"mappings":";;;;;;AAMA,MAAM,uBAAuB;;;;AA2B7B,MAAM,uBAAuB,WAAmC;CAC9D,MAAM,aAAa,OAAO,MAAM,IAAI;CACpC,MAAMA,UAA0B,EAAE;AAElC,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC1C,MAAM,WAAW,cAAc,WAAW,GAAG,MAAM,EAAE,EAAE;AACvD,MAAI,SAAU,SAAQ,KAAK,SAAS;;AAGtC,QAAO;;;;;AAMT,MAAM,iBAAiB,KAAa,MAAmC;CACrE,MAAM,QAAQ,qBAAqB,KAAK,IAAI;AAC5C,KAAI,CAAC,MAAO,QAAO;CAEnB,MAAM,SAAS,MAAM;CACrB,MAAM,SAAS,MAAM;CACrB,IAAI,OAAO;AAEX,KAAI,OAAQ,QAAO,GAAG,OAAO,GAAG;CAEhC,IAAI,IAAI;AACR,KAAI,MAAM,IAAI;EACZ,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI;AAClC,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;GACtC,MAAM,IAAI,OAAO,GAAG,MAAM,IAAI;AAC9B,OAAI,EAAE,OAAO,IAAK,KAAI,WAAW,EAAE,GAAG;;;AAI1C,QAAO;EACL;EACA;EACA;EACA;EACA;EACD;;;;;AAMH,MAAM,uBACJ,UACA,UACA,UACiB;CACjB,IAAIC,WAAyB;EAAE,GAAG;EAAI,GAAG;EAAG,GAAG;EAAG,GAAG;EAAO;AAE5D,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,MAAM,OAAO,QAAQ,UAAU,SAAS,IAAI,MAAM;AAClD,MACE,SACC,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAEtE,YAAW;;AAIf,QAAO;;;;;AAMT,MAAM,WACJ,UACA,MACA,UACwB;CACxB,MAAM,IAAI,cAAc,UAAU,MAAM;AACxC,KAAI,CAAC,EAAG,QAAO;CACf,IAAI,IAAI;AACR,KAAI,KAAK,KAAK,aAAa,KAAK,EAAE,KAAK,aAAa,CAClD,MAAK;UACI,KAAK,OAAO,aAAa,KAAK,EAAE,KAAK,aAAa,CAC3D,MAAK;UACI,KAAK,KAAK,aAAa,KAAK,EAAE,OAAO,aAAa,CAC3D,MAAK;UACI,KAAK,SAAS,IACvB,QAAO;AAGT,QAAO;EACL,GAAG;EACH,GAAG,KAAK;EACR,GAAG,KAAK;EACR;EACD;;;;;AAMH,MAAM,sBACJ,QACA,aACa;CAEb,MAAM,UAAU,oBACd,WAAW,SAAY,MAAO,UAAU,GACzC;AAED,KAAI,CAAC,SACH,QAAO,QAAQ,OAAO,UAAU,CAAC,KAAK,aAAa,CAAC,IAAI,gBAAgB;CAG1E,MAAM,aAAa,SAAS,KAAK,MAAM,UACrC,oBAAoB,MAAM,SAAS,MAAM,CAC1C;AAED,QAAO,WACJ,OAAO,UAAU,CACjB,KAAK,aAAa,CAClB,KAAK,aAAa,SAAS,WAAW,QAAQ,SAAS,EAAE;;;;;AAM9D,MAAM,gBAAgB,GAAmB,MACvC,EAAE,IAAI,EAAE,MACP,EAAE,KAAK,MAAM,EAAE,KAAK,OACpB,EAAE,KAAK,MAAM,EAAE,KAAK,MACrB,EAAE,IAAI,EAAE,KACR;;;;AAKF,MAAM,mBAAmB,SAA+B,KAAK;;;;AAK7D,MAAM,aAAa,SAAiC,KAAK,IAAI;;;;;;AAO7D,MAAa,kBACX,SACA,SACA,kBACW;CACX,MAAM,SAAS,QAAQ;AAGvB,QAAO,eAFW,mBAAmB,OAAO,EAEC,SAAS,cAAc"}
|