react-intlayer 3.5.2 → 3.5.3

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.
@@ -26,9 +26,44 @@ var import_client = require("@intlayer/config/client");
26
26
  var import_core = require("@intlayer/core");
27
27
  var import_react = require("react");
28
28
  var import_IntlayerProvider = require('./IntlayerProvider.cjs');
29
- const useLocale = () => {
29
+ var import_useLocaleCookie = require('./useLocaleCookie.cjs');
30
+ const useLocale = ({ onLocaleChange } = {}) => {
31
+ const {
32
+ /**
33
+ * Prefix default prefix the default locale to the path as other locales.
34
+ *
35
+ * Example with prefixDefault = true and defaultLocale = 'en':
36
+ * path = /en/dashboard or /fr/dashboard
37
+ *
38
+ * Example with prefixDefault = false and defaultLocale = 'en':
39
+ * path = /dashboard or /fr/dashboard
40
+ *
41
+ */
42
+ prefixDefault
43
+ } = (0, import_client.getConfiguration)().middleware;
30
44
  const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
31
- const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
45
+ const { locale, setLocale: setLocaleState } = (0, import_react.useContext)(
46
+ import_IntlayerProvider.IntlayerClientContext
47
+ );
48
+ const { setLocaleCookie } = (0, import_useLocaleCookie.useLocaleCookie)();
49
+ const setLocale = (0, import_react.useCallback)(
50
+ (locale2) => {
51
+ if (!availableLocales.includes(locale2)) {
52
+ console.error(`Locale ${locale2} is not available`);
53
+ return;
54
+ }
55
+ setLocaleState(locale2);
56
+ setLocaleCookie(locale2);
57
+ onLocaleChange?.(locale2);
58
+ },
59
+ [
60
+ onLocaleChange,
61
+ availableLocales,
62
+ setLocaleState,
63
+ prefixDefault,
64
+ defaultLocale
65
+ ]
66
+ );
32
67
  return {
33
68
  locale,
34
69
  // Current locale
@@ -1 +1 @@
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 './IntlayerProvider';\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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAA2B;AAC3B,8BAAsC;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,6CAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type Locales } from '@intlayer/config';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useLocaleCookie } from './useLocaleCookie';\n\ntype useLocaleProps = {\n onLocaleChange?: (locale: Locales) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({ onLocaleChange }: useLocaleProps = {}) => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale: setLocaleState } = useContext(\n IntlayerClientContext\n );\n const { setLocaleCookie } = useLocaleCookie();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleCookie(locale);\n onLocaleChange?.(locale);\n },\n [\n onLocaleChange,\n availableLocales,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n ]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAAwC;AACxC,8BAAsC;AACtC,6BAAgC;AASzB,MAAM,YAAY,CAAC,EAAE,eAAe,IAAoB,CAAC,MAAM;AACpE,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,QAAI,gCAAiB,EAAE;AACvB,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,WAAW,eAAe,QAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,QAAI,wCAAgB;AAE5C,QAAM,gBAAY;AAAA,IAChB,CAACA,YAAoB;AACnB,UAAI,CAAC,iBAAiB,SAASA,OAAM,GAAG;AACtC,gBAAQ,MAAM,UAAUA,OAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,qBAAeA,OAAM;AACrB,sBAAgBA,OAAM;AACtB,uBAAiBA,OAAM;AAAA,IACzB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":["locale"]}
@@ -2,11 +2,46 @@
2
2
  import "../chunk-ZD7AOCMD.mjs";
3
3
  import { getConfiguration } from "@intlayer/config/client";
4
4
  import { localeList } from "@intlayer/core";
5
- import { useContext } from "react";
5
+ import { useCallback, useContext } from "react";
6
6
  import { IntlayerClientContext } from './IntlayerProvider.mjs';
7
- const useLocale = () => {
7
+ import { useLocaleCookie } from './useLocaleCookie.mjs';
8
+ const useLocale = ({ onLocaleChange } = {}) => {
9
+ const {
10
+ /**
11
+ * Prefix default prefix the default locale to the path as other locales.
12
+ *
13
+ * Example with prefixDefault = true and defaultLocale = 'en':
14
+ * path = /en/dashboard or /fr/dashboard
15
+ *
16
+ * Example with prefixDefault = false and defaultLocale = 'en':
17
+ * path = /dashboard or /fr/dashboard
18
+ *
19
+ */
20
+ prefixDefault
21
+ } = getConfiguration().middleware;
8
22
  const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
9
- const { locale, setLocale } = useContext(IntlayerClientContext);
23
+ const { locale, setLocale: setLocaleState } = useContext(
24
+ IntlayerClientContext
25
+ );
26
+ const { setLocaleCookie } = useLocaleCookie();
27
+ const setLocale = useCallback(
28
+ (locale2) => {
29
+ if (!availableLocales.includes(locale2)) {
30
+ console.error(`Locale ${locale2} is not available`);
31
+ return;
32
+ }
33
+ setLocaleState(locale2);
34
+ setLocaleCookie(locale2);
35
+ onLocaleChange?.(locale2);
36
+ },
37
+ [
38
+ onLocaleChange,
39
+ availableLocales,
40
+ setLocaleState,
41
+ prefixDefault,
42
+ defaultLocale
43
+ ]
44
+ );
10
45
  return {
11
46
  locale,
12
47
  // Current locale
@@ -1 +1 @@
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 './IntlayerProvider';\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":[]}
1
+ {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type Locales } from '@intlayer/config';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useLocaleCookie } from './useLocaleCookie';\n\ntype useLocaleProps = {\n onLocaleChange?: (locale: Locales) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({ onLocaleChange }: useLocaleProps = {}) => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale: setLocaleState } = useContext(\n IntlayerClientContext\n );\n const { setLocaleCookie } = useLocaleCookie();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleCookie(locale);\n onLocaleChange?.(locale);\n },\n [\n onLocaleChange,\n availableLocales,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n ]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;AAGA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,aAAa,kBAAkB;AACxC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AASzB,MAAM,YAAY,CAAC,EAAE,eAAe,IAAoB,CAAC,MAAM;AACpE,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,IAAI,iBAAiB,EAAE;AACvB,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,WAAW,eAAe,IAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,IAAI,gBAAgB;AAE5C,QAAM,YAAY;AAAA,IAChB,CAACA,YAAoB;AACnB,UAAI,CAAC,iBAAiB,SAASA,OAAM,GAAG;AACtC,gBAAQ,MAAM,UAAUA,OAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,qBAAeA,OAAM;AACrB,sBAAgBA,OAAM;AACtB,uBAAiBA,OAAM;AAAA,IACzB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":["locale"]}
@@ -1,11 +1,16 @@
1
+ import { type Locales } from '@intlayer/config';
2
+ type useLocaleProps = {
3
+ onLocaleChange?: (locale: Locales) => void;
4
+ };
1
5
  /**
2
6
  * On the client side, hook to get the current locale and all related fields
3
7
  */
4
- export declare const useLocale: () => {
5
- locale: import("intlayer").Locales;
6
- defaultLocale: import("intlayer").Locales;
7
- availableLocales: import("intlayer").Locales[];
8
- localeList: import("intlayer").Locales[];
9
- setLocale: (newLocale: import("intlayer").Locales) => void;
8
+ export declare const useLocale: ({ onLocaleChange }?: useLocaleProps) => {
9
+ locale: Locales;
10
+ defaultLocale: Locales;
11
+ availableLocales: Locales[];
12
+ localeList: Locales[];
13
+ setLocale: (locale: Locales) => void;
10
14
  };
15
+ export {};
11
16
  //# sourceMappingURL=useLocale.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../../src/client/useLocale.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;CAYrB,CAAC"}
1
+ {"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../../src/client/useLocale.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,KAAK,cAAc,GAAG;IACpB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,wBAAwB,cAAc;;;;;wBAsB/C,OAAO;CA0BnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intlayer",
3
- "version": "3.5.2",
3
+ "version": "3.5.3",
4
4
  "private": false,
5
5
  "description": "Internationalization layer for React applications. Declare your multilingual contant in the same lever than your component. Powered by TypeScript, declaration files.",
6
6
  "keywords": [
@@ -91,11 +91,11 @@
91
91
  "react-cookie": "^7.2.2",
92
92
  "vite": "^6.0.3",
93
93
  "webpack": "^5.96.1",
94
- "@intlayer/config": "^3.5.2",
95
- "@intlayer/core": "^3.5.2",
96
- "@intlayer/webpack": "^3.5.2",
97
- "@intlayer/dictionaries-entry": "^3.5.2",
98
- "@intlayer/chokidar": "^3.5.2"
94
+ "@intlayer/chokidar": "^3.5.3",
95
+ "@intlayer/webpack": "^3.5.3",
96
+ "@intlayer/core": "^3.5.3",
97
+ "@intlayer/dictionaries-entry": "^3.5.3",
98
+ "@intlayer/config": "^3.5.3"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@craco/types": "^7.1.0",
@@ -113,21 +113,21 @@
113
113
  "tsc-alias": "^1.8.10",
114
114
  "tsup": "^8.3.5",
115
115
  "typescript": "^5.7.2",
116
- "@utils/eslint-config": "^1.0.4",
117
- "@utils/ts-config": "^1.0.4",
118
116
  "@utils/ts-config-types": "^1.0.4",
117
+ "@utils/ts-config": "^1.0.4",
118
+ "@utils/eslint-config": "^1.0.4",
119
119
  "@utils/tsup-config": "^1.0.4"
120
120
  },
121
121
  "peerDependencies": {
122
122
  "react": ">=16.0.0 <19.0.0",
123
123
  "react-dom": ">=16.0.0 <19.0.0",
124
124
  "vite": ">=4.0.0",
125
- "@intlayer/chokidar": "^3.5.2",
126
- "@intlayer/config": "^3.5.2",
127
- "@intlayer/core": "^3.5.2",
128
- "@intlayer/dictionaries-entry": "^3.5.2",
129
- "@intlayer/webpack": "^3.5.2",
130
- "intlayer": "^3.5.2"
125
+ "@intlayer/chokidar": "^3.5.3",
126
+ "@intlayer/config": "^3.5.3",
127
+ "@intlayer/dictionaries-entry": "^3.5.3",
128
+ "@intlayer/core": "^3.5.3",
129
+ "intlayer": "^3.5.3",
130
+ "@intlayer/webpack": "^3.5.3"
131
131
  },
132
132
  "engines": {
133
133
  "node": ">=14.18"