@ttoss/react-i18n 1.17.2 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1,17 +1,14 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
 
3
- // tsup.inject.js
4
- import * as React from "react";
5
-
6
3
  // src/index.ts
7
4
  import { defineMessages, defineMessage, FormattedMessage } from "react-intl";
8
5
 
9
6
  // src/i18Provider.tsx
10
- import * as React2 from "react";
7
+ import * as React from "react";
11
8
  import { IntlProvider } from "react-intl";
12
9
  import { Fragment, jsx } from "react/jsx-runtime";
13
10
  var DEFAULT_LOCALE = "en";
14
- var I18nConfigContext = React2.createContext({
11
+ var I18nConfigContext = React.createContext({
15
12
  defaultLocale: DEFAULT_LOCALE,
16
13
  setLocale: () => {
17
14
  return null;
@@ -23,40 +20,44 @@ var I18nProvider = ({
23
20
  loadLocaleData,
24
21
  ...intlConfig
25
22
  }) => {
26
- const [locale, setLocale] = React2.useState(initialLocale || DEFAULT_LOCALE);
27
- const [messages, setMessages] = React2.useState();
28
- React2.useEffect(() => {
23
+ const [locale, setLocale] = React.useState(initialLocale || DEFAULT_LOCALE);
24
+ const [messages, setMessages] = React.useState();
25
+ React.useEffect(() => {
29
26
  if (loadLocaleData) {
30
27
  loadLocaleData(locale).then((message) => {
31
28
  return setMessages(message);
32
29
  });
33
30
  }
34
31
  }, [loadLocaleData, locale]);
35
- return /* @__PURE__ */ jsx(I18nConfigContext.Provider, {
36
- value: {
37
- defaultLocale: DEFAULT_LOCALE,
38
- locale,
39
- setLocale,
40
- ...intlConfig
41
- },
42
- children: /* @__PURE__ */ jsx(IntlProvider, {
43
- defaultLocale: DEFAULT_LOCALE,
44
- locale,
45
- messages,
46
- ...intlConfig,
47
- children: /* @__PURE__ */ jsx(Fragment, {
48
- children
49
- })
50
- })
51
- });
32
+ return /* @__PURE__ */ jsx(
33
+ I18nConfigContext.Provider,
34
+ {
35
+ value: {
36
+ defaultLocale: DEFAULT_LOCALE,
37
+ locale,
38
+ setLocale,
39
+ ...intlConfig
40
+ },
41
+ children: /* @__PURE__ */ jsx(
42
+ IntlProvider,
43
+ {
44
+ defaultLocale: DEFAULT_LOCALE,
45
+ locale,
46
+ messages,
47
+ ...intlConfig,
48
+ children: /* @__PURE__ */ jsx(Fragment, { children })
49
+ }
50
+ )
51
+ }
52
+ );
52
53
  };
53
54
 
54
55
  // src/useI18n.ts
55
- import * as React3 from "react";
56
+ import * as React2 from "react";
56
57
  import { useIntl } from "react-intl";
57
58
  var useI18n = () => {
58
59
  const intl = useIntl();
59
- const config = React3.useContext(I18nConfigContext);
60
+ const config = React2.useContext(I18nConfigContext);
60
61
  return { ...config, intl };
61
62
  };
62
63
  export {
package/dist/index.d.ts CHANGED
@@ -2,9 +2,9 @@ import * as react_intl from 'react-intl';
2
2
  export { FormattedMessage, defineMessage, defineMessages } from 'react-intl';
3
3
  import * as React from 'react';
4
4
 
5
- declare type MessagesType = any;
6
- declare type LoadLocaleData = (locale: string) => Promise<MessagesType>;
7
- declare type I18nProviderProps = {
5
+ type MessagesType = any;
6
+ type LoadLocaleData = (locale: string) => Promise<MessagesType>;
7
+ type I18nProviderProps = {
8
8
  locale?: string;
9
9
  loadLocaleData?: LoadLocaleData;
10
10
  children?: React.ReactNode;
@@ -13,7 +13,7 @@ declare type I18nProviderProps = {
13
13
  * `DEFAULT_LOCALE` must be `en` because is the default of the other modules.
14
14
  */
15
15
  declare const DEFAULT_LOCALE = "en";
16
- declare const I18nProvider: ({ children, locale, loadLocaleData, ...intlConfig }: I18nProviderProps) => JSX.Element;
16
+ declare const I18nProvider: ({ children, locale: initialLocale, loadLocaleData, ...intlConfig }: I18nProviderProps) => JSX.Element;
17
17
 
18
18
  declare const useI18n: () => {
19
19
  intl: react_intl.IntlShape;
package/dist/index.js CHANGED
@@ -35,19 +35,14 @@ __export(src_exports, {
35
35
  useI18n: () => useI18n
36
36
  });
37
37
  module.exports = __toCommonJS(src_exports);
38
-
39
- // tsup.inject.js
40
- var React = __toESM(require("react"));
41
-
42
- // src/index.ts
43
38
  var import_react_intl3 = require("react-intl");
44
39
 
45
40
  // src/i18Provider.tsx
46
- var React2 = __toESM(require("react"));
41
+ var React = __toESM(require("react"));
47
42
  var import_react_intl = require("react-intl");
48
43
  var import_jsx_runtime = require("react/jsx-runtime");
49
44
  var DEFAULT_LOCALE = "en";
50
- var I18nConfigContext = React2.createContext({
45
+ var I18nConfigContext = React.createContext({
51
46
  defaultLocale: DEFAULT_LOCALE,
52
47
  setLocale: () => {
53
48
  return null;
@@ -59,40 +54,44 @@ var I18nProvider = ({
59
54
  loadLocaleData,
60
55
  ...intlConfig
61
56
  }) => {
62
- const [locale, setLocale] = React2.useState(initialLocale || DEFAULT_LOCALE);
63
- const [messages, setMessages] = React2.useState();
64
- React2.useEffect(() => {
57
+ const [locale, setLocale] = React.useState(initialLocale || DEFAULT_LOCALE);
58
+ const [messages, setMessages] = React.useState();
59
+ React.useEffect(() => {
65
60
  if (loadLocaleData) {
66
61
  loadLocaleData(locale).then((message) => {
67
62
  return setMessages(message);
68
63
  });
69
64
  }
70
65
  }, [loadLocaleData, locale]);
71
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(I18nConfigContext.Provider, {
72
- value: {
73
- defaultLocale: DEFAULT_LOCALE,
74
- locale,
75
- setLocale,
76
- ...intlConfig
77
- },
78
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_intl.IntlProvider, {
79
- defaultLocale: DEFAULT_LOCALE,
80
- locale,
81
- messages,
82
- ...intlConfig,
83
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
84
- children
85
- })
86
- })
87
- });
66
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
67
+ I18nConfigContext.Provider,
68
+ {
69
+ value: {
70
+ defaultLocale: DEFAULT_LOCALE,
71
+ locale,
72
+ setLocale,
73
+ ...intlConfig
74
+ },
75
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
76
+ import_react_intl.IntlProvider,
77
+ {
78
+ defaultLocale: DEFAULT_LOCALE,
79
+ locale,
80
+ messages,
81
+ ...intlConfig,
82
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children })
83
+ }
84
+ )
85
+ }
86
+ );
88
87
  };
89
88
 
90
89
  // src/useI18n.ts
91
- var React3 = __toESM(require("react"));
90
+ var React2 = __toESM(require("react"));
92
91
  var import_react_intl2 = require("react-intl");
93
92
  var useI18n = () => {
94
93
  const intl = (0, import_react_intl2.useIntl)();
95
- const config = React3.useContext(I18nConfigContext);
94
+ const config = React2.useContext(I18nConfigContext);
96
95
  return { ...config, intl };
97
96
  };
98
97
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/react-i18n",
3
- "version": "1.17.2",
3
+ "version": "1.18.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -9,11 +9,7 @@
9
9
  ],
10
10
  "main": "dist/index.js",
11
11
  "module": "dist/esm/index.js",
12
- "bin": {
13
- "ttoss-i18n": "./bin/cli.js"
14
- },
15
12
  "files": [
16
- "bin",
17
13
  "dist",
18
14
  "src"
19
15
  ],
@@ -29,15 +25,15 @@
29
25
  },
30
26
  "typings": "dist/index.d.ts",
31
27
  "dependencies": {
32
- "glob": "^8.0.3",
33
28
  "react-intl": "^6.2.5"
34
29
  },
35
30
  "peerDependencies": {
36
31
  "react": ">=16.8.0"
37
32
  },
38
33
  "devDependencies": {
39
- "@formatjs/cli": "^5.1.7",
34
+ "@formatjs/cli": "^5.1.10",
40
35
  "@ttoss/config": "^1.25.0",
36
+ "@ttoss/i18n-cli": "^0.2.0",
41
37
  "@ttoss/test-utils": "^1.18.3"
42
38
  },
43
39
  "keywords": [
@@ -48,5 +44,5 @@
48
44
  "publishConfig": {
49
45
  "access": "public"
50
46
  },
51
- "gitHead": "88b98945c469cdfdece6b12ce41243403ad2c242"
47
+ "gitHead": "9159bd57009f4fee620218bc1a0e7bbac28acccd"
52
48
  }
package/bin/cli.js DELETED
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { compile, extract } = require('@formatjs/cli');
4
- const fs = require('fs');
5
- const glob = require('glob');
6
- const path = require('path');
7
-
8
- const DEFAULT_DIR = 'i18n';
9
-
10
- const EXTRACT_DIR = path.join(DEFAULT_DIR, 'lang');
11
-
12
- const COMPILE_DIR = path.join(DEFAULT_DIR, 'compiled-lang');
13
-
14
- const args = process.argv.slice(2);
15
-
16
- (async () => {
17
- /**
18
- * Extract
19
- */
20
- const extractedDataAsString = await extract(glob.sync('src/**/*.{ts,tsx}'), {
21
- idInterpolationPattern: '[sha512:contenthash:base64:6]',
22
- });
23
-
24
- await fs.promises.mkdir(EXTRACT_DIR, { recursive: true });
25
-
26
- await fs.promises.writeFile(
27
- path.join(EXTRACT_DIR, 'en.json'),
28
- extractedDataAsString
29
- );
30
-
31
- if (args.includes('--no-compile')) {
32
- return;
33
- }
34
-
35
- /**
36
- * Compile
37
- */
38
- await fs.promises.mkdir(COMPILE_DIR, {
39
- recursive: true,
40
- });
41
-
42
- const translations = glob.sync(EXTRACT_DIR + '/*.json');
43
-
44
- for (const translation of translations) {
45
- const filename = translation.split('/').pop();
46
-
47
- const compiledDataAsString = await compile([translation], {
48
- ast: true,
49
- });
50
-
51
- await fs.promises.writeFile(
52
- path.join(COMPILE_DIR, filename),
53
- compiledDataAsString
54
- );
55
- }
56
- })();