preact-intlayer 9.4.4 → 9.5.1
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/useLocaleBase.d.ts +2 -2
- package/package.json +9 -9
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.
|
|
@@ -5,6 +5,7 @@ let _intlayer_config_built = require("@intlayer/config/built");
|
|
|
5
5
|
let preact_hooks = require("preact/hooks");
|
|
6
6
|
|
|
7
7
|
//#region src/client/useLocale.ts
|
|
8
|
+
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
|
|
8
9
|
/**
|
|
9
10
|
* Preact hook to get the current locale and related locale management functions.
|
|
10
11
|
*
|
|
@@ -29,7 +30,6 @@ let preact_hooks = require("preact/hooks");
|
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
32
|
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
32
|
-
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
|
|
33
33
|
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
34
34
|
const setLocale = (locale) => {
|
|
35
35
|
if (!availableLocales?.map(String).includes(locale)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["internationalization","useContext","IntlayerClientContext"],"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 { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const {
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["internationalization","useContext","IntlayerClientContext"],"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 { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization ?? {};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext) ?? {};\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale as DeclaredLocales);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;AAqBA,MAAM,EAAE,eAAe,SAAS,qBAAqBA,+CAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAyB9E,MAAa,aAAa,EACxB,iBACA,mBACkB,CAAC,MAAuB;CAC1C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,+BACfC,yBAAWC,qDAAqB,KAAK,CAAC;CAE1C,MAAM,aAAa,WAA0B;EAC3C,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG;GACnD,QAAQ,MAAM,UAAU,OAAO,kBAAkB;GACjD;EACF;EAEA,eAAe,MAAM;EAErB,mDACE,QACA,mBAAmB,0BAA0B,IAC/C;EAEA,iBAAiB,MAAyB;CAC5C;CAEA,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -4,6 +4,7 @@ import { internationalization } from "@intlayer/config/built";
|
|
|
4
4
|
import { useContext } from "preact/hooks";
|
|
5
5
|
|
|
6
6
|
//#region src/client/useLocale.ts
|
|
7
|
+
const { defaultLocale, locales: availableLocales } = internationalization ?? {};
|
|
7
8
|
/**
|
|
8
9
|
* Preact hook to get the current locale and related locale management functions.
|
|
9
10
|
*
|
|
@@ -28,7 +29,6 @@ import { useContext } from "preact/hooks";
|
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
31
|
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
31
|
-
const { defaultLocale, locales: availableLocales } = internationalization ?? {};
|
|
32
32
|
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = useContext(IntlayerClientContext) ?? {};
|
|
33
33
|
const setLocale = (locale) => {
|
|
34
34
|
if (!availableLocales?.map(String).includes(locale)) {
|
|
@@ -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 { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const {
|
|
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 { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n};\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n setLocale: (locale: LocalesValues) => void;\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization ?? {};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext) ?? {};\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale as DeclaredLocales);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;AAqBA,MAAM,EAAE,eAAe,SAAS,qBAAqB,wBAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAyB9E,MAAa,aAAa,EACxB,iBACA,mBACkB,CAAC,MAAuB;CAC1C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,2BACf,WAAW,qBAAqB,KAAK,CAAC;CAE1C,MAAM,aAAa,WAA0B;EAC3C,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG;GACnD,QAAQ,MAAM,UAAU,OAAO,kBAAkB;GACjD;EACF;EAEA,eAAe,MAAM;EAErB,mBACE,QACA,mBAAmB,0BAA0B,IAC/C;EAEA,iBAAiB,MAAyB;CAC5C;CAEA,OAAO;EACL;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;KASK;EACH;EACA,kBAAkB,QAAQ;;KAGvB;EACH,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;KASK;EACH;EACA,kBAAkB,QAAQ;;KAGvB;EACH,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;qBA4BT,cAAS,iBAAA,mBAGnB,mBAAsB"}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const useLocaleBase: () => {
|
|
6
6
|
locale: import("@intlayer/types").LocalesValues;
|
|
7
|
-
defaultLocale:
|
|
8
|
-
availableLocales:
|
|
7
|
+
defaultLocale: import("@intlayer/types").Locale;
|
|
8
|
+
availableLocales: import("@intlayer/types").Locale[];
|
|
9
9
|
setLocale: (newLocale: import("@intlayer/types").LocalesValues) => void;
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Preact applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -100,15 +100,15 @@
|
|
|
100
100
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@intlayer/api": "9.
|
|
104
|
-
"@intlayer/config": "9.
|
|
105
|
-
"@intlayer/core": "9.
|
|
106
|
-
"@intlayer/editor": "9.
|
|
107
|
-
"@intlayer/engine": "9.
|
|
108
|
-
"@intlayer/types": "9.
|
|
103
|
+
"@intlayer/api": "9.5.1",
|
|
104
|
+
"@intlayer/config": "9.5.1",
|
|
105
|
+
"@intlayer/core": "9.5.1",
|
|
106
|
+
"@intlayer/editor": "9.5.1",
|
|
107
|
+
"@intlayer/engine": "9.5.1",
|
|
108
|
+
"@intlayer/types": "9.5.1"
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
|
-
"@types/node": "26.
|
|
111
|
+
"@types/node": "26.5.0",
|
|
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",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"preact": ">=8.0.0"
|
|
123
123
|
},
|
|
124
124
|
"optionalDependencies": {
|
|
125
|
-
"@intlayer/analytics": "9.
|
|
125
|
+
"@intlayer/analytics": "9.5.1"
|
|
126
126
|
},
|
|
127
127
|
"engines": {
|
|
128
128
|
"node": ">=14.18"
|