@intlayer/core 7.4.0 → 7.5.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.
Files changed (63) hide show
  1. package/dist/cjs/localization/getLocale.cjs +3 -4
  2. package/dist/cjs/localization/getLocale.cjs.map +1 -1
  3. package/dist/cjs/localization/getLocalizedUrl.cjs +2 -1
  4. package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
  5. package/dist/cjs/messageFormat/ICU.cjs +309 -0
  6. package/dist/cjs/messageFormat/ICU.cjs.map +1 -0
  7. package/dist/cjs/messageFormat/i18next.cjs +320 -0
  8. package/dist/cjs/messageFormat/i18next.cjs.map +1 -0
  9. package/dist/cjs/messageFormat/index.cjs +10 -0
  10. package/dist/cjs/messageFormat/vue-i18n.cjs +166 -0
  11. package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -0
  12. package/dist/esm/localization/getLocale.mjs +1 -2
  13. package/dist/esm/localization/getLocale.mjs.map +1 -1
  14. package/dist/esm/localization/getLocalizedUrl.mjs +2 -1
  15. package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
  16. package/dist/esm/messageFormat/ICU.mjs +307 -0
  17. package/dist/esm/messageFormat/ICU.mjs.map +1 -0
  18. package/dist/esm/messageFormat/i18next.mjs +318 -0
  19. package/dist/esm/messageFormat/i18next.mjs.map +1 -0
  20. package/dist/esm/messageFormat/index.mjs +5 -0
  21. package/dist/esm/messageFormat/vue-i18n.mjs +164 -0
  22. package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -0
  23. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +8 -7
  24. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
  25. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +8 -7
  26. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
  27. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +8 -7
  28. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
  29. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +2 -2
  30. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
  31. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  32. package/dist/types/messageFormat/ICU.d.ts +11 -0
  33. package/dist/types/messageFormat/ICU.d.ts.map +1 -0
  34. package/dist/types/messageFormat/i18next.d.ts +9 -0
  35. package/dist/types/messageFormat/i18next.d.ts.map +1 -0
  36. package/dist/types/messageFormat/index.d.ts +4 -0
  37. package/dist/types/messageFormat/vue-i18n.d.ts +9 -0
  38. package/dist/types/messageFormat/vue-i18n.d.ts.map +1 -0
  39. package/dist/types/transpiler/translation/translation.d.ts +1 -1
  40. package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
  41. package/package.json +11 -6
  42. package/dist/cjs/dist/esm/getStorageAttributes.cjs +0 -134
  43. package/dist/cjs/dist/esm/getStorageAttributes.cjs.map +0 -1
  44. package/dist/cjs/dist/esm/localization/localeResolver.cjs +0 -28
  45. package/dist/cjs/dist/esm/localization/localeResolver.cjs.map +0 -1
  46. package/dist/cjs/dist/esm/utils/getCookie.cjs +0 -32
  47. package/dist/cjs/dist/esm/utils/getCookie.cjs.map +0 -1
  48. package/dist/cjs/dist/esm/utils/localeStorage.cjs +0 -61
  49. package/dist/cjs/dist/esm/utils/localeStorage.cjs.map +0 -1
  50. package/dist/cjs/localization/isValidLocale.cjs +0 -54
  51. package/dist/cjs/localization/isValidLocale.cjs.map +0 -1
  52. package/dist/esm/dist/esm/getStorageAttributes.mjs +0 -133
  53. package/dist/esm/dist/esm/getStorageAttributes.mjs.map +0 -1
  54. package/dist/esm/dist/esm/localization/localeResolver.mjs +0 -26
  55. package/dist/esm/dist/esm/localization/localeResolver.mjs.map +0 -1
  56. package/dist/esm/dist/esm/utils/getCookie.mjs +0 -31
  57. package/dist/esm/dist/esm/utils/getCookie.mjs.map +0 -1
  58. package/dist/esm/dist/esm/utils/localeStorage.mjs +0 -59
  59. package/dist/esm/dist/esm/utils/localeStorage.mjs.map +0 -1
  60. package/dist/esm/localization/isValidLocale.mjs +0 -52
  61. package/dist/esm/localization/isValidLocale.mjs.map +0 -1
  62. package/dist/types/localization/isValidLocale.d.ts +0 -35
  63. package/dist/types/localization/isValidLocale.d.ts.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"localeStorage.mjs","names":[],"sources":["../../../utils/localeStorage.mjs"],"sourcesContent":["import { getStorageAttributes } from \"../getStorageAttributes.mjs\";\nimport { getCookie } from \"./getCookie.mjs\";\nimport configuration from \"@intlayer/config/built\";\n\n//#region src/utils/localeStorage.ts\nconst buildCookieString = (name, value, attributes) => {\n\tconst parts = [`${name}=${encodeURIComponent(value)}`];\n\tif (attributes.path) parts.push(`Path=${attributes.path}`);\n\tif (attributes.domain) parts.push(`Domain=${attributes.domain}`);\n\tif (attributes.expires instanceof Date) parts.push(`Expires=${attributes.expires.toUTCString()}`);\n\tif (attributes.secure) parts.push(\"Secure\");\n\tif (attributes.sameSite) parts.push(`SameSite=${attributes.sameSite}`);\n\treturn parts.join(\"; \");\n};\n/**\n* Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n* The function checks storage locations in order of priority as defined in the configuration.\n*\n* @returns The locale if found in any storage, or undefined if not found\n*/\nconst getLocaleFromStorage = (options) => {\n\tconst { routing, internationalization } = configuration;\n\tconst { locales } = internationalization;\n\tconst { storage } = routing;\n\tif (storage === false || options?.isCookieEnabled === false) return void 0;\n\tconst storageAttributes = getStorageAttributes(storage);\n\tconst isValidLocale = (value) => {\n\t\tif (!value) return false;\n\t\treturn locales.includes(value);\n\t};\n\tconst readCookie = (name) => {\n\t\ttry {\n\t\t\tconst fromOption = options?.getCookie?.(name);\n\t\t\tif (fromOption !== null && fromOption !== void 0) return fromOption;\n\t\t} catch {}\n\t\treturn getCookie(name);\n\t};\n\tfor (let i = 0; i < storageAttributes.cookies.length; i++) {\n\t\tconst { name } = storageAttributes.cookies[i];\n\t\tconst value = readCookie(name);\n\t\tif (isValidLocale(value)) return value;\n\t}\n\tfor (let i = 0; i < storageAttributes.localStorage.length; i++) {\n\t\tconst { name } = storageAttributes.localStorage[i];\n\t\ttry {\n\t\t\tconst value = options?.getLocaleStorage?.(name);\n\t\t\tif (isValidLocale(value)) return value;\n\t\t} catch {}\n\t}\n\tfor (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n\t\tconst { name } = storageAttributes.sessionStorage[i];\n\t\ttry {\n\t\t\tconst value = options?.getSessionStorage?.(name);\n\t\t\tif (isValidLocale(value)) return value;\n\t\t} catch {}\n\t}\n\tfor (let i = 0; i < storageAttributes.headers.length; i++) {\n\t\tconst { name } = storageAttributes.headers[i];\n\t\ttry {\n\t\t\tconst value = options?.getHeader?.(name);\n\t\t\tif (isValidLocale(value)) return value;\n\t\t} catch {}\n\t}\n};\n/**\n* Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n* The function writes to all configured storage locations according to their attributes.\n* Respects overwrite flags for localStorage and sessionStorage.\n*\n* @param locale - The locale to store\n*/\nconst setLocaleInStorage = (locale, options) => {\n\tif (configuration.routing.storage === false || options?.isCookieEnabled === false) return;\n\tconst storageAttributes = getStorageAttributes(configuration.routing.storage);\n\tfor (let i = 0; i < storageAttributes.cookies.length; i++) {\n\t\tconst { name, attributes } = storageAttributes.cookies[i];\n\t\ttry {\n\t\t\tif (options?.setCookieStore) options?.setCookieStore?.(name, locale, {\n\t\t\t\t...attributes,\n\t\t\t\texpires: attributes.expires instanceof Date ? attributes.expires.getTime() : attributes.expires\n\t\t\t});\n\t\t} catch {\n\t\t\ttry {\n\t\t\t\tif (options?.setCookieString) {\n\t\t\t\t\tconst cookieString = buildCookieString(name, locale, attributes);\n\t\t\t\t\toptions?.setCookieString?.(name, cookieString);\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t}\n\t}\n\tif (options?.setLocaleStorage) for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n\t\tconst { name } = storageAttributes.localStorage[i];\n\t\ttry {\n\t\t\tif (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n\t\t\t\tif (options?.getLocaleStorage?.(name)) continue;\n\t\t\t}\n\t\t\toptions?.setLocaleStorage?.(name, locale);\n\t\t} catch {}\n\t}\n\tif (options?.setSessionStorage) for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n\t\tconst { name } = storageAttributes.sessionStorage[i];\n\t\ttry {\n\t\t\tif (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n\t\t\t\tif (options?.getSessionStorage?.(name)) continue;\n\t\t\t}\n\t\t\toptions?.setSessionStorage?.(name, locale);\n\t\t} catch {}\n\t}\n\tif (options?.setHeader) for (let i = 0; i < storageAttributes.headers.length; i++) {\n\t\tconst { name } = storageAttributes.headers[i];\n\t\ttry {\n\t\t\toptions?.setHeader?.(name, locale);\n\t\t} catch {}\n\t}\n};\n/**\n* Utility object to get and set the locale in the storage by considering the configuration\n*\n* @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n* Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n* The function checks storage locations in order of priority as defined in the configuration.\n*\n* @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n* The function writes to all configured storage locations according to their attributes.\n* Respects overwrite flags for localStorage and sessionStorage.\n*\n* @returns The locale if found in any storage, or undefined if not found\n*/\nconst LocaleStorage = (options) => ({\n\tgetLocale: () => getLocaleFromStorage(options),\n\tsetLocale: (locale) => setLocaleInStorage(locale, options)\n});\n\n//#endregion\nexport { LocaleStorage, getLocaleFromStorage, setLocaleInStorage };\n//# sourceMappingURL=localeStorage.mjs.map"],"mappings":";;;;;;;;;;;AAoBA,MAAM,wBAAwB,YAAY;CACzC,MAAM,EAAE,SAAS,yBAAyB;CAC1C,MAAM,EAAE,YAAY;CACpB,MAAM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
- //#region src/localization/isValidLocale.ts
6
- /**
7
- * Checks whether a given locale is valid based on the configured locales.
8
- *
9
- * @param locale - The locale value to validate. Can be `undefined` or `null`.
10
- * @param options - Optional configuration to override default settings.
11
- * @param options.locales - Array of valid locales. Defaults to the configured internationalization locales.
12
- * @param options.defaultLocale - The default locale to use as fallback. Defaults to the configured default locale.
13
- * @param options.mode - The routing mode (`'prefix'`, `'prefix-all'`, or `'no-prefix'`). Defaults to the configured routing mode.
14
- * @returns `true` if the locale is valid or if no locale is provided and the routing mode allows it; `false` otherwise.
15
- *
16
- * @example
17
- * // Check if 'en' is a valid locale
18
- * const isValid = validatePrefix('en');
19
- *
20
- * @example
21
- * // Check with custom options
22
- * const isValid = validatePrefix('fr', {
23
- * locales: ['en', 'fr', 'es'],
24
- * defaultLocale: 'en',
25
- * mode: 'prefix-all',
26
- * });
27
- */
28
- const validatePrefix = (locale, options) => {
29
- const { defaultLocale, mode, locales } = {
30
- defaultLocale: configuration?.internationalization?.defaultLocale ?? DefaultValues.Internationalization.DEFAULT_LOCALE,
31
- mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,
32
- locales: configuration?.internationalization?.locales ?? DefaultValues.Internationalization.LOCALES,
33
- ...options
34
- };
35
- const { localePrefix } = getPrefix(locale || defaultLocale, {
36
- mode,
37
- locales,
38
- defaultLocale
39
- });
40
- if (localePrefix === locale && locale === void 0) return {
41
- isValid: true,
42
- localePrefix: void 0
43
- };
44
- return {
45
- isValid: locales.some((localeEl) => localeEl === locale),
46
- localePrefix
47
- };
48
- };
49
-
50
- //#endregion
51
- export { validatePrefix };
52
- //# sourceMappingURL=isValidLocale.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isValidLocale.mjs","names":[],"sources":["../../../src/localization/isValidLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { LocalesValues } from '@intlayer/types';\nimport { getPrefix } from './getPrefix';\n\n/**\n * Checks whether a given locale is valid based on the configured locales.\n *\n * @param locale - The locale value to validate. Can be `undefined` or `null`.\n * @param options - Optional configuration to override default settings.\n * @param options.locales - Array of valid locales. Defaults to the configured internationalization locales.\n * @param options.defaultLocale - The default locale to use as fallback. Defaults to the configured default locale.\n * @param options.mode - The routing mode (`'prefix'`, `'prefix-all'`, or `'no-prefix'`). Defaults to the configured routing mode.\n * @returns `true` if the locale is valid or if no locale is provided and the routing mode allows it; `false` otherwise.\n *\n * @example\n * // Check if 'en' is a valid locale\n * const isValid = validatePrefix('en');\n *\n * @example\n * // Check with custom options\n * const isValid = validatePrefix('fr', {\n * locales: ['en', 'fr', 'es'],\n * defaultLocale: 'en',\n * mode: 'prefix-all',\n * });\n */\nexport const validatePrefix = (\n locale: LocalesValues | undefined | null,\n options?: {\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: typeof configuration.routing.mode;\n }\n): boolean => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES,\n ...options,\n };\n\n // If no locale provided (optional param), will use default\n // In `routing.mode = 'prefix-all'`, the locale is required to be a valid locale\n const { localePrefix } = getPrefix(locale || defaultLocale, {\n mode,\n locales,\n defaultLocale,\n });\n\n if (localePrefix === locale && locale === undefined) {\n return { isValid: true, localePrefix: undefined };\n }\n\n // Check if the provided locale is valid\n const isValidLocale: boolean = locales.some(\n (localeEl) => localeEl === locale\n );\n\n return { isValid: isValidLocale, localePrefix: localePrefix };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,kBACX,QACA,YAKY;CACZ,MAAM,EAAE,eAAe,MAAM,YAAY;EACvC,eACE,eAAe,sBAAsB,iBACrC,cAAc,qBAAqB;EACrC,MAAM,eAAe,SAAS,QAAQ,cAAc,QAAQ;EAC5D,SACE,eAAe,sBAAsB,WACrC,cAAc,qBAAqB;EACrC,GAAG;EACJ;CAID,MAAM,EAAE,iBAAiB,UAAU,UAAU,eAAe;EAC1D;EACA;EACA;EACD,CAAC;AAEF,KAAI,iBAAiB,UAAU,WAAW,OACxC,QAAO;EAAE,SAAS;EAAM,cAAc;EAAW;AAQnD,QAAO;EAAE,SAJsB,QAAQ,MACpC,aAAa,aAAa,OAC5B;EAE8C;EAAc"}
@@ -1,35 +0,0 @@
1
- import { LocalesValues } from "@intlayer/types";
2
- import configuration from "@intlayer/config/built";
3
-
4
- //#region src/localization/isValidLocale.d.ts
5
-
6
- /**
7
- * Checks whether a given locale is valid based on the configured locales.
8
- *
9
- * @param locale - The locale value to validate. Can be `undefined` or `null`.
10
- * @param options - Optional configuration to override default settings.
11
- * @param options.locales - Array of valid locales. Defaults to the configured internationalization locales.
12
- * @param options.defaultLocale - The default locale to use as fallback. Defaults to the configured default locale.
13
- * @param options.mode - The routing mode (`'prefix'`, `'prefix-all'`, or `'no-prefix'`). Defaults to the configured routing mode.
14
- * @returns `true` if the locale is valid or if no locale is provided and the routing mode allows it; `false` otherwise.
15
- *
16
- * @example
17
- * // Check if 'en' is a valid locale
18
- * const isValid = validatePrefix('en');
19
- *
20
- * @example
21
- * // Check with custom options
22
- * const isValid = validatePrefix('fr', {
23
- * locales: ['en', 'fr', 'es'],
24
- * defaultLocale: 'en',
25
- * mode: 'prefix-all',
26
- * });
27
- */
28
- declare const validatePrefix: (locale: LocalesValues | undefined | null, options?: {
29
- locales?: LocalesValues[];
30
- defaultLocale?: LocalesValues;
31
- mode?: typeof configuration.routing.mode;
32
- }) => boolean;
33
- //#endregion
34
- export { validatePrefix };
35
- //# sourceMappingURL=isValidLocale.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isValidLocale.d.ts","names":[],"sources":["../../../src/localization/isValidLocale.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2BA;;;;;;;;;;;;;;;;;;;;cAAa,yBACH;YAEI;kBACM;gBACF,aAAA,CAAc,OAAA,CAAQ"}