preact-intlayer 5.7.6-canary.0 → 5.7.7
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 +3 -0
- package/dist/cjs/client/index.cjs +0 -3
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +4 -2
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +19 -2
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +4 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +4 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +4 -1
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/index.cjs +0 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/client/index.mjs +0 -2
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +5 -3
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +10 -3
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +5 -2
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +5 -3
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +5 -2
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/client/index.d.ts +0 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useTraduction.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +11 -11
- package/dist/cjs/client/useIntlayerAsync.cjs +0 -54
- package/dist/cjs/client/useIntlayerAsync.cjs.map +0 -1
- package/dist/esm/client/useIntlayerAsync.mjs +0 -33
- package/dist/esm/client/useIntlayerAsync.mjs.map +0 -1
- package/dist/types/client/useIntlayerAsync.d.ts +0 -14
- package/dist/types/client/useIntlayerAsync.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
<div>
|
|
28
28
|
<br/>
|
|
29
29
|
<p align="center">
|
|
30
|
+
<a href="https://discord.gg/528mBV4N" target="blank"><img align="center"
|
|
31
|
+
src="https://img.shields.io/badge/discord-5865F2.svg?style=for-the-badge&logo=discord&logoColor=white"
|
|
32
|
+
alt="Intlayer Discord" height="30"/></a>
|
|
30
33
|
<a href="https://www.linkedin.com/company/intlayerorg" target="blank"><img align="center"
|
|
31
34
|
src="https://img.shields.io/badge/linkedin-%231DA1F2.svg?style=for-the-badge&logo=linkedin&logoColor=white"
|
|
32
35
|
alt="Intlayer LinkedIn" height="30"/></a>
|
|
@@ -29,7 +29,6 @@ __export(client_exports, {
|
|
|
29
29
|
useDictionaryAsync: () => import_useDictionaryAsync.useDictionaryAsync,
|
|
30
30
|
useDictionaryDynamic: () => import_useDictionaryDynamic.useDictionaryDynamic,
|
|
31
31
|
useIntlayer: () => import_useIntlayer.useIntlayer,
|
|
32
|
-
useIntlayerAsync: () => import_useIntlayerAsync.useIntlayerAsync,
|
|
33
32
|
useIntlayerContext: () => import_IntlayerProvider.useIntlayerContext,
|
|
34
33
|
useLoadDynamic: () => import_useLoadDynamic.useLoadDynamic,
|
|
35
34
|
useLocale: () => import_useLocale.useLocale,
|
|
@@ -44,7 +43,6 @@ var import_useDictionary = require('./useDictionary.cjs');
|
|
|
44
43
|
var import_useDictionaryAsync = require('./useDictionaryAsync.cjs');
|
|
45
44
|
var import_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
46
45
|
var import_useIntlayer = require('./useIntlayer.cjs');
|
|
47
|
-
var import_useIntlayerAsync = require('./useIntlayerAsync.cjs');
|
|
48
46
|
var import_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
49
47
|
var import_useLocale = require('./useLocale.cjs');
|
|
50
48
|
var import_useLocaleBase = require('./useLocaleBase.cjs');
|
|
@@ -62,7 +60,6 @@ var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
|
62
60
|
useDictionaryAsync,
|
|
63
61
|
useDictionaryDynamic,
|
|
64
62
|
useIntlayer,
|
|
65
|
-
useIntlayerAsync,
|
|
66
63
|
useIntlayerContext,
|
|
67
64
|
useLoadDynamic,
|
|
68
65
|
useLocale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export { getBrowserLocale } from './getBrowserLocale';\nexport {\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n useIntlayerContext,\n type IntlayerProviderProps,\n} from './IntlayerProvider';\nexport { t } from './t';\nexport { useDictionary } from './useDictionary';\nexport { useDictionaryAsync } from './useDictionaryAsync';\nexport { useDictionaryDynamic } from './useDictionaryDynamic';\nexport { useIntlayer } from './useIntlayer';\nexport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export { getBrowserLocale } from './getBrowserLocale';\nexport {\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n useIntlayerContext,\n type IntlayerProviderProps,\n} from './IntlayerProvider';\nexport { t } from './t';\nexport { useDictionary } from './useDictionary';\nexport { useDictionaryAsync } from './useDictionaryAsync';\nexport { useDictionaryDynamic } from './useDictionaryDynamic';\nexport { useIntlayer } from './useIntlayer';\nexport { useLoadDynamic } from './useLoadDynamic';\nexport { useLocale } from './useLocale';\nexport { useLocaleBase } from './useLocaleBase';\nexport {\n localeCookie,\n setLocaleCookie,\n useLocaleCookie,\n} from './useLocaleCookie';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAiC;AACjC,8BAMO;AACP,eAAkB;AAClB,2BAA8B;AAC9B,gCAAmC;AACnC,kCAAqC;AACrC,yBAA4B;AAC5B,4BAA+B;AAC/B,uBAA0B;AAC1B,2BAA8B;AAC9B,6BAIO;","names":[]}
|
|
@@ -27,8 +27,10 @@ var import_getDictionary = require('../getDictionary.cjs');
|
|
|
27
27
|
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
28
28
|
const useDictionary = (dictionary, locale) => {
|
|
29
29
|
const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
return (0, import_hooks.useMemo)(() => {
|
|
31
|
+
const localeTarget = locale ?? currentLocale;
|
|
32
|
+
return (0, import_getDictionary.getDictionary)(dictionary, localeTarget);
|
|
33
|
+
}, [dictionary, currentLocale, locale]);
|
|
32
34
|
};
|
|
33
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
36
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, LocalesValues>(dictionary, localeTarget);\n }, [dictionary, currentLocale, locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAoC;AACpC,2BAA8B;AAC9B,8BAAsC;AAO/B,MAAM,gBAAgB,CAC3B,YACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAElE,aAAO,sBAAQ,MAAM;AACnB,UAAM,eAAe,UAAU;AAE/B,eAAO,oCAAgC,YAAY,YAAY;AAAA,EACjE,GAAG,CAAC,YAAY,eAAe,MAAM,CAAC;AACxC;","names":[]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
9
|
var __export = (target, all) => {
|
|
8
10
|
for (var name in all)
|
|
@@ -16,19 +18,34 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
}
|
|
17
19
|
return to;
|
|
18
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
19
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
30
|
var useDictionaryAsync_exports = {};
|
|
21
31
|
__export(useDictionaryAsync_exports, {
|
|
22
32
|
useDictionaryAsync: () => useDictionaryAsync
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(useDictionaryAsync_exports);
|
|
35
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
25
36
|
var import_hooks = require("preact/hooks");
|
|
26
37
|
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
27
38
|
var import_useDictionary = require('./useDictionary.cjs');
|
|
28
39
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
29
40
|
const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
30
|
-
const localeTarget =
|
|
31
|
-
|
|
41
|
+
const localeTarget = (0, import_hooks.useMemo)(
|
|
42
|
+
() => locale ?? currentLocale ?? import_built.default?.internationalization.defaultLocale,
|
|
43
|
+
[currentLocale, locale]
|
|
44
|
+
);
|
|
45
|
+
const dictionary = await (0, import_hooks.useMemo)(
|
|
46
|
+
async () => await dictionaryPromise[localeTarget](),
|
|
47
|
+
[dictionaryPromise, localeTarget]
|
|
48
|
+
);
|
|
32
49
|
return (0, import_useDictionary.useDictionary)(dictionary, localeTarget);
|
|
33
50
|
};
|
|
34
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary, LanguageContent } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary, LanguageContent } from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () => (await dictionaryPromise[localeTarget]!()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAG1B,mBAAoC;AACpC,8BAAsC;AACtC,2BAA8B;AAOvB,MAAM,qBAAqB,OAChC,mBACA,WACe;AACf,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAElE,QAAM,mBAAe;AAAA,IACnB,MACE,UACA,iBACA,aAAAA,SAAe,qBAAqB;AAAA,IACtC,CAAC,eAAe,MAAM;AAAA,EACxB;AAEA,QAAM,aAAa,UAAM;AAAA,IACvB,YAAa,MAAM,kBAAkB,YAAY,EAAG;AAAA,IACpD,CAAC,mBAAmB,YAAY;AAAA,EAClC;AAEA,aAAO,oCAAc,YAAY,YAAY;AAC/C;","names":["configuration"]}
|
|
@@ -28,7 +28,10 @@ var import_useDictionary = require('./useDictionary.cjs');
|
|
|
28
28
|
var import_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
29
29
|
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
30
30
|
const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
31
|
-
const localeTarget =
|
|
31
|
+
const localeTarget = (0, import_hooks.useMemo)(
|
|
32
|
+
() => locale ?? currentLocale,
|
|
33
|
+
[currentLocale, locale]
|
|
34
|
+
);
|
|
32
35
|
const dictionary = (0, import_useLoadDynamic.useLoadDynamic)(
|
|
33
36
|
`${String(key)}.${localeTarget}`,
|
|
34
37
|
dictionaryPromise[localeTarget]()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type {\n Dictionary,\n DictionaryKeys,\n LanguageContent,\n} from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n dictionaryPromise[localeTarget]!()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type {\n Dictionary,\n DictionaryKeys,\n LanguageContent,\n} from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n dictionaryPromise[localeTarget]!()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,mBAAoC;AACpC,8BAAsC;AACtC,2BAA8B;AAC9B,4BAA+B;AAOxB,MAAM,uBAAuB,CAIlC,mBACA,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,mBAAe;AAAA,IACnB,MAAM,UAAU;AAAA,IAChB,CAAC,eAAe,MAAM;AAAA,EACxB;AAEA,QAAM,iBAAa;AAAA,IACjB,GAAG,OAAO,GAAG,CAAC,IAAI,YAAY;AAAA,IAC9B,kBAAkB,YAAY,EAAG;AAAA,EACnC;AAEA,aAAO,oCAAc,YAAY,YAAY;AAC/C;","names":[]}
|
|
@@ -27,8 +27,10 @@ var import_getIntlayer = require('../getIntlayer.cjs');
|
|
|
27
27
|
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
28
28
|
const useIntlayer = (key, locale) => {
|
|
29
29
|
const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
return (0, import_hooks.useMemo)(() => {
|
|
31
|
+
const localeTarget = locale ?? currentLocale;
|
|
32
|
+
return (0, import_getIntlayer.getIntlayer)(key, localeTarget);
|
|
33
|
+
}, [key, currentLocale, locale]);
|
|
32
34
|
};
|
|
33
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
36
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { DictionaryKeys } from '@intlayer/core';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { useContext } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content']> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { DictionaryKeys } from '@intlayer/core';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content']> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getIntlayer(key, localeTarget) as any;\n }, [key, currentLocale, locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,mBAAoC;AACpC,yBAA4B;AAE5B,8BAAsC;AAO/B,MAAM,cAAc,CACzB,KACA,WACyE;AACzE,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAElE,aAAO,sBAAQ,MAAM;AACnB,UAAM,eAAe,UAAU;AAE/B,eAAO,gCAAY,KAAK,YAAY;AAAA,EACtC,GAAG,CAAC,KAAK,eAAe,MAAM,CAAC;AACjC;","names":[]}
|
|
@@ -26,7 +26,10 @@ var import_hooks = require("preact/hooks");
|
|
|
26
26
|
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
27
27
|
const useTranslation = (languageContent) => {
|
|
28
28
|
const { locale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
29
|
-
return (0,
|
|
29
|
+
return (0, import_hooks.useMemo)(
|
|
30
|
+
() => (0, import_core.getTranslation)(languageContent, locale),
|
|
31
|
+
[languageContent, locale]
|
|
32
|
+
);
|
|
30
33
|
};
|
|
31
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
35
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation, type LanguageContent } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqD;AACrD,
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation, type LanguageContent } from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqD;AACrD,mBAAoC;AACpC,8BAAsC;AAuB/B,MAAM,iBAAiB,CAC5B,oBACY;AACZ,QAAM,EAAE,OAAO,QAAI,yBAAW,6CAAqB;AAEnD,aAAO;AAAA,IACL,UAAM,4BAAe,iBAAiB,MAAM;AAAA,IAC5C,CAAC,iBAAiB,MAAM;AAAA,EAC1B;AACF;","names":[]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -30,7 +30,6 @@ __export(index_exports, {
|
|
|
30
30
|
useDictionaryAsync: () => import_client.useDictionaryAsync,
|
|
31
31
|
useDictionaryDynamic: () => import_client.useDictionaryDynamic,
|
|
32
32
|
useIntlayer: () => import_client.useIntlayer,
|
|
33
|
-
useIntlayerAsync: () => import_client.useIntlayerAsync,
|
|
34
33
|
useIntlayerContext: () => import_client.useIntlayerContext,
|
|
35
34
|
useLoadDynamic: () => import_client.useLoadDynamic,
|
|
36
35
|
useLocale: () => import_client.useLocale,
|
|
@@ -54,7 +53,6 @@ var import_markdown = require('./markdown/index.cjs');
|
|
|
54
53
|
useDictionaryAsync,
|
|
55
54
|
useDictionaryDynamic,
|
|
56
55
|
useIntlayer,
|
|
57
|
-
useIntlayerAsync,
|
|
58
56
|
useIntlayerContext,
|
|
59
57
|
useLoadDynamic,
|
|
60
58
|
useLocale,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import type { IInterpreterPluginPreact } from './plugins';\n\ndeclare module '@intlayer/core' {\n interface IInterpreterPlugin<T, S> extends IInterpreterPluginPreact<T> {}\n}\n\nexport {\n getBrowserLocale,\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n localeCookie,\n setLocaleCookie,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useIntlayer,\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import type { IInterpreterPluginPreact } from './plugins';\n\ndeclare module '@intlayer/core' {\n interface IInterpreterPlugin<T, S> extends IInterpreterPluginPreact<T> {}\n}\n\nexport {\n getBrowserLocale,\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n localeCookie,\n setLocaleCookie,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useIntlayer,\n useIntlayerContext,\n useLoadDynamic,\n useLocale,\n useLocaleBase,\n useLocaleCookie,\n type IntlayerProviderProps,\n} from './client/index';\nexport { type IntlayerNode } from './IntlayerNode';\nexport { MarkdownProvider } from './markdown/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,oBAkBO;AAEP,sBAAiC;","names":[]}
|
|
@@ -10,7 +10,6 @@ import { useDictionary } from "./useDictionary.mjs";
|
|
|
10
10
|
import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
|
|
11
11
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
12
12
|
import { useIntlayer } from "./useIntlayer.mjs";
|
|
13
|
-
import { useIntlayerAsync } from "./useIntlayerAsync.mjs";
|
|
14
13
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
15
14
|
import { useLocale } from "./useLocale.mjs";
|
|
16
15
|
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
@@ -31,7 +30,6 @@ export {
|
|
|
31
30
|
useDictionaryAsync,
|
|
32
31
|
useDictionaryDynamic,
|
|
33
32
|
useIntlayer,
|
|
34
|
-
useIntlayerAsync,
|
|
35
33
|
useIntlayerContext,
|
|
36
34
|
useLoadDynamic,
|
|
37
35
|
useLocale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export { getBrowserLocale } from './getBrowserLocale';\nexport {\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n useIntlayerContext,\n type IntlayerProviderProps,\n} from './IntlayerProvider';\nexport { t } from './t';\nexport { useDictionary } from './useDictionary';\nexport { useDictionaryAsync } from './useDictionaryAsync';\nexport { useDictionaryDynamic } from './useDictionaryDynamic';\nexport { useIntlayer } from './useIntlayer';\nexport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export { getBrowserLocale } from './getBrowserLocale';\nexport {\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n useIntlayerContext,\n type IntlayerProviderProps,\n} from './IntlayerProvider';\nexport { t } from './t';\nexport { useDictionary } from './useDictionary';\nexport { useDictionaryAsync } from './useDictionaryAsync';\nexport { useDictionaryDynamic } from './useDictionaryDynamic';\nexport { useIntlayer } from './useIntlayer';\nexport { useLoadDynamic } from './useLoadDynamic';\nexport { useLocale } from './useLocale';\nexport { useLocaleBase } from './useLocaleBase';\nexport {\n localeCookie,\n setLocaleCookie,\n useLocaleCookie,\n} from './useLocaleCookie';\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,SAAS;AAClB,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useContext } from "preact/hooks";
|
|
2
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
3
3
|
import { getDictionary } from "../getDictionary.mjs";
|
|
4
4
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
5
|
const useDictionary = (dictionary, locale) => {
|
|
6
6
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
return useMemo(() => {
|
|
8
|
+
const localeTarget = locale ?? currentLocale;
|
|
9
|
+
return getDictionary(dictionary, localeTarget);
|
|
10
|
+
}, [dictionary, currentLocale, locale]);
|
|
9
11
|
};
|
|
10
12
|
export {
|
|
11
13
|
useDictionary
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, LocalesValues>(dictionary, localeTarget);\n }, [dictionary, currentLocale, locale]);\n};\n"],"mappings":";AAIA,SAAS,YAAY,eAAe;AACpC,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAO/B,MAAM,gBAAgB,CAC3B,YACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAElE,SAAO,QAAQ,MAAM;AACnB,UAAM,eAAe,UAAU;AAE/B,WAAO,cAAgC,YAAY,YAAY;AAAA,EACjE,GAAG,CAAC,YAAY,eAAe,MAAM,CAAC;AACxC;","names":[]}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import configuration from "@intlayer/config/built";
|
|
3
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
3
4
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
5
|
import { useDictionary } from "./useDictionary.mjs";
|
|
5
6
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
6
7
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
7
|
-
const localeTarget =
|
|
8
|
-
|
|
8
|
+
const localeTarget = useMemo(
|
|
9
|
+
() => locale ?? currentLocale ?? configuration?.internationalization.defaultLocale,
|
|
10
|
+
[currentLocale, locale]
|
|
11
|
+
);
|
|
12
|
+
const dictionary = await useMemo(
|
|
13
|
+
async () => await dictionaryPromise[localeTarget](),
|
|
14
|
+
[dictionaryPromise, localeTarget]
|
|
15
|
+
);
|
|
9
16
|
return useDictionary(dictionary, localeTarget);
|
|
10
17
|
};
|
|
11
18
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary, LanguageContent } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary, LanguageContent } from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () => (await dictionaryPromise[localeTarget]!()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":";AAEA,OAAO,mBAAmB;AAG1B,SAAS,YAAY,eAAe;AACpC,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAOvB,MAAM,qBAAqB,OAChC,mBACA,WACe;AACf,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAElE,QAAM,eAAe;AAAA,IACnB,MACE,UACA,iBACA,eAAe,qBAAqB;AAAA,IACtC,CAAC,eAAe,MAAM;AAAA,EACxB;AAEA,QAAM,aAAa,MAAM;AAAA,IACvB,YAAa,MAAM,kBAAkB,YAAY,EAAG;AAAA,IACpD,CAAC,mBAAmB,YAAY;AAAA,EAClC;AAEA,SAAO,cAAc,YAAY,YAAY;AAC/C;","names":[]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useContext } from "preact/hooks";
|
|
2
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
3
3
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
4
|
import { useDictionary } from "./useDictionary.mjs";
|
|
5
5
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
6
6
|
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
7
7
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
8
|
-
const localeTarget =
|
|
8
|
+
const localeTarget = useMemo(
|
|
9
|
+
() => locale ?? currentLocale,
|
|
10
|
+
[currentLocale, locale]
|
|
11
|
+
);
|
|
9
12
|
const dictionary = useLoadDynamic(
|
|
10
13
|
`${String(key)}.${localeTarget}`,
|
|
11
14
|
dictionaryPromise[localeTarget]()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type {\n Dictionary,\n DictionaryKeys,\n LanguageContent,\n} from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n dictionaryPromise[localeTarget]!()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":";AAQA,SAAS,
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type {\n Dictionary,\n DictionaryKeys,\n LanguageContent,\n} from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n dictionaryPromise[localeTarget]!()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":";AAQA,SAAS,YAAY,eAAe;AACpC,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAOxB,MAAM,uBAAuB,CAIlC,mBACA,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe;AAAA,IACnB,MAAM,UAAU;AAAA,IAChB,CAAC,eAAe,MAAM;AAAA,EACxB;AAEA,QAAM,aAAa;AAAA,IACjB,GAAG,OAAO,GAAG,CAAC,IAAI,YAAY;AAAA,IAC9B,kBAAkB,YAAY,EAAG;AAAA,EACnC;AAEA,SAAO,cAAc,YAAY,YAAY;AAC/C;","names":[]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useContext } from "preact/hooks";
|
|
2
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
3
3
|
import { getIntlayer } from "../getIntlayer.mjs";
|
|
4
4
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
5
|
const useIntlayer = (key, locale) => {
|
|
6
6
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
return useMemo(() => {
|
|
8
|
+
const localeTarget = locale ?? currentLocale;
|
|
9
|
+
return getIntlayer(key, localeTarget);
|
|
10
|
+
}, [key, currentLocale, locale]);
|
|
9
11
|
};
|
|
10
12
|
export {
|
|
11
13
|
useIntlayer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { DictionaryKeys } from '@intlayer/core';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { useContext } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content']> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { DictionaryKeys } from '@intlayer/core';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content']> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getIntlayer(key, localeTarget) as any;\n }, [key, currentLocale, locale]);\n};\n"],"mappings":";AAMA,SAAS,YAAY,eAAe;AACpC,SAAS,mBAAmB;AAE5B,SAAS,6BAA6B;AAO/B,MAAM,cAAc,CACzB,KACA,WACyE;AACzE,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAElE,SAAO,QAAQ,MAAM;AACnB,UAAM,eAAe,UAAU;AAE/B,WAAO,YAAY,KAAK,YAAY;AAAA,EACtC,GAAG,CAAC,KAAK,eAAe,MAAM,CAAC;AACjC;","names":[]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { getTranslation } from "@intlayer/core";
|
|
2
|
-
import { useContext } from "preact/hooks";
|
|
2
|
+
import { useContext, useMemo } from "preact/hooks";
|
|
3
3
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
4
|
const useTranslation = (languageContent) => {
|
|
5
5
|
const { locale } = useContext(IntlayerClientContext);
|
|
6
|
-
return
|
|
6
|
+
return useMemo(
|
|
7
|
+
() => getTranslation(languageContent, locale),
|
|
8
|
+
[languageContent, locale]
|
|
9
|
+
);
|
|
7
10
|
};
|
|
8
11
|
export {
|
|
9
12
|
useTranslation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation, type LanguageContent } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"AAAA,SAAS,sBAA4C;AACrD,SAAS,
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation, type LanguageContent } from '@intlayer/core';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":"AAAA,SAAS,sBAA4C;AACrD,SAAS,YAAY,eAAe;AACpC,SAAS,6BAA6B;AAuB/B,MAAM,iBAAiB,CAC5B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO;AAAA,IACL,MAAM,eAAe,iBAAiB,MAAM;AAAA,IAC5C,CAAC,iBAAiB,MAAM;AAAA,EAC1B;AACF;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
useDictionaryAsync,
|
|
11
11
|
useDictionaryDynamic,
|
|
12
12
|
useIntlayer,
|
|
13
|
-
useIntlayerAsync,
|
|
14
13
|
useIntlayerContext,
|
|
15
14
|
useLoadDynamic,
|
|
16
15
|
useLocale,
|
|
@@ -31,7 +30,6 @@ export {
|
|
|
31
30
|
useDictionaryAsync,
|
|
32
31
|
useDictionaryDynamic,
|
|
33
32
|
useIntlayer,
|
|
34
|
-
useIntlayerAsync,
|
|
35
33
|
useIntlayerContext,
|
|
36
34
|
useLoadDynamic,
|
|
37
35
|
useLocale,
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import type { IInterpreterPluginPreact } from './plugins';\n\ndeclare module '@intlayer/core' {\n interface IInterpreterPlugin<T, S> extends IInterpreterPluginPreact<T> {}\n}\n\nexport {\n getBrowserLocale,\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n localeCookie,\n setLocaleCookie,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useIntlayer,\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import type { IInterpreterPluginPreact } from './plugins';\n\ndeclare module '@intlayer/core' {\n interface IInterpreterPlugin<T, S> extends IInterpreterPluginPreact<T> {}\n}\n\nexport {\n getBrowserLocale,\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n localeCookie,\n setLocaleCookie,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useIntlayer,\n useIntlayerContext,\n useLoadDynamic,\n useLocale,\n useLocaleBase,\n useLocaleCookie,\n type IntlayerProviderProps,\n} from './client/index';\nexport { type IntlayerNode } from './IntlayerNode';\nexport { MarkdownProvider } from './markdown/index';\n"],"mappings":"AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,wBAAwB;","names":[]}
|
|
@@ -5,7 +5,6 @@ export { useDictionary } from './useDictionary';
|
|
|
5
5
|
export { useDictionaryAsync } from './useDictionaryAsync';
|
|
6
6
|
export { useDictionaryDynamic } from './useDictionaryDynamic';
|
|
7
7
|
export { useIntlayer } from './useIntlayer';
|
|
8
|
-
export { useIntlayerAsync } from './useIntlayerAsync';
|
|
9
8
|
export { useLoadDynamic } from './useLoadDynamic';
|
|
10
9
|
export { useLocale } from './useLocale';
|
|
11
10
|
export { useLocaleBase } from './useLocaleBase';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,qBAAqB,GAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,qBAAqB,GAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,MAAM,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/client/useDictionary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKjD;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,UAAU,EAChD,YAAY,CAAC,EACb,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/client/useDictionary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKjD;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,UAAU,EAChD,YAAY,CAAC,EACb,SAAS,aAAa,8GASvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.d.ts","sourceRoot":"","sources":["../../../src/client/useDictionaryAsync.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.d.ts","sourceRoot":"","sources":["../../../src/client/useDictionaryAsync.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKlE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAU,CAAC,SAAS,UAAU,EAC3D,mBAAmB,eAAe,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,EACpD,SAAS,aAAa,KACrB,OAAO,CAAC,CAAC,CAiBX,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.d.ts","sourceRoot":"","sources":["../../../src/client/useDictionaryDynamic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAMxB;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,cAAc,EAExB,mBAAmB,eAAe,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,EACpD,KAAK,CAAC,EACN,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.d.ts","sourceRoot":"","sources":["../../../src/client/useDictionaryDynamic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAMxB;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,cAAc,EAExB,mBAAmB,eAAe,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,EACpD,KAAK,CAAC,EACN,SAAS,aAAa,8GAcvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/client/useIntlayer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAGjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGvD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,cAAc,EAClD,KAAK,CAAC,EACN,SAAS,aAAa,KACrB,oBAAoB,CAAC,gCAAgC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/client/useIntlayer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAGjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGvD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,cAAc,EAClD,KAAK,CAAC,EACN,SAAS,aAAa,KACrB,oBAAoB,CAAC,gCAAgC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAQrE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTraduction.d.ts","sourceRoot":"","sources":["../../../src/client/useTraduction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,MAAM,EAC7C,iBAAiB,eAAe,CAAC,OAAO,CAAC,KACxC,
|
|
1
|
+
{"version":3,"file":"useTraduction.d.ts","sourceRoot":"","sources":["../../../src/client/useTraduction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,MAAM,EAC7C,iBAAiB,eAAe,CAAC,OAAO,CAAC,KACxC,OAOF,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ declare module '@intlayer/core' {
|
|
|
3
3
|
interface IInterpreterPlugin<T, S> extends IInterpreterPluginPreact<T> {
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
-
export { getBrowserLocale, IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, localeCookie, setLocaleCookie, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer,
|
|
6
|
+
export { getBrowserLocale, IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, localeCookie, setLocaleCookie, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, type IntlayerProviderProps, } from './client/index';
|
|
7
7
|
export { type IntlayerNode } from './IntlayerNode';
|
|
8
8
|
export { MarkdownProvider } from './markdown/index';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,wBAAwB,CAAC,CAAC,CAAC;KAAG;CAC1E;AAED,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACZ,eAAe,EACf,CAAC,EACD,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,wBAAwB,CAAC,CAAC,CAAC;KAAG;CAC1E;AAED,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACZ,eAAe,EACf,CAAC,EACD,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,aAAa,EACb,eAAe,EACf,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-intlayer",
|
|
3
|
-
"version": "5.7.
|
|
3
|
+
"version": "5.7.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Preact applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"js-cookie": "^3.0.5",
|
|
60
60
|
"uuid": "^11.1.0",
|
|
61
|
-
"@intlayer/
|
|
62
|
-
"@intlayer/
|
|
63
|
-
"@intlayer/core": "5.7.
|
|
64
|
-
"@intlayer/editor": "5.7.
|
|
65
|
-
"@intlayer/api": "5.7.
|
|
61
|
+
"@intlayer/config": "5.7.7",
|
|
62
|
+
"@intlayer/chokidar": "5.7.7",
|
|
63
|
+
"@intlayer/core": "5.7.7",
|
|
64
|
+
"@intlayer/editor": "5.7.7",
|
|
65
|
+
"@intlayer/api": "5.7.7"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/node": "^22.15.30",
|
|
@@ -83,11 +83,11 @@
|
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"preact": "^10.26.4",
|
|
86
|
-
"@intlayer/
|
|
87
|
-
"@intlayer/
|
|
88
|
-
"@intlayer/
|
|
89
|
-
"@intlayer/
|
|
90
|
-
"@intlayer/
|
|
86
|
+
"@intlayer/chokidar": "5.7.7",
|
|
87
|
+
"@intlayer/config": "5.7.7",
|
|
88
|
+
"@intlayer/api": "5.7.7",
|
|
89
|
+
"@intlayer/core": "5.7.7",
|
|
90
|
+
"@intlayer/editor": "5.7.7"
|
|
91
91
|
},
|
|
92
92
|
"engines": {
|
|
93
93
|
"node": ">=14.18"
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var useIntlayerAsync_exports = {};
|
|
21
|
-
__export(useIntlayerAsync_exports, {
|
|
22
|
-
useIntlayerAsync: () => useIntlayerAsync
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(useIntlayerAsync_exports);
|
|
25
|
-
var import_core = require("@intlayer/core");
|
|
26
|
-
var import_hooks = require("preact/hooks");
|
|
27
|
-
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
28
|
-
const useIntlayerAsync = (key, locale) => {
|
|
29
|
-
const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
30
|
-
const localeTarget = locale ?? currentLocale;
|
|
31
|
-
const localeDictionary = (0, import_core.getIntlayer)(key, localeTarget);
|
|
32
|
-
const [distantDictionary, setDistantDictionary] = (0, import_hooks.useState)(void 0);
|
|
33
|
-
const [isLoading, setIsLoading] = (0, import_hooks.useState)(false);
|
|
34
|
-
(0, import_hooks.useEffect)(() => {
|
|
35
|
-
setIsLoading(true);
|
|
36
|
-
(0, import_core.getIntlayerAsync)(key).then((distantDictionary2) => {
|
|
37
|
-
if (distantDictionary2) {
|
|
38
|
-
setDistantDictionary(distantDictionary2);
|
|
39
|
-
}
|
|
40
|
-
}).finally(() => {
|
|
41
|
-
setIsLoading(false);
|
|
42
|
-
});
|
|
43
|
-
}, []);
|
|
44
|
-
const dictionary = (0, import_hooks.useMemo)(
|
|
45
|
-
() => distantDictionary ?? localeDictionary,
|
|
46
|
-
[distantDictionary, localeDictionary]
|
|
47
|
-
);
|
|
48
|
-
return { ...dictionary, isLoading };
|
|
49
|
-
};
|
|
50
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
-
0 && (module.exports = {
|
|
52
|
-
useIntlayerAsync
|
|
53
|
-
});
|
|
54
|
-
//# sourceMappingURL=useIntlayerAsync.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n getIntlayer,\n getIntlayerAsync,\n} from '@intlayer/core';\nimport { useContext, useEffect, useMemo, useState } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayerAsync = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n const localeDictionary = getIntlayer(key, localeTarget);\n const [distantDictionary, setDistantDictionary] = useState<\n typeof localeDictionary | null | undefined\n >(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n useEffect(() => {\n setIsLoading(true);\n\n getIntlayerAsync(key)\n .then((distantDictionary) => {\n if (distantDictionary) {\n setDistantDictionary(distantDictionary);\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const dictionary = useMemo(\n () => distantDictionary ?? localeDictionary,\n [distantDictionary, localeDictionary]\n );\n\n return { ...(dictionary as object), isLoading } as typeof localeDictionary & {\n isLoading: boolean;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAIO;AACP,mBAAyD;AACzD,8BAAsC;AAU/B,MAAM,mBAAmB,CAC9B,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,uBAAmB,yBAAY,KAAK,YAAY;AACtD,QAAM,CAAC,mBAAmB,oBAAoB,QAAI,uBAEhD,MAAS;AACX,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAEhD,8BAAU,MAAM;AACd,iBAAa,IAAI;AAEjB,sCAAiB,GAAG,EACjB,KAAK,CAACA,uBAAsB;AAC3B,UAAIA,oBAAmB;AACrB,6BAAqBA,kBAAiB;AAAA,MACxC;AAAA,IACF,CAAC,EACA,QAAQ,MAAM;AACb,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,CAAC;AAEL,QAAM,iBAAa;AAAA,IACjB,MAAM,qBAAqB;AAAA,IAC3B,CAAC,mBAAmB,gBAAgB;AAAA,EACtC;AAEA,SAAO,EAAE,GAAI,YAAuB,UAAU;AAGhD;","names":["distantDictionary"]}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
getIntlayer,
|
|
4
|
-
getIntlayerAsync
|
|
5
|
-
} from "@intlayer/core";
|
|
6
|
-
import { useContext, useEffect, useMemo, useState } from "preact/hooks";
|
|
7
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
8
|
-
const useIntlayerAsync = (key, locale) => {
|
|
9
|
-
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
10
|
-
const localeTarget = locale ?? currentLocale;
|
|
11
|
-
const localeDictionary = getIntlayer(key, localeTarget);
|
|
12
|
-
const [distantDictionary, setDistantDictionary] = useState(void 0);
|
|
13
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
setIsLoading(true);
|
|
16
|
-
getIntlayerAsync(key).then((distantDictionary2) => {
|
|
17
|
-
if (distantDictionary2) {
|
|
18
|
-
setDistantDictionary(distantDictionary2);
|
|
19
|
-
}
|
|
20
|
-
}).finally(() => {
|
|
21
|
-
setIsLoading(false);
|
|
22
|
-
});
|
|
23
|
-
}, []);
|
|
24
|
-
const dictionary = useMemo(
|
|
25
|
-
() => distantDictionary ?? localeDictionary,
|
|
26
|
-
[distantDictionary, localeDictionary]
|
|
27
|
-
);
|
|
28
|
-
return { ...dictionary, isLoading };
|
|
29
|
-
};
|
|
30
|
-
export {
|
|
31
|
-
useIntlayerAsync
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=useIntlayerAsync.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n getIntlayer,\n getIntlayerAsync,\n} from '@intlayer/core';\nimport { useContext, useEffect, useMemo, useState } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayerAsync = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n const localeDictionary = getIntlayer(key, localeTarget);\n const [distantDictionary, setDistantDictionary] = useState<\n typeof localeDictionary | null | undefined\n >(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n useEffect(() => {\n setIsLoading(true);\n\n getIntlayerAsync(key)\n .then((distantDictionary) => {\n if (distantDictionary) {\n setDistantDictionary(distantDictionary);\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const dictionary = useMemo(\n () => distantDictionary ?? localeDictionary,\n [distantDictionary, localeDictionary]\n );\n\n return { ...(dictionary as object), isLoading } as typeof localeDictionary & {\n isLoading: boolean;\n };\n};\n"],"mappings":";AAGA;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY,WAAW,SAAS,gBAAgB;AACzD,SAAS,6BAA6B;AAU/B,MAAM,mBAAmB,CAC9B,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,mBAAmB,YAAY,KAAK,YAAY;AACtD,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAEhD,MAAS;AACX,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAEjB,qBAAiB,GAAG,EACjB,KAAK,CAACA,uBAAsB;AAC3B,UAAIA,oBAAmB;AACrB,6BAAqBA,kBAAiB;AAAA,MACxC;AAAA,IACF,CAAC,EACA,QAAQ,MAAM;AACb,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa;AAAA,IACjB,MAAM,qBAAqB;AAAA,IAC3B,CAAC,mBAAmB,gBAAgB;AAAA,EACtC;AAEA,SAAO,EAAE,GAAI,YAAuB,UAAU;AAGhD;","names":["distantDictionary"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LocalesValues } from '@intlayer/config/client';
|
|
2
|
-
import { type DictionaryKeys } from '@intlayer/core';
|
|
3
|
-
/**
|
|
4
|
-
* On the client side, Hook that picking one dictionary by its key and return the content
|
|
5
|
-
*
|
|
6
|
-
* This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
10
|
-
*/
|
|
11
|
-
export declare const useIntlayerAsync: <T extends DictionaryKeys>(key: T, locale?: LocalesValues) => import("@intlayer/core").DeepTransformContent<import("intlayer").IntlayerDictionaryTypesConnector[T]["content"], import("@intlayer/core").IInterpreterPluginState> & {
|
|
12
|
-
isLoading: boolean;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=useIntlayerAsync.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayerAsync.d.ts","sourceRoot":"","sources":["../../../src/client/useIntlayerAsync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,gBAAgB,CAAC;AAIxB;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,cAAc,EACvD,KAAK,CAAC,EACN,SAAS,aAAa,KA6B6B,qKAA0B;IAC3E,SAAS,EAAE,OAAO,CAAC;CAEtB,CAAC"}
|