@intlayer/core 8.5.1 → 8.6.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/formatters/compact.cjs +1 -1
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs +1 -1
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs +1 -1
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/index.cjs +1 -1
- package/dist/cjs/formatters/list.cjs +1 -1
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs +1 -1
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs +2 -2
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs +1 -1
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs +1 -1
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/index.cjs +16 -9
- package/dist/cjs/interpreter/getContent/getContent.cjs +8 -8
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs +10 -35
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
- package/dist/cjs/localization/generateSitemap.cjs +111 -0
- package/dist/cjs/localization/generateSitemap.cjs.map +1 -0
- package/dist/cjs/localization/getBrowserLocale.cjs +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs +2 -2
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +1 -1
- package/dist/cjs/localization/getPrefix.cjs +1 -1
- package/dist/cjs/localization/index.cjs +8 -7
- package/dist/cjs/localization/localeMapper.cjs +1 -1
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs +2 -3
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +9 -3
- package/dist/cjs/utils/intl.cjs +88 -72
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs +191 -64
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/esm/formatters/compact.mjs +2 -2
- package/dist/esm/formatters/compact.mjs.map +1 -1
- package/dist/esm/formatters/currency.mjs +2 -2
- package/dist/esm/formatters/currency.mjs.map +1 -1
- package/dist/esm/formatters/date.mjs +2 -2
- package/dist/esm/formatters/date.mjs.map +1 -1
- package/dist/esm/formatters/index.mjs +2 -2
- package/dist/esm/formatters/list.mjs +2 -2
- package/dist/esm/formatters/list.mjs.map +1 -1
- package/dist/esm/formatters/number.mjs +2 -2
- package/dist/esm/formatters/number.mjs.map +1 -1
- package/dist/esm/formatters/percentage.mjs +3 -3
- package/dist/esm/formatters/percentage.mjs.map +1 -1
- package/dist/esm/formatters/relativeTime.mjs +2 -2
- package/dist/esm/formatters/relativeTime.mjs.map +1 -1
- package/dist/esm/formatters/units.mjs +2 -2
- package/dist/esm/formatters/units.mjs.map +1 -1
- package/dist/esm/index.mjs +10 -10
- package/dist/esm/interpreter/getContent/getContent.mjs +8 -8
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs +10 -35
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
- package/dist/esm/localization/generateSitemap.mjs +109 -0
- package/dist/esm/localization/generateSitemap.mjs.map +1 -0
- package/dist/esm/localization/getBrowserLocale.mjs +2 -2
- package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs +3 -3
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +1 -1
- package/dist/esm/localization/getPrefix.mjs +1 -1
- package/dist/esm/localization/index.mjs +7 -7
- package/dist/esm/localization/localeMapper.mjs +1 -1
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs +2 -4
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +4 -4
- package/dist/esm/utils/intl.mjs +87 -72
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs +186 -65
- package/dist/esm/utils/localeStorage.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +10 -10
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +10 -10
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +10 -10
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +2 -2
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
- package/dist/types/formatters/index.d.ts +2 -2
- package/dist/types/formatters/number.d.ts +4 -1
- package/dist/types/formatters/number.d.ts.map +1 -1
- package/dist/types/formatters/percentage.d.ts +4 -1
- package/dist/types/formatters/percentage.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/splitAndJoinInsertion.d.ts +0 -17
- package/dist/types/interpreter/splitAndJoinInsertion.d.ts.map +1 -1
- package/dist/types/localization/generateSitemap.d.ts +93 -0
- package/dist/types/localization/generateSitemap.d.ts.map +1 -0
- package/dist/types/localization/getBrowserLocale.d.ts +2 -2
- package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
- package/dist/types/localization/index.d.ts +2 -2
- package/dist/types/transpiler/html/getHTMLCustomComponents.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +3 -3
- package/dist/types/utils/intl.d.ts +15 -11
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/dist/types/utils/localeStorage.d.ts +85 -68
- package/dist/types/utils/localeStorage.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/cjs/getStorageAttributes.cjs +0 -135
- package/dist/cjs/getStorageAttributes.cjs.map +0 -1
- package/dist/esm/getStorageAttributes.mjs +0 -133
- package/dist/esm/getStorageAttributes.mjs.map +0 -1
- package/dist/types/getStorageAttributes.d.ts +0 -29
- package/dist/types/getStorageAttributes.d.ts.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCachedIntl } from "../utils/intl.mjs";
|
|
2
2
|
import configuration from "@intlayer/config/built";
|
|
3
3
|
|
|
4
4
|
//#region src/formatters/units.ts
|
|
@@ -9,7 +9,7 @@ import configuration from "@intlayer/config/built";
|
|
|
9
9
|
* units(5, { unit: "kilometer", unitDisplay: "long", locale: "en-GB" });
|
|
10
10
|
* // "5 kilometers"
|
|
11
11
|
*/
|
|
12
|
-
const units = (value, options) =>
|
|
12
|
+
const units = (value, options) => getCachedIntl(Intl.NumberFormat, options?.locale ?? configuration?.internationalization?.defaultLocale, {
|
|
13
13
|
style: "unit",
|
|
14
14
|
unit: options?.unit ?? "day",
|
|
15
15
|
unitDisplay: options?.unitDisplay ?? "short",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.mjs","names":[],"sources":["../../../src/formatters/units.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport {
|
|
1
|
+
{"version":3,"file":"units.mjs","names":[],"sources":["../../../src/formatters/units.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value as a localized unit string.\n *\n * @example\n * units(5, { unit: \"kilometer\", unitDisplay: \"long\", locale: \"en-GB\" });\n * // \"5 kilometers\"\n */\nexport const units = (\n value: number | string,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n style: 'unit',\n unit: options?.unit ?? 'day',\n unitDisplay: options?.unitDisplay ?? 'short',\n useGrouping: options?.useGrouping ?? false,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,SACX,OACA,YAEA,cACE,KAAK,cACL,SAAS,UAAU,eAAe,sBAAsB,eACxD;CACE,OAAO;CACP,MAAM,SAAS,QAAQ;CACvB,aAAa,SAAS,eAAe;CACrC,aAAa,SAAS,eAAe;CACtC,CACF,CAAC,OAAO,OAAO,MAAM,CAAC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getStorageAttributes } from "./getStorageAttributes.mjs";
|
|
2
1
|
import { getCondition } from "./interpreter/getCondition.mjs";
|
|
3
2
|
import { deepTransformNode } from "./interpreter/getContent/deepTransform.mjs";
|
|
4
3
|
import { findMatchingCondition, getEnumeration } from "./interpreter/getEnumeration.mjs";
|
|
@@ -47,7 +46,7 @@ import { normalizeDictionaries, normalizeDictionary } from "./dictionaryManipula
|
|
|
47
46
|
import { removeContentNodeByKeyPath } from "./dictionaryManipulator/removeContentNodeByKeyPath.mjs";
|
|
48
47
|
import { renameContentNodeByKeyPath } from "./dictionaryManipulator/renameContentNodeByKeyPath.mjs";
|
|
49
48
|
import { updateNodeChildren } from "./dictionaryManipulator/updateNodeChildren.mjs";
|
|
50
|
-
import { CachedIntl, bindIntl,
|
|
49
|
+
import { CachedIntl, bindIntl, getCachedIntl } from "./utils/intl.mjs";
|
|
51
50
|
import { compact } from "./formatters/compact.mjs";
|
|
52
51
|
import { currency } from "./formatters/currency.mjs";
|
|
53
52
|
import { date, presets } from "./formatters/date.mjs";
|
|
@@ -56,22 +55,23 @@ import { number } from "./formatters/number.mjs";
|
|
|
56
55
|
import { percentage } from "./formatters/percentage.mjs";
|
|
57
56
|
import { relativeTime } from "./formatters/relativeTime.mjs";
|
|
58
57
|
import { units } from "./formatters/units.mjs";
|
|
58
|
+
import { checkIsURLAbsolute } from "./utils/checkIsURLAbsolute.mjs";
|
|
59
|
+
import { getPathWithoutLocale } from "./localization/getPathWithoutLocale.mjs";
|
|
60
|
+
import { getPrefix } from "./localization/getPrefix.mjs";
|
|
61
|
+
import { getCanonicalPath, getInternalPath, getLocalizedPath, getRewritePath, getRewriteRules } from "./localization/rewriteUtils.mjs";
|
|
62
|
+
import { getLocalizedUrl } from "./localization/getLocalizedUrl.mjs";
|
|
63
|
+
import { getMultilingualUrls } from "./localization/getMultilingualUrls.mjs";
|
|
64
|
+
import { generateSitemap, generateSitemapUrl } from "./localization/generateSitemap.mjs";
|
|
59
65
|
import { getCookie } from "./utils/getCookie.mjs";
|
|
60
|
-
import { LocaleStorage, getLocaleFromStorage, setLocaleInStorage } from "./utils/localeStorage.mjs";
|
|
66
|
+
import { LocaleStorage, LocaleStorageClient, LocaleStorageServer, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer } from "./utils/localeStorage.mjs";
|
|
61
67
|
import { localeResolver } from "./localization/localeResolver.mjs";
|
|
62
68
|
import { localeDetector } from "./localization/localeDetector.mjs";
|
|
63
69
|
import { getBrowserLocale, localeStorageOptions } from "./localization/getBrowserLocale.mjs";
|
|
64
70
|
import { getHTMLTextDir } from "./localization/getHTMLTextDir.mjs";
|
|
65
71
|
import { getLocale } from "./localization/getLocale.mjs";
|
|
66
|
-
import { checkIsURLAbsolute } from "./utils/checkIsURLAbsolute.mjs";
|
|
67
|
-
import { getPrefix } from "./localization/getPrefix.mjs";
|
|
68
72
|
import { getLocaleFromPath } from "./localization/getLocaleFromPath.mjs";
|
|
69
73
|
import { getLocaleLang } from "./localization/getLocaleLang.mjs";
|
|
70
74
|
import { getLocaleName } from "./localization/getLocaleName.mjs";
|
|
71
|
-
import { getPathWithoutLocale } from "./localization/getPathWithoutLocale.mjs";
|
|
72
|
-
import { getCanonicalPath, getInternalPath, getLocalizedPath, getRewritePath, getRewriteRules } from "./localization/rewriteUtils.mjs";
|
|
73
|
-
import { getLocalizedUrl } from "./localization/getLocalizedUrl.mjs";
|
|
74
|
-
import { getMultilingualUrls } from "./localization/getMultilingualUrls.mjs";
|
|
75
75
|
import { localeFlatMap, localeMap, localeRecord } from "./localization/localeMapper.mjs";
|
|
76
76
|
import { validatePrefix } from "./localization/validatePrefix.mjs";
|
|
77
77
|
import { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex } from "./markdown/constants.mjs";
|
|
@@ -84,4 +84,4 @@ import { i18nextToIntlayerFormatter, intlayerToI18nextFormatter } from "./messag
|
|
|
84
84
|
import { intlayerToVueI18nFormatter, vueI18nToIntlayerFormatter } from "./messageFormat/vue-i18n.mjs";
|
|
85
85
|
import { isSameKeyPath } from "./utils/isSameKeyPath.mjs";
|
|
86
86
|
|
|
87
|
-
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, LocaleStorage, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, VOID_ELEMENTS, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, compile, compileWithOptions, condition as cond, conditionPlugin,
|
|
87
|
+
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, LocaleStorage, LocaleStorageClient, LocaleStorageServer, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, VOID_ELEMENTS, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getHTML, getHTMLTextDir, getInsertionValues, getInternalPath, getIntlayer, getLocale, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSplittedContent, getSplittedDictionaryContent, getTranslation, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToVueI18nFormatter, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseInline, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseYaml, parserFor, percentage, presets, qualifies, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderNothing, sanitizer, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, translation as t, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter };
|
|
@@ -4,14 +4,14 @@ import configuration from "@intlayer/config/built";
|
|
|
4
4
|
|
|
5
5
|
//#region src/interpreter/getContent/getContent.ts
|
|
6
6
|
const getBasePlugins = (locale, fallback = true) => [
|
|
7
|
-
translationPlugin(locale ?? configuration.internationalization.defaultLocale, fallback ? configuration.internationalization.defaultLocale : void 0),
|
|
8
|
-
enumerationPlugin,
|
|
9
|
-
conditionPlugin,
|
|
10
|
-
insertionPlugin,
|
|
11
|
-
nestedPlugin(locale ?? configuration.internationalization.defaultLocale),
|
|
12
|
-
filePlugin,
|
|
13
|
-
genderPlugin
|
|
14
|
-
];
|
|
7
|
+
process.env.INTLAYER_NODE_TYPE_TRANSLATION !== "false" && translationPlugin(locale ?? configuration.internationalization.defaultLocale, fallback ? configuration.internationalization.defaultLocale : void 0),
|
|
8
|
+
process.env.INTLAYER_NODE_TYPE_ENUMERATION !== "false" && enumerationPlugin,
|
|
9
|
+
process.env.INTLAYER_NODE_TYPE_CONDITION !== "false" && conditionPlugin,
|
|
10
|
+
process.env.INTLAYER_NODE_TYPE_INSERTION !== "false" && insertionPlugin,
|
|
11
|
+
process.env.INTLAYER_NODE_TYPE_NESTED !== "false" && nestedPlugin(locale ?? configuration.internationalization.defaultLocale),
|
|
12
|
+
process.env.INTLAYER_NODE_TYPE_FILE !== "false" && filePlugin,
|
|
13
|
+
process.env.INTLAYER_NODE_TYPE_GENDER !== "false" && genderPlugin
|
|
14
|
+
].filter(Boolean);
|
|
15
15
|
/**
|
|
16
16
|
* Transforms a node in a single pass, applying each plugin as needed.
|
|
17
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContent.mjs","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { deepTransformNode } from './deepTransform';\nimport {\n conditionPlugin,\n type DeepTransformContent,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState,\n insertionPlugin,\n type NodeProps,\n nestedPlugin,\n type Plugins,\n translationPlugin,\n} from './plugins';\n\nexport const getBasePlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[]
|
|
1
|
+
{"version":3,"file":"getContent.mjs","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { deepTransformNode } from './deepTransform';\nimport {\n conditionPlugin,\n type DeepTransformContent,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState,\n insertionPlugin,\n type NodeProps,\n nestedPlugin,\n type Plugins,\n translationPlugin,\n} from './plugins';\n\nexport const getBasePlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] =>\n [\n process.env.INTLAYER_NODE_TYPE_TRANSLATION !== 'false' &&\n translationPlugin(\n locale ?? configuration.internationalization.defaultLocale,\n fallback ? configuration.internationalization.defaultLocale : undefined\n ),\n process.env.INTLAYER_NODE_TYPE_ENUMERATION !== 'false' && enumerationPlugin,\n process.env.INTLAYER_NODE_TYPE_CONDITION !== 'false' && conditionPlugin,\n process.env.INTLAYER_NODE_TYPE_INSERTION !== 'false' && insertionPlugin,\n process.env.INTLAYER_NODE_TYPE_NESTED !== 'false' &&\n nestedPlugin(locale ?? configuration.internationalization.defaultLocale),\n process.env.INTLAYER_NODE_TYPE_FILE !== 'false' && filePlugin,\n process.env.INTLAYER_NODE_TYPE_GENDER !== 'false' && genderPlugin,\n ].filter(Boolean) as Plugins[];\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n nodeProps: NodeProps,\n plugins: Plugins[] = []\n) =>\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;AAqBA,MAAa,kBACX,QACA,WAAoB,SAEpB;CACE,QAAQ,IAAI,mCAAmC,WAC7C,kBACE,UAAU,cAAc,qBAAqB,eAC7C,WAAW,cAAc,qBAAqB,gBAAgB,OAC/D;CACH,QAAQ,IAAI,mCAAmC,WAAW;CAC1D,QAAQ,IAAI,iCAAiC,WAAW;CACxD,QAAQ,IAAI,iCAAiC,WAAW;CACxD,QAAQ,IAAI,8BAA8B,WACxC,aAAa,UAAU,cAAc,qBAAqB,cAAc;CAC1E,QAAQ,IAAI,4BAA4B,WAAW;CACnD,QAAQ,IAAI,8BAA8B,WAAW;CACtD,CAAC,OAAO,QAAQ;;;;;;;AAQnB,MAAa,cAIX,MACA,WACA,UAAqB,EAAE,KAEvB,kBAAkB,MAAM;CACtB,GAAG;CACH;CACD,CAAC"}
|
|
@@ -3,46 +3,21 @@
|
|
|
3
3
|
* Check if a value is a complex object (not a primitive)
|
|
4
4
|
* Used to determine if values need to be wrapped in fragments
|
|
5
5
|
*/
|
|
6
|
-
const isComplexValue = (value) =>
|
|
7
|
-
|
|
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
|
-
*/
|
|
6
|
+
const isComplexValue = (value) => value != null && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean";
|
|
7
|
+
const insertionRegex = /\{\{\s*(.*?)\s*\}\}/g;
|
|
26
8
|
const splitInsertionTemplate = (template, values = {}) => {
|
|
27
|
-
|
|
28
|
-
if (!Object.values(safeValues).some(isComplexValue)) return {
|
|
9
|
+
if (!Object.values(values).some(isComplexValue)) return {
|
|
29
10
|
isSimple: true,
|
|
30
|
-
parts: template.replace(
|
|
31
|
-
return (safeValues[key.trim()] ?? "").toString();
|
|
32
|
-
})
|
|
11
|
+
parts: template.replace(insertionRegex, (_, key) => (values[key.trim()] ?? "").toString())
|
|
33
12
|
};
|
|
13
|
+
const chunks = template.split(insertionRegex);
|
|
34
14
|
const parts = [];
|
|
35
|
-
let
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (
|
|
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);
|
|
15
|
+
for (let i = 0; i < chunks.length; i++) if (i % 2 === 0) {
|
|
16
|
+
if (chunks[i]) parts.push(chunks[i]);
|
|
17
|
+
} else {
|
|
18
|
+
const val = values[chunks[i].trim()];
|
|
19
|
+
if (val != null) parts.push(val);
|
|
44
20
|
}
|
|
45
|
-
if (lastIndex < template.length) parts.push(template.substring(lastIndex));
|
|
46
21
|
return {
|
|
47
22
|
isSimple: false,
|
|
48
23
|
parts
|
|
@@ -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
|
|
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 value != null &&\n typeof value !== 'string' &&\n typeof value !== 'number' &&\n typeof value !== 'boolean';\n\n// Hoisted: replace/split do not suffer from the stateful lastIndex mutation of .exec()\nconst insertionRegex = /\\{\\{\\s*(.*?)\\s*\\}\\}/g;\n\nexport const splitInsertionTemplate = <T = any>(\n template: string,\n values: Record<string, T> = {}\n): { isSimple: boolean; parts: string | T[] } => {\n if (!Object.values(values).some(isComplexValue)) {\n return {\n isSimple: true,\n parts: template.replace(insertionRegex, (_, key) =>\n (values[key.trim()] ?? '').toString()\n ),\n };\n }\n\n const chunks = template.split(insertionRegex);\n const parts: any[] = [];\n\n for (let i = 0; i < chunks.length; i++) {\n if (i % 2 === 0) {\n if (chunks[i]) parts.push(chunks[i]);\n } else {\n const val = values[chunks[i].trim()];\n if (val != null) parts.push(val);\n }\n }\n\n return { isSimple: false, parts };\n};\n"],"mappings":";;;;;AAIA,MAAM,kBAAkB,UACtB,SAAS,QACT,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU;AAGnB,MAAM,iBAAiB;AAEvB,MAAa,0BACX,UACA,SAA4B,EAAE,KACiB;AAC/C,KAAI,CAAC,OAAO,OAAO,OAAO,CAAC,KAAK,eAAe,CAC7C,QAAO;EACL,UAAU;EACV,OAAO,SAAS,QAAQ,iBAAiB,GAAG,SACzC,OAAO,IAAI,MAAM,KAAK,IAAI,UAAU,CACtC;EACF;CAGH,MAAM,SAAS,SAAS,MAAM,eAAe;CAC7C,MAAM,QAAe,EAAE;AAEvB,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,KAAI,IAAI,MAAM,GACZ;MAAI,OAAO,GAAI,OAAM,KAAK,OAAO,GAAG;QAC/B;EACL,MAAM,MAAM,OAAO,OAAO,GAAG,MAAM;AACnC,MAAI,OAAO,KAAM,OAAM,KAAK,IAAI;;AAIpC,QAAO;EAAE,UAAU;EAAO;EAAO"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { resolveRoutingConfig } from "./getPrefix.mjs";
|
|
2
|
+
import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/localization/generateSitemap.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns whether xhtml:link alternate tags should be generated for the given routing mode.
|
|
7
|
+
*
|
|
8
|
+
* Alternates are meaningful only when locale URLs are distinct:
|
|
9
|
+
* - 'no-prefix' produces identical URLs for all locales → no alternates
|
|
10
|
+
* - all other modes produce distinct URLs → alternates are generated
|
|
11
|
+
*/
|
|
12
|
+
const shouldIncludeAlternates = (mode, xhtmlLinks) => xhtmlLinks && mode !== "no-prefix";
|
|
13
|
+
/**
|
|
14
|
+
* Generates a single `<url>` sitemap entry for the given path.
|
|
15
|
+
*
|
|
16
|
+
* Example:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* generateSitemapUrl('/dashboard', {
|
|
20
|
+
* siteUrl: 'https://example.com',
|
|
21
|
+
* changefreq: 'weekly',
|
|
22
|
+
* priority: 0.8,
|
|
23
|
+
* xhtmlLinks: true,
|
|
24
|
+
* locales: ['en', 'fr'],
|
|
25
|
+
* defaultLocale: 'en',
|
|
26
|
+
* mode: 'prefix-no-default',
|
|
27
|
+
* });
|
|
28
|
+
* // Returns:
|
|
29
|
+
* // <url>
|
|
30
|
+
* // <loc>https://example.com/dashboard</loc>
|
|
31
|
+
* // <changefreq>weekly</changefreq>
|
|
32
|
+
* // <priority>0.8</priority>
|
|
33
|
+
* // <xhtml:link rel="alternate" hrefLang="en" href="https://example.com/dashboard"/>
|
|
34
|
+
* // <xhtml:link rel="alternate" hrefLang="fr" href="https://example.com/fr/dashboard"/>
|
|
35
|
+
* // <xhtml:link rel="alternate" hrefLang="x-default" href="https://example.com/dashboard"/>
|
|
36
|
+
* // </url>
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param path - The canonical path to generate the entry for.
|
|
40
|
+
* @param options - Configuration options.
|
|
41
|
+
* @returns A `<url>` XML string.
|
|
42
|
+
*/
|
|
43
|
+
const generateSitemapUrl = (path, options) => {
|
|
44
|
+
const { siteUrl, changefreq, priority, lastmod, xhtmlLinks = true, ...routingOptions } = options;
|
|
45
|
+
const resolved = resolveRoutingConfig(routingOptions);
|
|
46
|
+
const fullUrl = `${siteUrl}${path}`;
|
|
47
|
+
const lines = [
|
|
48
|
+
" <url>",
|
|
49
|
+
` <loc>${fullUrl}</loc>`,
|
|
50
|
+
lastmod ? ` <lastmod>${lastmod}</lastmod>` : null,
|
|
51
|
+
changefreq ? ` <changefreq>${changefreq}</changefreq>` : null,
|
|
52
|
+
priority !== void 0 ? ` <priority>${priority}</priority>` : null
|
|
53
|
+
];
|
|
54
|
+
if (shouldIncludeAlternates(resolved.mode, xhtmlLinks)) {
|
|
55
|
+
const alternates = getMultilingualUrls(path, routingOptions);
|
|
56
|
+
for (const [lang, localePath] of Object.entries(alternates)) lines.push(` <xhtml:link rel="alternate" hrefLang="${lang}" href="${siteUrl}${localePath}"/>`);
|
|
57
|
+
lines.push(` <xhtml:link rel="alternate" hrefLang="x-default" href="${fullUrl}"/>`);
|
|
58
|
+
}
|
|
59
|
+
lines.push(" </url>");
|
|
60
|
+
return lines.filter(Boolean).join("\n");
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Generates a full XML sitemap string from an array of URL entries.
|
|
64
|
+
*
|
|
65
|
+
* Automatically adds `xmlns:xhtml` to the `<urlset>` declaration when
|
|
66
|
+
* xhtml:link alternate tags are included.
|
|
67
|
+
*
|
|
68
|
+
* Example:
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* generateSitemap(
|
|
72
|
+
* [
|
|
73
|
+
* { path: '/', changefreq: 'daily', priority: 1.0 },
|
|
74
|
+
* { path: '/about', changefreq: 'monthly', priority: 0.5 },
|
|
75
|
+
* ],
|
|
76
|
+
* {
|
|
77
|
+
* siteUrl: 'https://example.com',
|
|
78
|
+
* xhtmlLinks: true,
|
|
79
|
+
* locales: ['en', 'fr'],
|
|
80
|
+
* defaultLocale: 'en',
|
|
81
|
+
* mode: 'prefix-no-default',
|
|
82
|
+
* }
|
|
83
|
+
* );
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @param entries - Array of URL entries to include in the sitemap.
|
|
87
|
+
* @param options - Sitemap generation options.
|
|
88
|
+
* @returns A full XML sitemap string.
|
|
89
|
+
*/
|
|
90
|
+
const generateSitemap = (entries, options) => {
|
|
91
|
+
const { siteUrl, xhtmlLinks = true, ...routingOptions } = options;
|
|
92
|
+
const includeAlternates = shouldIncludeAlternates(resolveRoutingConfig(routingOptions).mode, xhtmlLinks);
|
|
93
|
+
const xmlEntries = entries.map((entry) => generateSitemapUrl(entry.path, {
|
|
94
|
+
...entry,
|
|
95
|
+
siteUrl,
|
|
96
|
+
xhtmlLinks,
|
|
97
|
+
...routingOptions
|
|
98
|
+
}));
|
|
99
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
100
|
+
<urlset
|
|
101
|
+
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"${includeAlternates ? "\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"" : ""}
|
|
102
|
+
>
|
|
103
|
+
${xmlEntries.join("\n")}
|
|
104
|
+
</urlset>`;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
export { generateSitemap, generateSitemapUrl };
|
|
109
|
+
//# sourceMappingURL=generateSitemap.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSitemap.mjs","names":[],"sources":["../../../src/localization/generateSitemap.ts"],"sourcesContent":["import type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getMultilingualUrls } from './getMultilingualUrls';\nimport { type RoutingOptions, resolveRoutingConfig } from './getPrefix';\n\nexport type SitemapUrlEntry = {\n /** The canonical path, e.g. '/dashboard' */\n path: string;\n changefreq?: string;\n priority?: number;\n /** ISO date string, e.g. '2024-01-15' */\n lastmod?: string;\n};\n\nexport type GenerateSitemapOptions = {\n /** Base site URL without trailing slash, e.g. 'https://example.com' */\n siteUrl: string;\n /**\n * Whether to include xhtml:link alternate tags for multilingual support.\n *\n * When enabled, alternate links are only generated for modes where URLs\n * differ per locale:\n * - 'prefix-no-default': included\n * - 'prefix-all': included\n * - 'search-params': included\n * - 'no-prefix': excluded (all locales share the same URL)\n *\n * @default true\n */\n xhtmlLinks?: boolean;\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n};\n\n/**\n * Returns whether xhtml:link alternate tags should be generated for the given routing mode.\n *\n * Alternates are meaningful only when locale URLs are distinct:\n * - 'no-prefix' produces identical URLs for all locales → no alternates\n * - all other modes produce distinct URLs → alternates are generated\n */\nconst shouldIncludeAlternates = (\n mode: RoutingConfig['mode'],\n xhtmlLinks: boolean\n): boolean => xhtmlLinks && mode !== 'no-prefix';\n\n/**\n * Generates a single `<url>` sitemap entry for the given path.\n *\n * Example:\n *\n * ```ts\n * generateSitemapUrl('/dashboard', {\n * siteUrl: 'https://example.com',\n * changefreq: 'weekly',\n * priority: 0.8,\n * xhtmlLinks: true,\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * mode: 'prefix-no-default',\n * });\n * // Returns:\n * // <url>\n * // <loc>https://example.com/dashboard</loc>\n * // <changefreq>weekly</changefreq>\n * // <priority>0.8</priority>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"en\" href=\"https://example.com/dashboard\"/>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"fr\" href=\"https://example.com/fr/dashboard\"/>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"x-default\" href=\"https://example.com/dashboard\"/>\n * // </url>\n * ```\n *\n * @param path - The canonical path to generate the entry for.\n * @param options - Configuration options.\n * @returns A `<url>` XML string.\n */\nexport const generateSitemapUrl = (\n path: string,\n options: SitemapUrlEntry & GenerateSitemapOptions\n): string => {\n const {\n siteUrl,\n changefreq,\n priority,\n lastmod,\n xhtmlLinks = true,\n ...routingOptions\n } = options;\n\n const resolved = resolveRoutingConfig(routingOptions as RoutingOptions);\n const fullUrl = `${siteUrl}${path}`;\n\n const lines: (string | null)[] = [\n ' <url>',\n ` <loc>${fullUrl}</loc>`,\n lastmod ? ` <lastmod>${lastmod}</lastmod>` : null,\n changefreq ? ` <changefreq>${changefreq}</changefreq>` : null,\n priority !== undefined ? ` <priority>${priority}</priority>` : null,\n ];\n\n if (shouldIncludeAlternates(resolved.mode, xhtmlLinks)) {\n const alternates = getMultilingualUrls(\n path,\n routingOptions as RoutingOptions\n );\n\n for (const [lang, localePath] of Object.entries(alternates)) {\n lines.push(\n ` <xhtml:link rel=\"alternate\" hrefLang=\"${lang}\" href=\"${siteUrl}${localePath}\"/>`\n );\n }\n\n lines.push(\n ` <xhtml:link rel=\"alternate\" hrefLang=\"x-default\" href=\"${fullUrl}\"/>`\n );\n }\n\n lines.push(' </url>');\n\n return lines.filter(Boolean).join('\\n');\n};\n\n/**\n * Generates a full XML sitemap string from an array of URL entries.\n *\n * Automatically adds `xmlns:xhtml` to the `<urlset>` declaration when\n * xhtml:link alternate tags are included.\n *\n * Example:\n *\n * ```ts\n * generateSitemap(\n * [\n * { path: '/', changefreq: 'daily', priority: 1.0 },\n * { path: '/about', changefreq: 'monthly', priority: 0.5 },\n * ],\n * {\n * siteUrl: 'https://example.com',\n * xhtmlLinks: true,\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * mode: 'prefix-no-default',\n * }\n * );\n * ```\n *\n * @param entries - Array of URL entries to include in the sitemap.\n * @param options - Sitemap generation options.\n * @returns A full XML sitemap string.\n */\nexport const generateSitemap = (\n entries: SitemapUrlEntry[],\n options: GenerateSitemapOptions\n): string => {\n const { siteUrl, xhtmlLinks = true, ...routingOptions } = options;\n\n const resolved = resolveRoutingConfig(routingOptions as RoutingOptions);\n const includeAlternates = shouldIncludeAlternates(resolved.mode, xhtmlLinks);\n\n const xmlEntries = entries.map((entry) =>\n generateSitemapUrl(entry.path, {\n ...entry,\n siteUrl,\n xhtmlLinks,\n ...routingOptions,\n })\n );\n\n const xmlns = includeAlternates\n ? '\\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"'\n : '';\n\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"${xmlns}\n>\n${xmlEntries.join('\\n')}\n</urlset>`;\n};\n"],"mappings":";;;;;;;;;;;AA2CA,MAAM,2BACJ,MACA,eACY,cAAc,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCrC,MAAa,sBACX,MACA,YACW;CACX,MAAM,EACJ,SACA,YACA,UACA,SACA,aAAa,MACb,GAAG,mBACD;CAEJ,MAAM,WAAW,qBAAqB,eAAiC;CACvE,MAAM,UAAU,GAAG,UAAU;CAE7B,MAAM,QAA2B;EAC/B;EACA,YAAY,QAAQ;EACpB,UAAU,gBAAgB,QAAQ,cAAc;EAChD,aAAa,mBAAmB,WAAW,iBAAiB;EAC5D,aAAa,SAAY,iBAAiB,SAAS,eAAe;EACnE;AAED,KAAI,wBAAwB,SAAS,MAAM,WAAW,EAAE;EACtD,MAAM,aAAa,oBACjB,MACA,eACD;AAED,OAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,WAAW,CACzD,OAAM,KACJ,6CAA6C,KAAK,UAAU,UAAU,WAAW,KAClF;AAGH,QAAM,KACJ,8DAA8D,QAAQ,KACvE;;AAGH,OAAM,KAAK,WAAW;AAEtB,QAAO,MAAM,OAAO,QAAQ,CAAC,KAAK,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BzC,MAAa,mBACX,SACA,YACW;CACX,MAAM,EAAE,SAAS,aAAa,MAAM,GAAG,mBAAmB;CAG1D,MAAM,oBAAoB,wBADT,qBAAqB,eAAiC,CACZ,MAAM,WAAW;CAE5E,MAAM,aAAa,QAAQ,KAAK,UAC9B,mBAAmB,MAAM,MAAM;EAC7B,GAAG;EACH;EACA;EACA,GAAG;EACJ,CAAC,CACH;AAMD,QAAO;;uDAJO,oBACV,qDACA,GAIuD;;EAE3D,WAAW,KAAK,KAAK,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLocaleFromStorageClient } from "../utils/localeStorage.mjs";
|
|
2
2
|
import { localeDetector } from "./localeDetector.mjs";
|
|
3
3
|
import configuration from "@intlayer/config/built";
|
|
4
4
|
import { ENGLISH } from "@intlayer/types/locales";
|
|
@@ -52,7 +52,7 @@ const detectLanguage = (order, options) => {
|
|
|
52
52
|
};
|
|
53
53
|
const storageDetector = () => {
|
|
54
54
|
if (typeof window === "undefined") return;
|
|
55
|
-
const locale =
|
|
55
|
+
const locale = getLocaleFromStorageClient({
|
|
56
56
|
getCookie: (name) => {
|
|
57
57
|
try {
|
|
58
58
|
const cookies = document.cookie.split(";");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBrowserLocale.mjs","names":[],"sources":["../../../src/localization/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport {\n
|
|
1
|
+
{"version":3,"file":"getBrowserLocale.mjs","names":[],"sources":["../../../src/localization/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport {\n getLocaleFromStorageClient,\n type LocaleStorageClientOptions,\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: LocaleStorageClientOptions = {\n getCookie: (name: string) =>\n document.cookie\n .split(';')\n .find((c) => c.trim().startsWith(`${name}=`))\n ?.split('=')[1],\n getLocaleStorage: (name: string) => localStorage.getItem(name),\n getSessionStorage: (name: string) => sessionStorage.getItem(name),\n isCookieEnabled: true,\n setCookieStore: (name, value, attributes) =>\n cookieStore.set({\n name,\n value,\n path: attributes.path,\n domain: attributes.domain,\n expires: attributes.expires,\n sameSite: attributes.sameSite,\n }),\n setCookieString: (_name, cookie) => {\n // biome-ignore lint/suspicious/noDocumentCookie: set cookie fallback\n document.cookie = cookie;\n },\n setSessionStorage: (name, value) => sessionStorage.setItem(name, value),\n setLocaleStorage: (name, value) => localStorage.setItem(name, value),\n};\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Storage,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n htmlTag: typeof document !== 'undefined' ? document.documentElement : null,\n };\n};\n\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locale | undefined> => {\n const detected: Record<LanguageDetector, Locale | undefined> = {} as Record<\n LanguageDetector,\n Locale | undefined\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locale;\n }\n };\n\n const storageDetector = () => {\n if (typeof window === 'undefined') return;\n\n const locale = getLocaleFromStorageClient({\n getCookie: (name: string) => {\n try {\n const cookies = document.cookie.split(';');\n const cookieName = `${name}=`;\n\n const cookie = cookies.find((cookie) =>\n cookie.trim().startsWith(cookieName)\n );\n\n if (cookie) {\n return cookie.split('=')[1].trim();\n }\n } catch {}\n return undefined;\n },\n getSessionStorage: (name: string) => {\n try {\n return window.sessionStorage.getItem(name) ?? undefined;\n } catch {}\n return undefined;\n },\n getLocaleStorage: (name: string) => {\n try {\n return window.localStorage.getItem(name) ?? undefined;\n } catch {}\n return undefined;\n },\n });\n\n if (locale) {\n detected[LanguageDetector.Storage] = locale;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n const { internationalization } = configuration;\n const languages = navigator.languages ?? [navigator.language];\n\n // Use localeDetector to find the best matching locale\n const locale = localeDetector(\n { 'accept-language': languages.join(',') },\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n if (locale) {\n detected[LanguageDetector.Navigator] = locale;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n const { internationalization } = configuration;\n\n // Validate and resolve the locale\n const locale = localeDetector(\n { 'accept-language': lang },\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n detected[LanguageDetector.HtmlTag] = locale;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Storage]: storageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locale | undefined>,\n order: LanguageDetector[]\n): Locale => {\n const { internationalization } = configuration;\n\n for (const detector of order) {\n const locale = locales[detector];\n\n if (locale && internationalization.locales.includes(locale)) {\n return locale;\n }\n }\n\n return internationalization?.defaultLocale ?? 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":";;;;;;AASA,IAAY,mBAAL;AACL;AACA;AACA;AACA;;KACD;AAED,MAAa,uBAAmD;CAC9D,YAAY,SACV,SAAS,OACN,MAAM,IAAI,CACV,MAAM,MAAM,EAAE,MAAM,CAAC,WAAW,GAAG,KAAK,GAAG,CAAC,EAC3C,MAAM,IAAI,CAAC;CACjB,mBAAmB,SAAiB,aAAa,QAAQ,KAAK;CAC9D,oBAAoB,SAAiB,eAAe,QAAQ,KAAK;CACjE,iBAAiB;CACjB,iBAAiB,MAAM,OAAO,eAC5B,YAAY,IAAI;EACd;EACA;EACA,MAAM,WAAW;EACjB,QAAQ,WAAW;EACnB,SAAS,WAAW;EACpB,UAAU,WAAW;EACtB,CAAC;CACJ,kBAAkB,OAAO,WAAW;AAElC,WAAS,SAAS;;CAEpB,oBAAoB,MAAM,UAAU,eAAe,QAAQ,MAAM,MAAM;CACvE,mBAAmB,MAAM,UAAU,aAAa,QAAQ,MAAM,MAAM;CACrE;AASD,MAAM,2BAAoD;AACxD,QAAO;EACL,OAAO;GACL,iBAAiB;GACjB,iBAAiB;GACjB,iBAAiB;GACjB,iBAAiB;GAClB;EACD,mBAAmB;EACnB,SAAS,OAAO,aAAa,cAAc,SAAS,kBAAkB;EACvE;;AAGH,MAAM,kBACJ,OACA,YACiD;CACjD,MAAM,WAAyD,EAAE;CAKjE,MAAM,4BAA4B;AAChC,MAAI,OAAO,WAAW,YAAa;EACnC,MAAM,SAAS,OAAO,SAAS,UAAU;EAEzC,MAAM,QADS,IAAI,gBAAgB,OAAO,CACrB,IAAI,QAAQ,qBAAqB,GAAG;AACzD,MAAI,MACF,UAAS,iBAAiB,eAAe;;CAI7C,MAAM,wBAAwB;AAC5B,MAAI,OAAO,WAAW,YAAa;EAEnC,MAAM,SAAS,2BAA2B;GACxC,YAAY,SAAiB;AAC3B,QAAI;KACF,MAAM,UAAU,SAAS,OAAO,MAAM,IAAI;KAC1C,MAAM,aAAa,GAAG,KAAK;KAE3B,MAAM,SAAS,QAAQ,MAAM,WAC3B,OAAO,MAAM,CAAC,WAAW,WAAW,CACrC;AAED,SAAI,OACF,QAAO,OAAO,MAAM,IAAI,CAAC,GAAG,MAAM;YAE9B;;GAGV,oBAAoB,SAAiB;AACnC,QAAI;AACF,YAAO,OAAO,eAAe,QAAQ,KAAK,IAAI;YACxC;;GAGV,mBAAmB,SAAiB;AAClC,QAAI;AACF,YAAO,OAAO,aAAa,QAAQ,KAAK,IAAI;YACtC;;GAGX,CAAC;AAEF,MAAI,OACF,UAAS,iBAAiB,WAAW;;CAIzC,MAAM,0BAA0B;AAC9B,MAAI,OAAO,cAAc,YAAa;EAEtC,MAAM,EAAE,yBAAyB;EACjC,MAAM,YAAY,UAAU,aAAa,CAAC,UAAU,SAAS;EAG7D,MAAM,SAAS,eACb,EAAE,mBAAmB,UAAU,KAAK,IAAI,EAAE,EAC1C,qBAAqB,SACrB,qBAAqB,cACtB;AAED,MAAI,OACF,UAAS,iBAAiB,aAAa;;CAI3C,MAAM,wBAAwB;EAC5B,MAAM,UAAU,QAAQ;AACxB,MAAI,WAAW,OAAO,QAAQ,iBAAiB,YAAY;GACzD,MAAM,OAAO,QAAQ,aAAa,OAAO;AACzC,OAAI,MAAM;IACR,MAAM,EAAE,yBAAyB;IAGjC,MAAM,SAAS,eACb,EAAE,mBAAmB,MAAM,EAC3B,qBAAqB,SACrB,qBAAqB,cACtB;AAED,aAAS,iBAAiB,WAAW;;;;CAM3C,MAAM,YAAwC;GAC3C,iBAAiB,cAAc;GAC/B,iBAAiB,UAAU;GAC3B,iBAAiB,YAAY;GAC7B,iBAAiB,UAAU;EAC7B;AAGD,OAAM,SAAS,iBAAiB;AAC9B,YAAU,iBAAiB;GAC3B;AAEF,QAAO;;AAGT,MAAM,2BACJ,SACA,UACW;CACX,MAAM,EAAE,yBAAyB;AAEjC,MAAK,MAAM,YAAY,OAAO;EAC5B,MAAM,SAAS,QAAQ;AAEvB,MAAI,UAAU,qBAAqB,QAAQ,SAAS,OAAO,CACzD,QAAO;;AAIX,QAAO,sBAAsB,iBAAiB;;;;;;;;;;;;;;;;;AAkBhD,MAAa,oBACX,cAAmD,EAAE,KAC1C;CACX,MAAM,UAAU;EAAE,GAAG,oBAAoB;EAAE,GAAG;EAAa;AAI3D,QAAO,wBAFS,eAAe,QAAQ,SAAS,EAAE,EAAE,QAAQ,EAEpB,QAAQ,SAAS,EAAE,CAAC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLocaleFromStorageServer } from "../utils/localeStorage.mjs";
|
|
2
2
|
import { localeResolver } from "./localeResolver.mjs";
|
|
3
3
|
import { getPreferredLanguages } from "./localeDetector.mjs";
|
|
4
|
-
import { DEFAULT_LOCALE, LOCALES } from "@intlayer/config/defaultValues";
|
|
5
4
|
import configuration from "@intlayer/config/built";
|
|
5
|
+
import { DEFAULT_LOCALE, LOCALES } from "@intlayer/config/defaultValues";
|
|
6
6
|
|
|
7
7
|
//#region src/localization/getLocale.ts
|
|
8
8
|
const getLocale = async (ctx = {}) => {
|
|
9
9
|
const defaultLocale = configuration?.internationalization?.defaultLocale ?? DEFAULT_LOCALE;
|
|
10
10
|
const availableLocales = configuration?.internationalization?.locales ?? LOCALES;
|
|
11
|
-
const storedLocale =
|
|
11
|
+
const storedLocale = getLocaleFromStorageServer({
|
|
12
12
|
getCookie: ctx.getCookie,
|
|
13
13
|
getHeader: ctx.getHeader
|
|
14
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.mjs","names":[],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DEFAULT_LOCALE, LOCALES } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport {
|
|
1
|
+
{"version":3,"file":"getLocale.mjs","names":[],"sources":["../../../src/localization/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DEFAULT_LOCALE, LOCALES } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getLocaleFromStorageServer } 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 ?? DEFAULT_LOCALE;\n const availableLocales =\n configuration?.internationalization?.locales ?? LOCALES;\n\n // Try locale from storage (cookie or header)\n const storedLocale = getLocaleFromStorageServer({\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":";;;;;;;AAYA,MAAa,YAAY,OAAO,MAAsB,EAAE,KAAsB;CAC5E,MAAM,gBACJ,eAAe,sBAAsB,iBAAiB;CACxD,MAAM,mBACJ,eAAe,sBAAsB,WAAW;CAGlD,MAAM,eAAe,2BAA2B;EAC9C,WAAW,IAAI;EACf,WAAW,IAAI;EAChB,CAAC;AAEF,KAAI,aACF,QAAO;CAIT,MAAM,uBAAuB,IAAI,YAAY,kBAAkB;AAE/D,KAAI,CAAC,qBACH,QAAO;CAQT,MAAM,qBAAqB,eALI,sBAC7B,sBACA,iBACD,EAIC,kBACA,cACD;AAED,KAAI,mBACF,QAAO;AAIT,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { checkIsURLAbsolute } from "../utils/checkIsURLAbsolute.mjs";
|
|
2
|
-
import { getPrefix, resolveRoutingConfig } from "./getPrefix.mjs";
|
|
3
2
|
import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
|
|
3
|
+
import { getPrefix, resolveRoutingConfig } from "./getPrefix.mjs";
|
|
4
4
|
import { getCanonicalPath, getLocalizedPath, getRewriteRules } from "./rewriteUtils.mjs";
|
|
5
5
|
import configuration from "@intlayer/config/built";
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DEFAULT_LOCALE, LOCALES, ROUTING_MODE } from "@intlayer/config/defaultValues";
|
|
2
1
|
import configuration from "@intlayer/config/built";
|
|
2
|
+
import { DEFAULT_LOCALE, LOCALES, ROUTING_MODE } from "@intlayer/config/defaultValues";
|
|
3
3
|
|
|
4
4
|
//#region src/localization/getPrefix.ts
|
|
5
5
|
/**
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
|
|
2
|
+
import { getPrefix } from "./getPrefix.mjs";
|
|
3
|
+
import { getCanonicalPath, getInternalPath, getLocalizedPath, getRewritePath, getRewriteRules } from "./rewriteUtils.mjs";
|
|
4
|
+
import { getLocalizedUrl } from "./getLocalizedUrl.mjs";
|
|
5
|
+
import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
|
|
6
|
+
import { generateSitemap, generateSitemapUrl } from "./generateSitemap.mjs";
|
|
2
7
|
import { localeResolver } from "./localeResolver.mjs";
|
|
3
8
|
import { localeDetector } from "./localeDetector.mjs";
|
|
4
9
|
import { getBrowserLocale, localeStorageOptions } from "./getBrowserLocale.mjs";
|
|
5
10
|
import { getHTMLTextDir } from "./getHTMLTextDir.mjs";
|
|
6
11
|
import { getLocale } from "./getLocale.mjs";
|
|
7
|
-
import { getPrefix } from "./getPrefix.mjs";
|
|
8
12
|
import { getLocaleFromPath } from "./getLocaleFromPath.mjs";
|
|
9
13
|
import { getLocaleLang } from "./getLocaleLang.mjs";
|
|
10
14
|
import { getLocaleName } from "./getLocaleName.mjs";
|
|
11
|
-
import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
|
|
12
|
-
import { getCanonicalPath, getInternalPath, getLocalizedPath, getRewritePath, getRewriteRules } from "./rewriteUtils.mjs";
|
|
13
|
-
import { getLocalizedUrl } from "./getLocalizedUrl.mjs";
|
|
14
|
-
import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
|
|
15
15
|
import { localeFlatMap, localeMap, localeRecord } from "./localeMapper.mjs";
|
|
16
16
|
import { validatePrefix } from "./validatePrefix.mjs";
|
|
17
17
|
|
|
18
|
-
export { getBrowserLocale, getCanonicalPath, getHTMLTextDir, getInternalPath, getLocale, getLocaleFromPath, getLocaleLang, getLocaleName, getLocalizedPath, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, getPrefix, getRewritePath, getRewriteRules,
|
|
18
|
+
export { generateSitemap, generateSitemapUrl, getBrowserLocale, getCanonicalPath, getHTMLTextDir, getInternalPath, getLocale, getLocaleFromPath, getLocaleLang, getLocaleName, getLocalizedPath, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, getPrefix, getRewritePath, getRewriteRules, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, validatePrefix };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getPrefix } from "./getPrefix.mjs";
|
|
2
|
-
import { DEFAULT_LOCALE } from "@intlayer/config/defaultValues";
|
|
3
2
|
import configuration from "@intlayer/config/built";
|
|
3
|
+
import { DEFAULT_LOCALE } from "@intlayer/config/defaultValues";
|
|
4
4
|
|
|
5
5
|
//#region src/localization/localeMapper.ts
|
|
6
6
|
/**
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { HTML_TAGS } from "./htmlTags.mjs";
|
|
2
|
-
|
|
3
1
|
//#region src/transpiler/html/getHTMLCustomComponents.ts
|
|
4
2
|
const parseAttributes = (attributesString) => {
|
|
5
3
|
const attributes = {};
|
|
6
|
-
if (!attributesString
|
|
4
|
+
if (!attributesString?.trim()) return attributes;
|
|
7
5
|
[...attributesString.matchAll(/([a-zA-Z0-9-:_@]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]+))?/g)].forEach((match) => {
|
|
8
6
|
const attrName = match[1];
|
|
9
7
|
attributes[attrName] = "string";
|
|
@@ -24,7 +22,7 @@ const getHTMLCustomComponents = (content) => {
|
|
|
24
22
|
const tagName = match[2];
|
|
25
23
|
const attributesString = match[3];
|
|
26
24
|
const isSelfClosing = !!match[4];
|
|
27
|
-
if (
|
|
25
|
+
if (/^[a-z][a-z0-9]*$/.test(tagName)) {
|
|
28
26
|
components[tagName] = true;
|
|
29
27
|
return;
|
|
30
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHTMLCustomComponents.mjs","names":[],"sources":["../../../../src/transpiler/html/getHTMLCustomComponents.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"getHTMLCustomComponents.mjs","names":[],"sources":["../../../../src/transpiler/html/getHTMLCustomComponents.ts"],"sourcesContent":["const parseAttributes = (attributesString: string): Record<string, string> => {\n const attributes: Record<string, string> = {};\n\n if (!attributesString?.trim()) {\n return attributes;\n }\n\n // Regex to match attribute names\n // Matches: name=\"value\", name='value', name=value, or just name\n const attrRegex =\n /([a-zA-Z0-9-:_@]+)(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^>\\s]+))?/g;\n\n const matches = [...attributesString.matchAll(attrRegex)];\n\n matches.forEach((match) => {\n const attrName = match[1];\n attributes[attrName] = 'string';\n });\n\n return attributes;\n};\n\n/**\n * Extracts component names from an HTML string.\n * - Standard HTML tags are set to `true`.\n * - Custom components are parsed to extract their attributes/props.\n */\nexport const getHTMLCustomComponents = (\n content: string\n): Record<string, Record<string, string> | true> => {\n if (typeof content !== 'string') {\n throw new Error('content must be a string');\n }\n\n const tagRegex = /<(\\/)?([a-zA-Z0-9.-]+)\\s*([\\s\\S]*?)(\\/?)>/g;\n const matches = [...content.matchAll(tagRegex)];\n\n const components: Record<string, Record<string, string> | true> = {};\n\n matches.forEach((match) => {\n const isClosing = !!match[1];\n const tagName = match[2];\n const attributesString = match[3];\n const isSelfClosing = !!match[4];\n\n // Matches any tag that is entirely lowercase letters and numbers (e.g., div, h1)\n const isStandardHTMLTag = /^[a-z][a-z0-9]*$/.test(tagName);\n\n if (isStandardHTMLTag) {\n components[tagName] = true;\n return;\n }\n\n if (!components[tagName]) {\n components[tagName] = {};\n }\n\n if (components[tagName] === true) {\n return;\n }\n\n if (isClosing) {\n return;\n }\n\n const attributes = parseAttributes(attributesString);\n const componentDef = components[tagName] as Record<string, string>;\n Object.assign(componentDef, attributes);\n\n if (!isSelfClosing) {\n componentDef.children = 'string';\n }\n });\n\n return components;\n};\n"],"mappings":";AAAA,MAAM,mBAAmB,qBAAqD;CAC5E,MAAM,aAAqC,EAAE;AAE7C,KAAI,CAAC,kBAAkB,MAAM,CAC3B,QAAO;AAUT,CAFgB,CAAC,GAAG,iBAAiB,SAFnC,6DAEsD,CAAC,CAEjD,SAAS,UAAU;EACzB,MAAM,WAAW,MAAM;AACvB,aAAW,YAAY;GACvB;AAEF,QAAO;;;;;;;AAQT,MAAa,2BACX,YACkD;AAClD,KAAI,OAAO,YAAY,SACrB,OAAM,IAAI,MAAM,2BAA2B;CAI7C,MAAM,UAAU,CAAC,GAAG,QAAQ,SADX,6CAC6B,CAAC;CAE/C,MAAM,aAA4D,EAAE;AAEpE,SAAQ,SAAS,UAAU;EACzB,MAAM,YAAY,CAAC,CAAC,MAAM;EAC1B,MAAM,UAAU,MAAM;EACtB,MAAM,mBAAmB,MAAM;EAC/B,MAAM,gBAAgB,CAAC,CAAC,MAAM;AAK9B,MAF0B,mBAAmB,KAAK,QAAQ,EAEnC;AACrB,cAAW,WAAW;AACtB;;AAGF,MAAI,CAAC,WAAW,SACd,YAAW,WAAW,EAAE;AAG1B,MAAI,WAAW,aAAa,KAC1B;AAGF,MAAI,UACF;EAGF,MAAM,aAAa,gBAAgB,iBAAiB;EACpD,MAAM,eAAe,WAAW;AAChC,SAAO,OAAO,cAAc,WAAW;AAEvC,MAAI,CAAC,cACH,cAAa,WAAW;GAE1B;AAEF,QAAO"}
|
package/dist/esm/utils/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { parseYaml } from "./parseYaml.mjs";
|
|
2
2
|
import { isValidElement } from "./isValidReactElement.mjs";
|
|
3
|
-
import { CachedIntl, bindIntl,
|
|
4
|
-
import { getCookie } from "./getCookie.mjs";
|
|
5
|
-
import { LocaleStorage, getLocaleFromStorage, setLocaleInStorage } from "./localeStorage.mjs";
|
|
3
|
+
import { CachedIntl, bindIntl, getCachedIntl } from "./intl.mjs";
|
|
6
4
|
import { checkIsURLAbsolute } from "./checkIsURLAbsolute.mjs";
|
|
5
|
+
import { getCookie } from "./getCookie.mjs";
|
|
6
|
+
import { LocaleStorage, LocaleStorageClient, LocaleStorageServer, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer } from "./localeStorage.mjs";
|
|
7
7
|
import { isSameKeyPath } from "./isSameKeyPath.mjs";
|
|
8
8
|
|
|
9
|
-
export { CachedIntl, CachedIntl as Intl, LocaleStorage, bindIntl, checkIsURLAbsolute,
|
|
9
|
+
export { CachedIntl, CachedIntl as Intl, LocaleStorage, LocaleStorageClient, LocaleStorageServer, bindIntl, checkIsURLAbsolute, getCachedIntl, getCookie, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, isSameKeyPath, isValidElement, parseYaml, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer };
|