vanilla-intlayer 8.9.3 → 8.9.4-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/types/client/index.d.ts +2 -2
- package/dist/types/client/useLocale.d.ts +10 -9
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["getIntlayerClient","internationalization"],"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\
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["getIntlayerClient","internationalization"],"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 const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,aAAa,QAAwB,EAAE,KAAsB;CACxE,MAAM,SAASA,kDAAmB;CAClC,MAAM,EAAE,eAAe,SAAS,qBAC9BC,+CAAwB,EAAE;CAE5B,MAAM,aAAa,cAAmC;EACpD,IAAI,EAAE,oBAAoB,EAAE,EAAE,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;GAC7D,QAAQ,MAAM,WAAW,UAAU,qBAAqB;GACxD;;EAGF,OAAO,UAAU,UAAU;EAE3B,mDACE,WACA,MAAM,mBAAmB,OAAO,mBAAmB,KACpD;EAED,MAAM,iBAAiB,UAA6B;;CAGtD,OAAO;EACL,QAAQ,OAAO;EACA;EACf,kBAAmB,oBAAoB,EAAE;EACzC;EACA,YAAY,aAAa,OAAO,UAAU,SAAS;EACpD"}
|
|
@@ -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\
|
|
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 const { defaultLocale, locales: availableLocales } =\n internationalization ?? {};\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,aAAa,QAAwB,EAAE,KAAsB;CACxE,MAAM,SAAS,mBAAmB;CAClC,MAAM,EAAE,eAAe,SAAS,qBAC9B,wBAAwB,EAAE;CAE5B,MAAM,aAAa,cAAmC;EACpD,IAAI,EAAE,oBAAoB,EAAE,EAAE,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;GAC7D,QAAQ,MAAM,WAAW,UAAU,qBAAqB;GACxD;;EAGF,OAAO,UAAU,UAAU;EAE3B,mBACE,WACA,MAAM,mBAAmB,OAAO,mBAAmB,KACpD;EAED,MAAM,iBAAiB,UAA6B;;CAGtD,OAAO;EACL,QAAQ,OAAO;EACA;EACf,kBAAmB,oBAAoB,EAAE;EACzC;EACA,YAAY,aAAa,OAAO,UAAU,SAAS;EACpD"}
|
|
@@ -2,7 +2,7 @@ import { IntlayerClient, createIntlayerClient, getIntlayerClient, installIntlaye
|
|
|
2
2
|
import { WithOnChange, useDictionary } from "./useDictionary.js";
|
|
3
3
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
|
|
4
4
|
import { useIntlayer } from "./useIntlayer.js";
|
|
5
|
-
import { useLocale } from "./useLocale.js";
|
|
5
|
+
import { UseLocaleProps, UseLocaleResult, useLocale } from "./useLocale.js";
|
|
6
6
|
import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.js";
|
|
7
7
|
import { useRewriteURL } from "./useRewriteURL.js";
|
|
8
|
-
export { IntlayerClient, WithOnChange, createIntlayerClient, getIntlayerClient, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
|
|
8
|
+
export { IntlayerClient, UseLocaleProps, UseLocaleResult, WithOnChange, createIntlayerClient, getIntlayerClient, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
|
|
@@ -3,7 +3,14 @@ import { DeclaredLocales, LocalesValues } from "@intlayer/types/module_augmentat
|
|
|
3
3
|
//#region src/client/useLocale.d.ts
|
|
4
4
|
type UseLocaleProps = {
|
|
5
5
|
isCookieEnabled?: boolean;
|
|
6
|
-
onLocaleChange?: (locale:
|
|
6
|
+
onLocaleChange?: (locale: DeclaredLocales) => void;
|
|
7
|
+
};
|
|
8
|
+
type UseLocaleResult = {
|
|
9
|
+
locale: DeclaredLocales;
|
|
10
|
+
defaultLocale: DeclaredLocales;
|
|
11
|
+
availableLocales: DeclaredLocales[];
|
|
12
|
+
setLocale: (locale: LocalesValues) => void;
|
|
13
|
+
subscribe: (callback: (locale: LocalesValues) => void) => () => void;
|
|
7
14
|
};
|
|
8
15
|
/**
|
|
9
16
|
* Get the current locale state and locale management utilities.
|
|
@@ -32,13 +39,7 @@ type UseLocaleProps = {
|
|
|
32
39
|
* });
|
|
33
40
|
* ```
|
|
34
41
|
*/
|
|
35
|
-
declare const useLocale: (props?: UseLocaleProps) =>
|
|
36
|
-
locale: DeclaredLocales;
|
|
37
|
-
defaultLocale: DeclaredLocales;
|
|
38
|
-
availableLocales: DeclaredLocales[];
|
|
39
|
-
setLocale: (newLocale: LocalesValues) => void;
|
|
40
|
-
subscribe: (callback: (locale: LocalesValues) => void) => () => void;
|
|
41
|
-
};
|
|
42
|
+
declare const useLocale: (props?: UseLocaleProps) => UseLocaleResult;
|
|
42
43
|
//#endregion
|
|
43
|
-
export { useLocale };
|
|
44
|
+
export { UseLocaleProps, UseLocaleResult, useLocale };
|
|
44
45
|
//# sourceMappingURL=useLocale.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;;KAQY,cAAA;EACV,eAAA;EACA,cAAA,IAAkB,MAAA,EAAQ,eAAA;AAAA;AAAA,KAGhB,eAAA;EACV,MAAA,EAAQ,eAAA;EACR,aAAA,EAAe,eAAA;EACf,gBAAA,EAAkB,eAAA;EAClB,SAAA,GAAY,MAAA,EAAQ,aAAA;EACpB,SAAA,GAAY,QAAA,GAAW,MAAA,EAAQ,aAAA;AAAA;;AALjC;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;cAAa,SAAA,GAAa,KAAA,GAAO,cAAA,KAAsB,eAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { DeepTransformContent, HTMLPluginCond, IInterpreterPluginState, IInterpr
|
|
|
3
3
|
import { WithOnChange, useDictionary } from "./client/useDictionary.js";
|
|
4
4
|
import { useDictionaryDynamic } from "./client/useDictionaryDynamic.js";
|
|
5
5
|
import { useIntlayer } from "./client/useIntlayer.js";
|
|
6
|
-
import { useLocale } from "./client/useLocale.js";
|
|
6
|
+
import { UseLocaleProps, UseLocaleResult, useLocale } from "./client/useLocale.js";
|
|
7
7
|
import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./client/useLocaleStorage.js";
|
|
8
8
|
import { useRewriteURL } from "./client/useRewriteURL.js";
|
|
9
9
|
import { useEditor } from "./editor/useEditor.js";
|
|
@@ -16,5 +16,5 @@ declare module '@intlayer/core/interpreter' {
|
|
|
16
16
|
interface IInterpreterPlugin<T, S, L extends LocalesValues> extends IInterpreterPluginVanilla<T, S, L> {}
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
|
-
export { DeepTransformContent, HTMLPluginCond, IInterpreterPluginState, IInterpreterPluginVanilla, InsertionCond, IntlayerClient, IntlayerNode, IntlayerNodeCond, MarkdownCond, MarkdownStringCond, WithOnChange, createIntlayerClient, getDictionary, getIntlayer, getIntlayerClient, getPlugins, htmlPlugin, insertionPlugin, installIntlayer, intlayerNodePlugins, localeCookie, localeInStorage, markdownPlugin, markdownStringPlugin, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useEditor, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
|
|
19
|
+
export { DeepTransformContent, HTMLPluginCond, IInterpreterPluginState, IInterpreterPluginVanilla, InsertionCond, IntlayerClient, IntlayerNode, IntlayerNodeCond, MarkdownCond, MarkdownStringCond, UseLocaleProps, UseLocaleResult, WithOnChange, createIntlayerClient, getDictionary, getIntlayer, getIntlayerClient, getPlugins, htmlPlugin, insertionPlugin, installIntlayer, intlayerNodePlugins, localeCookie, localeInStorage, markdownPlugin, markdownStringPlugin, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useEditor, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vanilla-intlayer",
|
|
3
|
-
"version": "8.9.
|
|
3
|
+
"version": "8.9.4-canary.0",
|
|
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": "8.9.
|
|
105
|
-
"@intlayer/config": "8.9.
|
|
106
|
-
"@intlayer/core": "8.9.
|
|
107
|
-
"@intlayer/editor": "8.9.
|
|
108
|
-
"@intlayer/types": "8.9.
|
|
104
|
+
"@intlayer/api": "8.9.4-canary.0",
|
|
105
|
+
"@intlayer/config": "8.9.4-canary.0",
|
|
106
|
+
"@intlayer/core": "8.9.4-canary.0",
|
|
107
|
+
"@intlayer/editor": "8.9.4-canary.0",
|
|
108
|
+
"@intlayer/types": "8.9.4-canary.0"
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
|
-
"@types/node": "25.6.
|
|
111
|
+
"@types/node": "25.6.2",
|
|
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": "4.1.5"
|
|
119
119
|
},
|
|
120
120
|
"peerDependencies": {
|
|
121
|
-
"intlayer": "8.9.
|
|
121
|
+
"intlayer": "8.9.4-canary.0"
|
|
122
122
|
},
|
|
123
123
|
"peerDependenciesMeta": {
|
|
124
124
|
"intlayer": {
|