vanilla-intlayer 9.4.4 → 9.5.2
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/README.md +0 -2
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +3 -3
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -69,8 +69,6 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
|
|
|
69
69
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) <br> - [Intlayer compat adapters](https://intlayer.org/doc/compatibility) |
|
|
70
70
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
|
|
71
71
|
|
|
72
|
-
---
|
|
73
|
-
|
|
74
72
|
## 📦 Installation
|
|
75
73
|
|
|
76
74
|
Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
|
|
@@ -4,6 +4,7 @@ const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
|
4
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
5
|
|
|
6
6
|
//#region src/client/useLocale.ts
|
|
7
|
+
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
|
|
7
8
|
/**
|
|
8
9
|
* Get the current locale state and locale management utilities.
|
|
9
10
|
*
|
|
@@ -33,7 +34,6 @@ let _intlayer_config_built = require("@intlayer/config/built");
|
|
|
33
34
|
*/
|
|
34
35
|
const useLocale = (props = {}) => {
|
|
35
36
|
const client = require_client_installIntlayer.getIntlayerClient();
|
|
36
|
-
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
|
|
37
37
|
const setLocale = (newLocale) => {
|
|
38
38
|
if (!(availableLocales ?? []).map(String).includes(newLocale)) {
|
|
39
39
|
console.error(`Locale "${newLocale}" is not available.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["internationalization","getIntlayerClient"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayerClient } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n subscribe: (callback: (locale: LocalesValues) => void) => () => void;\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization ?? {};\n\n/**\n * Get the current locale state and locale management utilities.\n *\n * Returns a plain object with the current `locale`, `defaultLocale`,\n * `availableLocales`, a `setLocale` function, and a `subscribe` function\n * to react to locale changes.\n *\n * @param props - Optional configuration.\n * @returns Locale state and management utilities.\n *\n * @example\n * ```ts\n * import { installIntlayer, useLocale } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const { locale, availableLocales, setLocale, subscribe } = useLocale();\n *\n * const unsubscribe = subscribe((newLocale) => {\n * console.log('Locale changed to', newLocale);\n * });\n *\n * document.querySelector('#lang-switcher').addEventListener('change', (e) => {\n * setLocale(e.target.value);\n * });\n * ```\n */\nexport const useLocale = (props: UseLocaleProps = {}): UseLocaleResult => {\n const client = getIntlayerClient();\n\n const setLocale = (newLocale: LocalesValues): void => {\n if (!(availableLocales ?? []).map(String).includes(newLocale)) {\n console.error(`Locale \"${newLocale}\" is not available.`);\n return;\n }\n\n client.setLocale(newLocale);\n\n setLocaleInStorage(\n newLocale,\n props.isCookieEnabled ?? client.isCookieEnabled ?? true\n );\n\n props.onLocaleChange?.(newLocale as DeclaredLocales);\n };\n\n return {\n locale: client.locale as DeclaredLocales,\n defaultLocale: defaultLocale as DeclaredLocales,\n availableLocales: (availableLocales ?? []) as DeclaredLocales[],\n setLocale,\n subscribe: (callback) => client.subscribe(callback),\n };\n};\n"],"mappings":";;;;;;AAqBA,MAAM,EAAE,eAAe,SAAS,qBAAqBA,+CAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6B9E,MAAa,aAAa,QAAwB,CAAC,MAAuB;CACxE,MAAM,SAASC,iDAAkB;CAEjC,MAAM,aAAa,cAAmC;EACpD,IAAI,EAAE,oBAAoB,CAAC,EAAC,CAAE,IAAI,MAAM,CAAC,CAAC,SAAS,SAAS,GAAG;GAC7D,QAAQ,MAAM,WAAW,UAAU,oBAAoB;GACvD;EACF;EAEA,OAAO,UAAU,SAAS;EAE1B,mDACE,WACA,MAAM,mBAAmB,OAAO,mBAAmB,IACrD;EAEA,MAAM,iBAAiB,SAA4B;CACrD;CAEA,OAAO;EACL,QAAQ,OAAO;EACA;EACf,kBAAmB,oBAAoB,CAAC;EACxC;EACA,YAAY,aAAa,OAAO,UAAU,QAAQ;CACpD;AACF"}
|
|
@@ -3,6 +3,7 @@ import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
|
3
3
|
import { internationalization } from "@intlayer/config/built";
|
|
4
4
|
|
|
5
5
|
//#region src/client/useLocale.ts
|
|
6
|
+
const { defaultLocale, locales: availableLocales } = internationalization ?? {};
|
|
6
7
|
/**
|
|
7
8
|
* Get the current locale state and locale management utilities.
|
|
8
9
|
*
|
|
@@ -32,7 +33,6 @@ import { internationalization } from "@intlayer/config/built";
|
|
|
32
33
|
*/
|
|
33
34
|
const useLocale = (props = {}) => {
|
|
34
35
|
const client = getIntlayerClient();
|
|
35
|
-
const { defaultLocale, locales: availableLocales } = internationalization ?? {};
|
|
36
36
|
const setLocale = (newLocale) => {
|
|
37
37
|
if (!(availableLocales ?? []).map(String).includes(newLocale)) {
|
|
38
38
|
console.error(`Locale "${newLocale}" is not available.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayerClient } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n subscribe: (callback: (locale: LocalesValues) => void) => () => void;\n};\n\n/**\n * Get the current locale state and locale management utilities.\n *\n * Returns a plain object with the current `locale`, `defaultLocale`,\n * `availableLocales`, a `setLocale` function, and a `subscribe` function\n * to react to locale changes.\n *\n * @param props - Optional configuration.\n * @returns Locale state and management utilities.\n *\n * @example\n * ```ts\n * import { installIntlayer, useLocale } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const { locale, availableLocales, setLocale, subscribe } = useLocale();\n *\n * const unsubscribe = subscribe((newLocale) => {\n * console.log('Locale changed to', newLocale);\n * });\n *\n * document.querySelector('#lang-switcher').addEventListener('change', (e) => {\n * setLocale(e.target.value);\n * });\n * ```\n */\nexport const useLocale = (props: UseLocaleProps = {}): UseLocaleResult => {\n const client = getIntlayerClient();\n
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayerClient } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n subscribe: (callback: (locale: LocalesValues) => void) => () => void;\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization ?? {};\n\n/**\n * Get the current locale state and locale management utilities.\n *\n * Returns a plain object with the current `locale`, `defaultLocale`,\n * `availableLocales`, a `setLocale` function, and a `subscribe` function\n * to react to locale changes.\n *\n * @param props - Optional configuration.\n * @returns Locale state and management utilities.\n *\n * @example\n * ```ts\n * import { installIntlayer, useLocale } from 'vanilla-intlayer';\n *\n * installIntlayer('en');\n *\n * const { locale, availableLocales, setLocale, subscribe } = useLocale();\n *\n * const unsubscribe = subscribe((newLocale) => {\n * console.log('Locale changed to', newLocale);\n * });\n *\n * document.querySelector('#lang-switcher').addEventListener('change', (e) => {\n * setLocale(e.target.value);\n * });\n * ```\n */\nexport const useLocale = (props: UseLocaleProps = {}): UseLocaleResult => {\n const client = getIntlayerClient();\n\n const setLocale = (newLocale: LocalesValues): void => {\n if (!(availableLocales ?? []).map(String).includes(newLocale)) {\n console.error(`Locale \"${newLocale}\" is not available.`);\n return;\n }\n\n client.setLocale(newLocale);\n\n setLocaleInStorage(\n newLocale,\n props.isCookieEnabled ?? client.isCookieEnabled ?? true\n );\n\n props.onLocaleChange?.(newLocale as DeclaredLocales);\n };\n\n return {\n locale: client.locale as DeclaredLocales,\n defaultLocale: defaultLocale as DeclaredLocales,\n availableLocales: (availableLocales ?? []) as DeclaredLocales[],\n setLocale,\n subscribe: (callback) => client.subscribe(callback),\n };\n};\n"],"mappings":";;;;;AAqBA,MAAM,EAAE,eAAe,SAAS,qBAAqB,wBAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6B9E,MAAa,aAAa,QAAwB,CAAC,MAAuB;CACxE,MAAM,SAAS,kBAAkB;CAEjC,MAAM,aAAa,cAAmC;EACpD,IAAI,EAAE,oBAAoB,CAAC,EAAC,CAAE,IAAI,MAAM,CAAC,CAAC,SAAS,SAAS,GAAG;GAC7D,QAAQ,MAAM,WAAW,UAAU,oBAAoB;GACvD;EACF;EAEA,OAAO,UAAU,SAAS;EAE1B,mBACE,WACA,MAAM,mBAAmB,OAAO,mBAAmB,IACrD;EAEA,MAAM,iBAAiB,SAA4B;CACrD;CAEA,OAAO;EACL,QAAQ,OAAO;EACA;EACf,kBAAmB,oBAAoB,CAAC;EACxC;EACA,YAAY,aAAa,OAAO,UAAU,QAAQ;CACpD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;YAQY;EACV;EACA,kBAAkB,QAAQ;;YAGhB;EACV,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,YAAY,QAAQ;EACpB,YAAY,WAAW,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;YAQY;EACV;EACA,kBAAkB,QAAQ;;YAGhB;EACV,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,YAAY,QAAQ;EACpB,YAAY,WAAW,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgCpB,YAAS,QAAW,mBAAsB"}
|
|
@@ -3,11 +3,11 @@ import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
|
3
3
|
/**
|
|
4
4
|
* Get the current locale from storage (cookie or localStorage).
|
|
5
5
|
*/
|
|
6
|
-
export declare const localeInStorage: import("
|
|
6
|
+
export declare const localeInStorage: import("intlayer").Locale;
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated Use localeInStorage instead.
|
|
9
9
|
*/
|
|
10
|
-
export declare const localeCookie: import("
|
|
10
|
+
export declare const localeCookie: import("intlayer").Locale;
|
|
11
11
|
/**
|
|
12
12
|
* Persist the locale to storage (cookie and/or localStorage).
|
|
13
13
|
*/
|
|
@@ -20,7 +20,7 @@ export declare const setLocaleCookie: typeof setLocaleInStorage;
|
|
|
20
20
|
* Returns the current locale from storage and a setter.
|
|
21
21
|
*/
|
|
22
22
|
export declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
|
|
23
|
-
localeStorage: import("
|
|
23
|
+
localeStorage: import("intlayer").Locale;
|
|
24
24
|
setLocaleStorage: (locale: LocalesValues) => void;
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.d.ts","names":[],"sources":["../../../src/client/useLocaleStorage.ts"],"mappings":";;;;;qBAWa,
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.d.ts","names":[],"sources":["../../../src/client/useLocaleStorage.ts"],"mappings":";;;;;qBAWa,oCAAe;;;;qBAKf,iCAAY;;;;qBAKZ,qBAAkB,QACrB,eAAa;;;;qBAWV,wBAAe;;;;qBAKf,mBAAgB;EAOzB,kCAAa;EACb,mBAAgB,QAAA;;;;;qBAOP,wBAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vanilla-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Vanilla JS, HTML, and PHP applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -101,14 +101,14 @@
|
|
|
101
101
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@intlayer/api": "9.
|
|
105
|
-
"@intlayer/config": "9.
|
|
106
|
-
"@intlayer/core": "9.
|
|
107
|
-
"@intlayer/editor": "9.
|
|
108
|
-
"@intlayer/types": "9.
|
|
104
|
+
"@intlayer/api": "9.5.2",
|
|
105
|
+
"@intlayer/config": "9.5.2",
|
|
106
|
+
"@intlayer/core": "9.5.2",
|
|
107
|
+
"@intlayer/editor": "9.5.2",
|
|
108
|
+
"@intlayer/types": "9.5.2"
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
|
-
"@types/node": "
|
|
111
|
+
"@types/node": "^22",
|
|
112
112
|
"@utils/ts-config": "1.0.4",
|
|
113
113
|
"@utils/ts-config-types": "1.0.4",
|
|
114
114
|
"@utils/tsdown-config": "1.0.4",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"vitest": "5.0.0"
|
|
119
119
|
},
|
|
120
120
|
"peerDependencies": {
|
|
121
|
-
"intlayer": "9.
|
|
121
|
+
"intlayer": "9.5.2"
|
|
122
122
|
},
|
|
123
123
|
"peerDependenciesMeta": {
|
|
124
124
|
"intlayer": {
|