react-intlayer 1.0.1 → 1.2.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/dist/cjs/{LocaleContextProvider.cjs → IntlayerProvider.cjs} +11 -11
- package/dist/cjs/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/IntlayerProvider.d.ts +9 -0
- package/dist/cjs/cli/react-intlayer.cjs +68 -0
- package/dist/cjs/cli/react-intlayer.cjs.map +1 -0
- package/dist/cjs/cli/react-intlayer.d.ts +1 -0
- package/dist/cjs/client/IntlayerClientProvider.cjs +69 -0
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -0
- package/dist/cjs/client/IntlayerClientProvider.d.ts +25 -0
- package/dist/cjs/client/getBrowserLocale.cjs +170 -0
- package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
- package/dist/cjs/client/getBrowserLocale.d.ts +26 -0
- package/dist/cjs/client/index.cjs +13 -7
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +3 -1
- package/dist/cjs/client/useContent.cjs +2 -2
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useContent.d.ts +4 -1
- package/dist/cjs/client/useIntlayer.cjs +2 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.d.ts +5 -0
- package/dist/cjs/client/useLocale.cjs +6 -4
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocale.d.ts +4 -0
- package/dist/cjs/client/{LocaleClientContextProvider.cjs → useLocaleBase.cjs} +24 -17
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
- package/dist/cjs/client/useLocaleBase.d.ts +14 -0
- package/dist/cjs/client/useLocaleCookie.cjs +1 -1
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
- package/dist/cjs/client/useLocaleCookie.d.ts +9 -0
- package/dist/cjs/client/useTraduction.cjs +2 -2
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.d.ts +22 -1
- package/dist/cjs/craco/craco.config.cjs +32 -0
- package/dist/cjs/craco/craco.config.cjs.map +1 -0
- package/dist/cjs/craco/craco.config.d.ts +2 -0
- package/dist/cjs/craco/intlayerCracoPlugin.cjs +89 -0
- package/dist/cjs/craco/intlayerCracoPlugin.cjs.map +1 -0
- package/dist/cjs/craco/intlayerCracoPlugin.d.ts +26 -0
- package/dist/cjs/getEnumeration.cjs.map +1 -1
- package/dist/cjs/getEnumeration.d.ts +28 -0
- package/dist/cjs/getTranslation.cjs +1 -1
- package/dist/cjs/getTranslation.cjs.map +1 -1
- package/dist/cjs/getTranslation.d.ts +22 -1
- package/dist/cjs/index.cjs +8 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/processDictionary/index.cjs +33 -1
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/processDictionary/index.d.ts +1 -1
- package/dist/cjs/server/{LocaleServerContextProvider.cjs → IntlayerServerProvider.cjs} +20 -14
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -0
- package/dist/{esm/server/LocaleServerContextProvider.d.mts → cjs/server/IntlayerServerProvider.d.ts} +17 -4
- package/dist/cjs/server/getLocaleTranslation.cjs +3 -3
- package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
- package/dist/cjs/server/getLocaleTranslation.d.ts +3 -0
- package/dist/cjs/server/index.cjs +6 -6
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/index.d.ts +1 -1
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/serverContext.d.ts +4 -4
- package/dist/cjs/server/useIntlayer.cjs +2 -2
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.d.ts +5 -0
- package/dist/cjs/server/useTraduction.cjs +2 -2
- package/dist/cjs/server/useTraduction.cjs.map +1 -1
- package/dist/cjs/server/useTraduction.d.ts +22 -1
- package/dist/cjs/useIntlayerBase.cjs.map +1 -1
- package/dist/cjs/useIntlayerBase.d.ts +3 -6
- package/dist/cjs/vite/intlayerPlugin.cjs +60 -0
- package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -0
- package/dist/cjs/vite/intlayerPlugin.d.ts +17 -0
- package/dist/esm/ContentEditor/ContentEditor.mjs +1 -0
- package/dist/esm/ContentEditor/ContentEditor.mjs.map +1 -1
- package/dist/esm/ContentEditor/contentRender.mjs +1 -0
- package/dist/esm/ContentEditor/contentRender.mjs.map +1 -1
- package/dist/esm/IntlayerProvider.d.mts +9 -0
- package/dist/esm/IntlayerProvider.mjs +18 -0
- package/dist/esm/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/chunk-ZNCO4QRF.mjs +9 -0
- package/dist/esm/chunk-ZNCO4QRF.mjs.map +1 -0
- package/dist/esm/cli/react-intlayer.d.mts +1 -0
- package/dist/esm/cli/react-intlayer.mjs +45 -0
- package/dist/esm/cli/react-intlayer.mjs.map +1 -0
- package/dist/esm/client/IntlayerClientProvider.d.mts +25 -0
- package/dist/esm/client/IntlayerClientProvider.mjs +50 -0
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -0
- package/dist/esm/client/getBrowserLocale.d.mts +26 -0
- package/dist/esm/client/getBrowserLocale.mjs +146 -0
- package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +3 -1
- package/dist/esm/client/index.mjs +12 -7
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useContent.d.mts +4 -1
- package/dist/esm/client/useContent.mjs +3 -2
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.d.mts +5 -0
- package/dist/esm/client/useIntlayer.mjs +3 -2
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.d.mts +4 -0
- package/dist/esm/client/useLocale.mjs +8 -5
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.d.mts +14 -0
- package/dist/esm/client/useLocaleBase.mjs +26 -0
- package/dist/esm/client/useLocaleBase.mjs.map +1 -0
- package/dist/esm/client/useLocaleCookie.d.mts +9 -0
- package/dist/esm/client/useLocaleCookie.mjs +3 -4
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.d.mts +22 -1
- package/dist/esm/client/useTraduction.mjs +3 -2
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/craco/craco.config.d.mts +2 -0
- package/dist/esm/craco/craco.config.mjs +17 -0
- package/dist/esm/craco/craco.config.mjs.map +1 -0
- package/dist/esm/craco/intlayerCracoPlugin.d.mts +26 -0
- package/dist/esm/craco/intlayerCracoPlugin.mjs +54 -0
- package/dist/esm/craco/intlayerCracoPlugin.mjs.map +1 -0
- package/dist/esm/getEnumeration.d.mts +28 -0
- package/dist/esm/getEnumeration.mjs +1 -0
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getTranslation.d.mts +22 -1
- package/dist/esm/getTranslation.mjs +3 -4
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/index.d.mts +3 -1
- package/dist/esm/index.mjs +10 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.d.mts +1 -1
- package/dist/esm/processDictionary/index.mjs +35 -4
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/{cjs/server/LocaleServerContextProvider.d.ts → esm/server/IntlayerServerProvider.d.mts} +17 -4
- package/dist/esm/server/IntlayerServerProvider.mjs +20 -0
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -0
- package/dist/esm/server/getLocaleTranslation.d.mts +3 -0
- package/dist/esm/server/getLocaleTranslation.mjs +5 -4
- package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
- package/dist/esm/server/index.d.mts +1 -1
- package/dist/esm/server/index.mjs +6 -5
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/serverContext.d.mts +4 -4
- package/dist/esm/server/serverContext.mjs +1 -0
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.d.mts +5 -0
- package/dist/esm/server/useIntlayer.mjs +3 -2
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useTraduction.d.mts +22 -1
- package/dist/esm/server/useTraduction.mjs +3 -2
- package/dist/esm/server/useTraduction.mjs.map +1 -1
- package/dist/esm/useIntlayerBase.d.mts +3 -6
- package/dist/esm/useIntlayerBase.mjs +1 -0
- package/dist/esm/useIntlayerBase.mjs.map +1 -1
- package/dist/esm/vite/intlayerPlugin.d.mts +17 -0
- package/dist/esm/vite/intlayerPlugin.mjs +36 -0
- package/dist/esm/vite/intlayerPlugin.mjs.map +1 -0
- package/package.json +32 -7
- package/src/IntlayerProvider.tsx +24 -0
- package/src/cli/react-intlayer.ts +60 -0
- package/src/client/IntlayerClientProvider.tsx +76 -0
- package/src/client/getBrowserLocale.tsx +192 -0
- package/src/client/index.ts +7 -5
- package/src/client/useContent.ts +5 -2
- package/src/client/useIntlayer.ts +7 -2
- package/src/client/useLocale.ts +9 -5
- package/src/client/useLocaleBase.ts +24 -0
- package/src/client/useLocaleCookie.ts +11 -6
- package/src/client/useTraduction.ts +24 -3
- package/src/craco/craco.config.ts +11 -0
- package/src/craco/intlayerCracoPlugin.ts +89 -0
- package/src/getEnumeration.ts +28 -0
- package/src/getTranslation.ts +24 -6
- package/src/index.ts +5 -5
- package/src/processDictionary/index.ts +53 -6
- package/src/server/IntlayerServerProvider.tsx +36 -0
- package/src/server/getLocaleTranslation.ts +7 -4
- package/src/server/index.ts +3 -3
- package/src/server/serverContext.ts +4 -4
- package/src/server/useIntlayer.ts +8 -2
- package/src/server/useTraduction.ts +24 -3
- package/src/useIntlayerBase.ts +4 -1
- package/src/vite/intlayerPlugin.ts +59 -0
- package/dist/cjs/LocaleContextProvider.cjs.map +0 -1
- package/dist/cjs/LocaleContextProvider.d.ts +0 -9
- package/dist/cjs/client/LocaleClientContextProvider.cjs.map +0 -1
- package/dist/cjs/client/LocaleClientContextProvider.d.ts +0 -15
- package/dist/cjs/server/LocaleServerContextProvider.cjs.map +0 -1
- package/dist/esm/LocaleContextProvider.d.mts +0 -9
- package/dist/esm/LocaleContextProvider.mjs +0 -17
- package/dist/esm/LocaleContextProvider.mjs.map +0 -1
- package/dist/esm/client/LocaleClientContextProvider.d.mts +0 -15
- package/dist/esm/client/LocaleClientContextProvider.mjs +0 -21
- package/dist/esm/client/LocaleClientContextProvider.mjs.map +0 -1
- package/dist/esm/server/LocaleServerContextProvider.mjs +0 -16
- package/dist/esm/server/LocaleServerContextProvider.mjs.map +0 -1
- package/src/LocaleContextProvider.tsx +0 -26
- package/src/client/LocaleClientContextProvider.tsx +0 -35
- package/src/server/LocaleServerContextProvider.tsx +0 -24
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useContext,
|
|
8
|
+
useMemo,
|
|
9
|
+
useState,
|
|
10
|
+
useCallback
|
|
11
|
+
} from "react";
|
|
12
|
+
import { localeCookie, setLocaleCookie } from './useLocaleCookie.mjs';
|
|
13
|
+
const IntlayerClientContext = createContext({
|
|
14
|
+
locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,
|
|
15
|
+
setLocale: () => null
|
|
16
|
+
});
|
|
17
|
+
const useIntlayerContext = () => useContext(IntlayerClientContext);
|
|
18
|
+
const IntlayerClientProvider = ({
|
|
19
|
+
locale,
|
|
20
|
+
children
|
|
21
|
+
}) => {
|
|
22
|
+
const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
|
|
23
|
+
const [currentLocale, setCurrentLocale] = useState(
|
|
24
|
+
locale ?? localeCookie ?? defaultLocale
|
|
25
|
+
);
|
|
26
|
+
const setLocale = useCallback(
|
|
27
|
+
(newLocale) => {
|
|
28
|
+
if (currentLocale.toString() === newLocale.toString())
|
|
29
|
+
return;
|
|
30
|
+
if (!availableLocales.includes(newLocale)) {
|
|
31
|
+
console.error(`Locale ${locale} is not available`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
setCurrentLocale(newLocale);
|
|
35
|
+
setLocaleCookie(newLocale);
|
|
36
|
+
},
|
|
37
|
+
[availableLocales, currentLocale, locale]
|
|
38
|
+
);
|
|
39
|
+
const value = useMemo(
|
|
40
|
+
() => ({ locale: currentLocale, setLocale }),
|
|
41
|
+
[currentLocale, setLocale]
|
|
42
|
+
);
|
|
43
|
+
return /* @__PURE__ */ jsx(IntlayerClientContext.Provider, { value, children });
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
IntlayerClientContext,
|
|
47
|
+
IntlayerClientProvider,
|
|
48
|
+
useIntlayerContext
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=IntlayerClientProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerClientProviderProps = PropsWithChildren & {\n locale?: Locales;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerClientProvider: FC<IntlayerClientProviderProps> = ({\n locale,\n children,\n}) => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocale = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;AAuEI;AArEJ,SAAS,wBAAsC;AAC/C;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,uBAAuB;AAUvC,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,iBAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AASjE,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAErB,QAAM,CAAC,eAAe,gBAAgB,IAAI;AAAA,IACxC,UAAU,gBAAgB;AAAA,EAC5B;AAEA,QAAM,YAAY;AAAA,IAChB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS;AAAG;AAEvD,UAAI,CAAC,iBAAiB,SAAS,SAAS,GAAG;AACzC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,sBAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,QAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAU;AAAA,IAC1C,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAC7B,UACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Locales } from '@intlayer/config/client';
|
|
2
|
+
|
|
3
|
+
declare enum LanguageDetector {
|
|
4
|
+
Querystring = "querystring",
|
|
5
|
+
Cookie = "cookie",
|
|
6
|
+
LocalStorage = "localStorage",
|
|
7
|
+
SessionStorage = "sessionStorage",
|
|
8
|
+
Navigator = "navigator",
|
|
9
|
+
HtmlTag = "htmlTag"
|
|
10
|
+
}
|
|
11
|
+
type LanguageDetectorOptions = {
|
|
12
|
+
order?: LanguageDetector[];
|
|
13
|
+
lookupQuerystring?: string;
|
|
14
|
+
lookupCookie?: string;
|
|
15
|
+
lookupLocalStorage?: string;
|
|
16
|
+
lookupSessionStorage?: string;
|
|
17
|
+
excludeCacheFor?: string[];
|
|
18
|
+
htmlTag?: HTMLElement | null;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Core language detector function
|
|
22
|
+
* const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });
|
|
23
|
+
*/
|
|
24
|
+
declare const getBrowserLocale: (userOptions?: LanguageDetectorOptions | undefined) => Locales;
|
|
25
|
+
|
|
26
|
+
export { LanguageDetector, getBrowserLocale };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
3
|
+
import { localeList } from "@intlayer/core";
|
|
4
|
+
var LanguageDetector = /* @__PURE__ */ ((LanguageDetector2) => {
|
|
5
|
+
LanguageDetector2["Querystring"] = "querystring";
|
|
6
|
+
LanguageDetector2["Cookie"] = "cookie";
|
|
7
|
+
LanguageDetector2["LocalStorage"] = "localStorage";
|
|
8
|
+
LanguageDetector2["SessionStorage"] = "sessionStorage";
|
|
9
|
+
LanguageDetector2["Navigator"] = "navigator";
|
|
10
|
+
LanguageDetector2["HtmlTag"] = "htmlTag";
|
|
11
|
+
return LanguageDetector2;
|
|
12
|
+
})(LanguageDetector || {});
|
|
13
|
+
const getDefaultsOptions = () => {
|
|
14
|
+
const { middleware } = getConfiguration();
|
|
15
|
+
return {
|
|
16
|
+
order: [
|
|
17
|
+
"querystring" /* Querystring */,
|
|
18
|
+
"cookie" /* Cookie */,
|
|
19
|
+
"navigator" /* Navigator */,
|
|
20
|
+
"htmlTag" /* HtmlTag */
|
|
21
|
+
],
|
|
22
|
+
lookupQuerystring: "locale",
|
|
23
|
+
lookupCookie: middleware.cookieName,
|
|
24
|
+
htmlTag: document.documentElement
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const isLocalStorageAvailable = () => {
|
|
28
|
+
try {
|
|
29
|
+
if (typeof window === "undefined")
|
|
30
|
+
return false;
|
|
31
|
+
const testKey = "intlayer.translate.boo";
|
|
32
|
+
window.localStorage.setItem(testKey, "foo");
|
|
33
|
+
window.localStorage.removeItem(testKey);
|
|
34
|
+
return true;
|
|
35
|
+
} catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const isSessionStorageAvailable = () => {
|
|
40
|
+
try {
|
|
41
|
+
if (typeof window === "undefined")
|
|
42
|
+
return false;
|
|
43
|
+
const testKey = "intlayer.translate.boo";
|
|
44
|
+
window.sessionStorage.setItem(testKey, "foo");
|
|
45
|
+
window.sessionStorage.removeItem(testKey);
|
|
46
|
+
return true;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const detectLanguage = (order, options) => {
|
|
52
|
+
const detected = {};
|
|
53
|
+
const queryStringDetector = () => {
|
|
54
|
+
if (typeof window === "undefined")
|
|
55
|
+
return;
|
|
56
|
+
const search = window.location.search || "";
|
|
57
|
+
const params = new URLSearchParams(search);
|
|
58
|
+
const value = params.get(options.lookupQuerystring ?? "");
|
|
59
|
+
if (value) {
|
|
60
|
+
detected["querystring" /* Querystring */] = value;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const cookieDetector = () => {
|
|
64
|
+
if (typeof document === "undefined")
|
|
65
|
+
return;
|
|
66
|
+
const cookies = document.cookie.split(";");
|
|
67
|
+
const cookieName = `${options.lookupCookie ?? ""}=`;
|
|
68
|
+
const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
|
|
69
|
+
if (cookie) {
|
|
70
|
+
const value = cookie.split("=")[1].trim();
|
|
71
|
+
detected["cookie" /* Cookie */] = value;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const localStorageDetector = () => {
|
|
75
|
+
if (!isLocalStorageAvailable())
|
|
76
|
+
return;
|
|
77
|
+
const value = window.localStorage.getItem(options.lookupLocalStorage ?? "");
|
|
78
|
+
if (value) {
|
|
79
|
+
detected["localStorage" /* LocalStorage */] = value;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const sessionStorageDetector = () => {
|
|
83
|
+
if (!isSessionStorageAvailable())
|
|
84
|
+
return;
|
|
85
|
+
const value = window.sessionStorage.getItem(
|
|
86
|
+
options.lookupSessionStorage ?? ""
|
|
87
|
+
);
|
|
88
|
+
if (value) {
|
|
89
|
+
detected["sessionStorage" /* SessionStorage */] = value;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const navigatorDetector = () => {
|
|
93
|
+
if (typeof navigator === "undefined")
|
|
94
|
+
return;
|
|
95
|
+
if (navigator.language) {
|
|
96
|
+
detected["navigator" /* Navigator */] = navigator.language;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const htmlTagDetector = () => {
|
|
100
|
+
const htmlTag = options.htmlTag;
|
|
101
|
+
if (htmlTag && typeof htmlTag.getAttribute === "function") {
|
|
102
|
+
const lang = htmlTag.getAttribute("lang");
|
|
103
|
+
if (lang) {
|
|
104
|
+
detected["htmlTag" /* HtmlTag */] = lang;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const detectors = {
|
|
109
|
+
["querystring" /* Querystring */]: queryStringDetector,
|
|
110
|
+
["cookie" /* Cookie */]: cookieDetector,
|
|
111
|
+
["localStorage" /* LocalStorage */]: localStorageDetector,
|
|
112
|
+
["sessionStorage" /* SessionStorage */]: sessionStorageDetector,
|
|
113
|
+
["navigator" /* Navigator */]: navigatorDetector,
|
|
114
|
+
["htmlTag" /* HtmlTag */]: htmlTagDetector
|
|
115
|
+
};
|
|
116
|
+
order.forEach((detectorName) => {
|
|
117
|
+
detectors[detectorName]?.();
|
|
118
|
+
});
|
|
119
|
+
return detected;
|
|
120
|
+
};
|
|
121
|
+
const getFirstAvailableLocale = (locales, order) => {
|
|
122
|
+
const { internationalization } = getConfiguration();
|
|
123
|
+
for (const detector of order) {
|
|
124
|
+
const localesArray = [locales[detector]].flat();
|
|
125
|
+
for (const locale of localesArray) {
|
|
126
|
+
if (locale && (internationalization.locales ?? localeList).includes(locale)) {
|
|
127
|
+
return locale;
|
|
128
|
+
} else if (locale?.includes("-") && (internationalization.locales ?? localeList).includes(
|
|
129
|
+
locale.split("-")[0]
|
|
130
|
+
)) {
|
|
131
|
+
return locale.split("-")[0];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return internationalization.defaultLocale;
|
|
136
|
+
};
|
|
137
|
+
const getBrowserLocale = (userOptions = {}) => {
|
|
138
|
+
const options = { ...getDefaultsOptions(), ...userOptions };
|
|
139
|
+
const locales = detectLanguage(options.order ?? [], options);
|
|
140
|
+
return getFirstAvailableLocale(locales, options.order ?? []);
|
|
141
|
+
};
|
|
142
|
+
export {
|
|
143
|
+
LanguageDetector,
|
|
144
|
+
getBrowserLocale
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=getBrowserLocale.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/getBrowserLocale.tsx"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Cookie = 'cookie',\n LocalStorage = 'localStorage',\n SessionStorage = 'sessionStorage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n lookupCookie?: string;\n lookupLocalStorage?: string;\n lookupSessionStorage?: string;\n excludeCacheFor?: string[];\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n const { middleware } = getConfiguration();\n\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Cookie,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n lookupCookie: middleware.cookieName,\n htmlTag: document.documentElement,\n };\n};\n\n// Helper functions for various checks and operations\nconst isLocalStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.localStorage.setItem(testKey, 'foo');\n window.localStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isSessionStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.sessionStorage.setItem(testKey, 'foo');\n window.sessionStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\n// Function to detect language using different detectors\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locales | Locales[]> => {\n const detected: Record<LanguageDetector, Locales | Locales[]> = {} as Record<\n LanguageDetector,\n Locales | Locales[]\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locales;\n }\n };\n\n const cookieDetector = () => {\n if (typeof document === 'undefined') return;\n const cookies = document.cookie.split(';');\n const cookieName = `${options.lookupCookie ?? ''}=`;\n const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\n if (cookie) {\n const value = cookie.split('=')[1].trim();\n\n detected[LanguageDetector.Cookie] = value as Locales;\n }\n };\n\n const localStorageDetector = () => {\n if (!isLocalStorageAvailable()) return;\n const value = window.localStorage.getItem(options.lookupLocalStorage ?? '');\n if (value) {\n detected[LanguageDetector.LocalStorage] = value as Locales;\n }\n };\n\n const sessionStorageDetector = () => {\n if (!isSessionStorageAvailable()) return;\n const value = window.sessionStorage.getItem(\n options.lookupSessionStorage ?? ''\n );\n if (value) {\n detected[LanguageDetector.SessionStorage] = value as Locales;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n if (navigator.language) {\n detected[LanguageDetector.Navigator] = navigator.language as Locales;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n detected[LanguageDetector.HtmlTag] = lang as Locales;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Cookie]: cookieDetector,\n [LanguageDetector.LocalStorage]: localStorageDetector,\n [LanguageDetector.SessionStorage]: sessionStorageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locales | Locales[]>,\n order: LanguageDetector[]\n): Locales => {\n const { internationalization } = getConfiguration();\n\n for (const detector of order) {\n const localesArray = [locales[detector]].flat() as Locales[];\n\n for (const locale of localesArray) {\n if (\n locale &&\n (internationalization.locales ?? localeList).includes(locale)\n ) {\n return locale;\n } else if (\n locale?.includes('-') &&\n (internationalization.locales ?? localeList).includes(\n locale.split('-')[0] as Locales\n )\n ) {\n return locale.split('-')[0] as Locales;\n }\n }\n }\n\n return internationalization.defaultLocale;\n};\n\n/**\n * Core language detector function\n * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locales => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":"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","names":["LanguageDetector"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps, useIntlayerContext } from './IntlayerClientProvider.mjs';
|
|
2
2
|
export { useIntlayer } from './useIntlayer.mjs';
|
|
3
|
+
export { useLocaleBase } from './useLocaleBase.mjs';
|
|
3
4
|
export { useLocale } from './useLocale.mjs';
|
|
4
5
|
export { useTraduction } from './useTraduction.mjs';
|
|
5
6
|
export { localeCookie, setLocaleCookie, useLocaleCookie } from './useLocaleCookie.mjs';
|
|
7
|
+
export { getBrowserLocale } from './getBrowserLocale.mjs';
|
|
6
8
|
import 'react';
|
|
7
9
|
import '@intlayer/config/client';
|
|
8
10
|
import '../useIntlayerBase.mjs';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from './
|
|
3
|
+
IntlayerClientContext,
|
|
4
|
+
useIntlayerContext,
|
|
5
|
+
IntlayerClientProvider
|
|
6
|
+
} from './IntlayerClientProvider.mjs';
|
|
6
7
|
import { useIntlayer } from './useIntlayer.mjs';
|
|
8
|
+
import { useLocaleBase } from './useLocaleBase.mjs';
|
|
7
9
|
import { useLocale } from './useLocale.mjs';
|
|
8
10
|
import { useTraduction } from './useTraduction.mjs';
|
|
9
11
|
import {
|
|
@@ -11,14 +13,17 @@ import {
|
|
|
11
13
|
localeCookie,
|
|
12
14
|
setLocaleCookie
|
|
13
15
|
} from './useLocaleCookie.mjs';
|
|
16
|
+
import { getBrowserLocale } from './getBrowserLocale.mjs';
|
|
14
17
|
export {
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
IntlayerClientContext as IntlayerClient,
|
|
19
|
+
IntlayerClientProvider,
|
|
20
|
+
getBrowserLocale,
|
|
17
21
|
localeCookie,
|
|
18
22
|
setLocaleCookie,
|
|
19
23
|
useIntlayer,
|
|
24
|
+
useIntlayerContext,
|
|
20
25
|
useLocale,
|
|
21
|
-
|
|
26
|
+
useLocaleBase,
|
|
22
27
|
useLocaleCookie,
|
|
23
28
|
useTraduction
|
|
24
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export type {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export type { IntlayerClientProviderProps } from './IntlayerClientProvider';\nexport {\n IntlayerClientContext as IntlayerClient,\n useIntlayerContext,\n IntlayerClientProvider,\n} from './IntlayerClientProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\n"],"mappings":";AACA;AAAA,EAC2B;AAAA,EACzB;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;","names":[]}
|
|
@@ -2,10 +2,13 @@ import * as _intlayer_config_client from '@intlayer/config/client';
|
|
|
2
2
|
import * as intlayer from 'intlayer';
|
|
3
3
|
import { LanguageContent } from '@intlayer/core';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* On the client side, hook to get the translation content based on the locale
|
|
7
|
+
*/
|
|
5
8
|
declare const useContent: <Content>(languageContent: LanguageContent<Content>) => {
|
|
6
9
|
locale: intlayer.Locales;
|
|
7
10
|
content: Content;
|
|
8
|
-
t: <Content_1>(languageContent: Partial<Record<_intlayer_config_client.LocalesValues, Content_1>>) => Content_1;
|
|
11
|
+
t: <Content_1 = string>(languageContent: Partial<Record<_intlayer_config_client.LocalesValues, Content_1>>) => Content_1;
|
|
9
12
|
};
|
|
10
13
|
|
|
11
14
|
export { useContent };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
2
|
+
import { useLocaleBase } from './useLocaleBase.mjs';
|
|
2
3
|
import { useTraduction } from './useTraduction.mjs';
|
|
3
4
|
const useContent = (languageContent) => {
|
|
4
|
-
const { locale } =
|
|
5
|
+
const { locale } = useLocaleBase();
|
|
5
6
|
const content = useTraduction(languageContent);
|
|
6
7
|
return {
|
|
7
8
|
locale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTraduction } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTraduction(languageContent);\n\n return {\n locale,\n content,\n t: useTraduction,\n };\n};\n"],"mappings":";AACA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAKvB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,IAAI,cAAc;AAEjC,QAAM,UAAU,cAAc,eAAe;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -2,6 +2,11 @@ import { UseIntlayer } from '../useIntlayerBase.mjs';
|
|
|
2
2
|
import '@intlayer/config/client';
|
|
3
3
|
import 'intlayer';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* On the client side, Hook that picking one dictionary by its id and return the content
|
|
7
|
+
*
|
|
8
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
9
|
+
*/
|
|
5
10
|
declare const useIntlayer: UseIntlayer;
|
|
6
11
|
|
|
7
12
|
export { useIntlayer };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
2
3
|
import { useContext } from "react";
|
|
3
4
|
import {
|
|
4
5
|
useIntlayerBase
|
|
5
6
|
} from '../useIntlayerBase.mjs';
|
|
6
|
-
import {
|
|
7
|
+
import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
|
|
7
8
|
const useIntlayer = (id, locale) => {
|
|
8
|
-
const { locale: currentLocale } = useContext(
|
|
9
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
9
10
|
const localeTarget = locale ?? currentLocale;
|
|
10
11
|
return useIntlayerBase(id, localeTarget);
|
|
11
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id 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: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import * as _intlayer_config_client from '@intlayer/config/client';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* On the client side, hook to get the current locale and all related fields
|
|
5
|
+
*/
|
|
3
6
|
declare const useLocale: () => {
|
|
4
7
|
locale: _intlayer_config_client.Locales;
|
|
5
8
|
defaultLocale: _intlayer_config_client.Locales;
|
|
6
9
|
availableLocales: _intlayer_config_client.Locales[];
|
|
7
10
|
localeList: _intlayer_config_client.Locales[];
|
|
11
|
+
setLocale: (newLocale: _intlayer_config_client.Locales) => void;
|
|
8
12
|
};
|
|
9
13
|
|
|
10
14
|
export { useLocale };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
3
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
3
4
|
import { localeList } from "@intlayer/core";
|
|
4
5
|
import { useContext } from "react";
|
|
5
|
-
import {
|
|
6
|
-
const { defaultLocale, locales: availableLocales } = intlayerIntlConfiguration;
|
|
6
|
+
import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
|
|
7
7
|
const useLocale = () => {
|
|
8
|
-
const {
|
|
8
|
+
const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
|
|
9
|
+
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
9
10
|
return {
|
|
10
11
|
locale,
|
|
11
12
|
// Current locale
|
|
@@ -13,8 +14,10 @@ const useLocale = () => {
|
|
|
13
14
|
// Principal locale defined in config
|
|
14
15
|
availableLocales,
|
|
15
16
|
// List of the available locales defined in config
|
|
16
|
-
localeList
|
|
17
|
+
localeList,
|
|
17
18
|
// List of all available locales
|
|
19
|
+
setLocale
|
|
20
|
+
// Function to set the locale
|
|
18
21
|
};
|
|
19
22
|
};
|
|
20
23
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = () => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale } = useContext(IntlayerClientContext);\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 localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _intlayer_config_client from '@intlayer/config/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* On the client side, hook to get the current locale and all related fields
|
|
5
|
+
*/
|
|
6
|
+
declare const useLocaleBase: () => {
|
|
7
|
+
locale: _intlayer_config_client.Locales;
|
|
8
|
+
defaultLocale: _intlayer_config_client.Locales;
|
|
9
|
+
availableLocales: _intlayer_config_client.Locales[];
|
|
10
|
+
localeList: _intlayer_config_client.Locales[];
|
|
11
|
+
setLocale: (newLocale: _intlayer_config_client.Locales) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useLocaleBase };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
3
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
4
|
+
import { localeList } from "@intlayer/core";
|
|
5
|
+
import { useContext } from "react";
|
|
6
|
+
import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
|
|
7
|
+
const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
|
|
8
|
+
const useLocaleBase = () => {
|
|
9
|
+
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
10
|
+
return {
|
|
11
|
+
locale,
|
|
12
|
+
// Current locale
|
|
13
|
+
defaultLocale,
|
|
14
|
+
// Principal locale defined in config
|
|
15
|
+
availableLocales,
|
|
16
|
+
// List of the available locales defined in config
|
|
17
|
+
localeList,
|
|
18
|
+
// List of all available locales
|
|
19
|
+
setLocale
|
|
20
|
+
// Function to set the locale
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
useLocaleBase
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=useLocaleBase.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\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 localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { Locales } from '@intlayer/config/client';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Get the locale cookie
|
|
5
|
+
*/
|
|
3
6
|
declare const localeCookie: Locales | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Set the locale cookie
|
|
9
|
+
*/
|
|
4
10
|
declare const setLocaleCookie: (locale: Locales) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Hook that provides the locale cookie and a function to set it
|
|
13
|
+
*/
|
|
5
14
|
declare const useLocaleCookie: () => {
|
|
6
15
|
localeCookie: Locales | undefined;
|
|
7
16
|
setLocaleCookie: (locale: Locales) => void;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
} from "@intlayer/config/client";
|
|
1
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
4
3
|
import Cookies from "js-cookie";
|
|
5
|
-
const { cookieName } =
|
|
4
|
+
const { cookieName } = getConfiguration().middleware;
|
|
6
5
|
const cookieAttributes = {
|
|
7
6
|
path: "/",
|
|
8
7
|
expires: void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = getConfiguration().middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as Locales | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":";AAAA,SAAuB,wBAAwB;AAC/C,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI,iBAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAK3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { LanguageContent } from '@intlayer/core';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* On the client side, Hook that picking one dictionary by its id and return the content.
|
|
5
|
+
*
|
|
6
|
+
* If not locale found, it will return the content related to the default locale.
|
|
7
|
+
*
|
|
8
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const content = useTraduction<string>({
|
|
14
|
+
* en: 'Hello',
|
|
15
|
+
* fr: 'Bonjour',
|
|
16
|
+
* }, 'fr');
|
|
17
|
+
* // 'Bonjour'
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Using TypeScript:
|
|
21
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
22
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
23
|
+
*/
|
|
24
|
+
declare const useTraduction: <Content = string>(languageContent: LanguageContent<Content>) => Content;
|
|
4
25
|
|
|
5
26
|
export { useTraduction };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import "../chunk-ZNCO4QRF.mjs";
|
|
1
2
|
import { useContext } from "react";
|
|
2
3
|
import { getTranslation } from '../getTranslation.mjs';
|
|
3
|
-
import {
|
|
4
|
+
import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
|
|
4
5
|
const useTraduction = (languageContent) => {
|
|
5
|
-
const { locale } = useContext(
|
|
6
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
6
7
|
return getTranslation(languageContent, locale);
|
|
7
8
|
};
|
|
8
9
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\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 = useTraduction<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 useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJS
|
|
3
|
+
} from '../chunk-ZNCO4QRF.mjs';
|
|
4
|
+
import * as intlayerPlugin from './intlayerCracoPlugin.mjs';
|
|
5
|
+
var require_craco_config = __commonJS({
|
|
6
|
+
"src/craco/craco.config.ts"(exports, module) {
|
|
7
|
+
module.exports = {
|
|
8
|
+
plugins: [
|
|
9
|
+
{
|
|
10
|
+
plugin: intlayerPlugin
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export default require_craco_config();
|
|
17
|
+
//# sourceMappingURL=craco.config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/craco/craco.config.ts"],"sourcesContent":["import type { CracoConfig } from '@craco/types';\nimport * as intlayerPlugin from './intlayerCracoPlugin';\n\n// Usage Example\nmodule.exports = {\n plugins: [\n {\n plugin: intlayerPlugin,\n },\n ],\n} satisfies CracoConfig;\n"],"mappings":";;;AACA,YAAY,oBAAoB;AADhC;AAAA;AAIA,WAAO,UAAU;AAAA,MACf,SAAS;AAAA,QACP;AAAA,UACE,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { WebpackConfigOverride, CracoConfigOverride, CracoConfig, CracoPlugin } from '@craco/types';
|
|
2
|
+
import { Configuration } from 'webpack';
|
|
3
|
+
|
|
4
|
+
declare const overrideWebpackConfig: ({ webpackConfig, }: WebpackConfigOverride) => Configuration;
|
|
5
|
+
declare const overrideCracoConfig: ({ cracoConfig, }: CracoConfigOverride) => CracoConfig;
|
|
6
|
+
/**
|
|
7
|
+
* A CRACO plugin that adds the IntLayer configuration to the webpack configuration and sets the environment variables.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const cracoConfig: CracoConfig = {
|
|
13
|
+
* plugins: [
|
|
14
|
+
* {
|
|
15
|
+
* plugin: intlayerCracoPlugin(),
|
|
16
|
+
* },
|
|
17
|
+
* ],
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* export default cracoConfig;
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
declare const plugin: CracoPlugin;
|
|
25
|
+
|
|
26
|
+
export { overrideCracoConfig, overrideWebpackConfig, plugin };
|