@ttoss/react-i18n 1.19.2 → 1.19.4
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 +24 -32
- package/dist/index.js +43 -37
- package/package.json +7 -7
package/dist/esm/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import * as React from "react";
|
|
|
8
8
|
import { IntlProvider } from "react-intl";
|
|
9
9
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
10
10
|
var DEFAULT_LOCALE = "en";
|
|
11
|
-
var I18nConfigContext = React.createContext({
|
|
11
|
+
var I18nConfigContext = /*#__PURE__*/React.createContext({
|
|
12
12
|
defaultLocale: DEFAULT_LOCALE,
|
|
13
13
|
setLocale: () => {
|
|
14
14
|
return null;
|
|
@@ -24,32 +24,28 @@ var I18nProvider = ({
|
|
|
24
24
|
const [messages, setMessages] = React.useState();
|
|
25
25
|
React.useEffect(() => {
|
|
26
26
|
if (loadLocaleData) {
|
|
27
|
-
loadLocaleData(locale).then(
|
|
27
|
+
loadLocaleData(locale).then(message => {
|
|
28
28
|
return setMessages(message);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
}, [loadLocaleData, locale]);
|
|
32
|
-
return /* @__PURE__ */
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
);
|
|
32
|
+
return /* @__PURE__ */jsx(I18nConfigContext.Provider, {
|
|
33
|
+
value: {
|
|
34
|
+
defaultLocale: DEFAULT_LOCALE,
|
|
35
|
+
locale,
|
|
36
|
+
setLocale,
|
|
37
|
+
...intlConfig
|
|
38
|
+
},
|
|
39
|
+
children: /* @__PURE__ */jsx(IntlProvider, {
|
|
40
|
+
defaultLocale: DEFAULT_LOCALE,
|
|
41
|
+
locale,
|
|
42
|
+
messages,
|
|
43
|
+
...intlConfig,
|
|
44
|
+
children: /* @__PURE__ */jsx(Fragment, {
|
|
45
|
+
children
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
});
|
|
53
49
|
};
|
|
54
50
|
|
|
55
51
|
// src/useI18n.ts
|
|
@@ -58,13 +54,9 @@ import { useIntl } from "react-intl";
|
|
|
58
54
|
var useI18n = () => {
|
|
59
55
|
const intl = useIntl();
|
|
60
56
|
const config = React2.useContext(I18nConfigContext);
|
|
61
|
-
return {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
FormattedMessage,
|
|
66
|
-
I18nProvider,
|
|
67
|
-
defineMessage,
|
|
68
|
-
defineMessages,
|
|
69
|
-
useI18n
|
|
57
|
+
return {
|
|
58
|
+
...config,
|
|
59
|
+
intl
|
|
60
|
+
};
|
|
70
61
|
};
|
|
62
|
+
export { DEFAULT_LOCALE, FormattedMessage, I18nProvider, defineMessage, defineMessages, useI18n };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
2
|
"use strict";
|
|
3
|
+
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,26 +8,32 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
12
15
|
};
|
|
13
16
|
var __copyProps = (to, from, except, desc) => {
|
|
14
17
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
18
22
|
}
|
|
19
23
|
return to;
|
|
20
24
|
};
|
|
21
25
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
mod
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
31
|
+
value: mod,
|
|
32
|
+
enumerable: true
|
|
33
|
+
}) : target, mod));
|
|
34
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
35
|
+
value: true
|
|
36
|
+
}), mod);
|
|
30
37
|
|
|
31
38
|
// src/index.ts
|
|
32
39
|
var src_exports = {};
|
|
@@ -62,32 +69,28 @@ var I18nProvider = ({
|
|
|
62
69
|
const [messages, setMessages] = React.useState();
|
|
63
70
|
React.useEffect(() => {
|
|
64
71
|
if (loadLocaleData) {
|
|
65
|
-
loadLocaleData(locale).then(
|
|
72
|
+
loadLocaleData(locale).then(message => {
|
|
66
73
|
return setMessages(message);
|
|
67
74
|
});
|
|
68
75
|
}
|
|
69
76
|
}, [loadLocaleData, locale]);
|
|
70
|
-
return /* @__PURE__ */
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
)
|
|
89
|
-
}
|
|
90
|
-
);
|
|
77
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(I18nConfigContext.Provider, {
|
|
78
|
+
value: {
|
|
79
|
+
defaultLocale: DEFAULT_LOCALE,
|
|
80
|
+
locale,
|
|
81
|
+
setLocale,
|
|
82
|
+
...intlConfig
|
|
83
|
+
},
|
|
84
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_intl.IntlProvider, {
|
|
85
|
+
defaultLocale: DEFAULT_LOCALE,
|
|
86
|
+
locale,
|
|
87
|
+
messages,
|
|
88
|
+
...intlConfig,
|
|
89
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
90
|
+
children
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
});
|
|
91
94
|
};
|
|
92
95
|
|
|
93
96
|
// src/useI18n.ts
|
|
@@ -96,7 +99,10 @@ var import_react_intl2 = require("react-intl");
|
|
|
96
99
|
var useI18n = () => {
|
|
97
100
|
const intl = (0, import_react_intl2.useIntl)();
|
|
98
101
|
const config = React2.useContext(I18nConfigContext);
|
|
99
|
-
return {
|
|
102
|
+
return {
|
|
103
|
+
...config,
|
|
104
|
+
intl
|
|
105
|
+
};
|
|
100
106
|
};
|
|
101
107
|
// Annotate the CommonJS export names for ESM import in node:
|
|
102
108
|
0 && (module.exports = {
|
|
@@ -106,4 +112,4 @@ var useI18n = () => {
|
|
|
106
112
|
defineMessage,
|
|
107
113
|
defineMessages,
|
|
108
114
|
useI18n
|
|
109
|
-
});
|
|
115
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-i18n",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.4",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"build": "tsup",
|
|
18
18
|
"dev": "yarn workspace @ttoss/storybook run dev",
|
|
19
19
|
"pretest:compile": "yarn run pretest:compile:en && yarn run pretest:compile:ptBR",
|
|
20
|
-
"pretest:compile:en": "formatjs compile i18n/lang/en.json --ast --out-file i18n/compiled
|
|
21
|
-
"pretest:compile:ptBR": "formatjs compile i18n/lang/pt-BR.json --ast --out-file i18n/compiled
|
|
20
|
+
"pretest:compile:en": "formatjs compile i18n/lang/en.json --ast --out-file i18n/compiled/en.json",
|
|
21
|
+
"pretest:compile:ptBR": "formatjs compile i18n/lang/pt-BR.json --ast --out-file i18n/compiled/pt-BR.json",
|
|
22
22
|
"pretest:extract": "formatjs extract 'tests/**/*.ts*' --out-file i18n/lang/en.json",
|
|
23
23
|
"pretest": "yarn run pretest:extract && yarn run pretest:compile",
|
|
24
24
|
"test": "jest"
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@formatjs/cli": "^6.0.4",
|
|
36
|
-
"@ttoss/config": "^1.29.
|
|
37
|
-
"@ttoss/i18n-cli": "^0.4.
|
|
38
|
-
"@ttoss/test-utils": "^1.
|
|
36
|
+
"@ttoss/config": "^1.29.2",
|
|
37
|
+
"@ttoss/i18n-cli": "^0.4.3",
|
|
38
|
+
"@ttoss/test-utils": "^1.21.0"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"React",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "01701f2c03d9872297d85af0a33d1ca4c2a6eb6b"
|
|
49
49
|
}
|