@ttoss/react-i18n 1.26.15 → 2.0.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 +1 -1
- package/package.json +4 -4
- package/dist/index.d.mts +0 -32
- package/dist/index.js +0 -122
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 =
|
|
11
|
+
var I18nConfigContext = React.createContext({
|
|
12
12
|
defaultLocale: DEFAULT_LOCALE,
|
|
13
13
|
messages: {},
|
|
14
14
|
setLocale: () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-i18n",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "ttoss",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Pedro Arantes <arantespp@gmail.com> (https://arantespp.com)",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"url": "https://github.com/ttoss/ttoss.git",
|
|
12
12
|
"directory": "packages/react-i18n"
|
|
13
13
|
},
|
|
14
|
+
"type": "module",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"import": "./dist/esm/index.js",
|
|
17
|
-
"require": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"jest": "^29.7.0",
|
|
36
36
|
"react": "^18.3.1",
|
|
37
37
|
"tsup": "^8.2.4",
|
|
38
|
-
"@ttoss/config": "^1.32.9",
|
|
39
38
|
"@ttoss/i18n-cli": "^0.7.18",
|
|
39
|
+
"@ttoss/config": "^1.32.9",
|
|
40
40
|
"@ttoss/test-utils": "^2.1.13"
|
|
41
41
|
},
|
|
42
42
|
"keywords": [
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"dev": "pnpm --filter @docs/storybook run dev",
|
|
54
54
|
"i18n": "ttoss-i18n --pattern 'tests/**/*.test.{ts,tsx}'",
|
|
55
55
|
"pretest": "pnpm run i18n",
|
|
56
|
-
"test": "jest"
|
|
56
|
+
"test": "jest --projects tests/unit"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as react_intl from 'react-intl';
|
|
2
|
-
import { MessageFormatElement } from 'react-intl';
|
|
3
|
-
export { FormattedMessage, IntlShape, MessageDescriptor, defineMessage, defineMessages } from 'react-intl';
|
|
4
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
|
|
7
|
-
type Messages = Record<string, string> | Record<string, MessageFormatElement[]>;
|
|
8
|
-
type LoadLocaleData = (locale: string) => Promise<Messages> | Messages;
|
|
9
|
-
type I18nProviderProps = {
|
|
10
|
-
locale?: string;
|
|
11
|
-
loadLocaleData?: LoadLocaleData;
|
|
12
|
-
children?: React.ReactNode;
|
|
13
|
-
onError?: (err: Error) => void;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* `DEFAULT_LOCALE` must be `en` because is the default of the other modules.
|
|
17
|
-
*/
|
|
18
|
-
declare const DEFAULT_LOCALE = "en";
|
|
19
|
-
declare const I18nProvider: ({ children, locale: initialLocale, loadLocaleData, ...intlConfig }: I18nProviderProps) => react_jsx_runtime.JSX.Element;
|
|
20
|
-
|
|
21
|
-
declare const useI18n: () => {
|
|
22
|
-
intl: react_intl.IntlShape;
|
|
23
|
-
locale?: string | undefined;
|
|
24
|
-
loadLocaleData?: LoadLocaleData | undefined;
|
|
25
|
-
children?: React.ReactNode;
|
|
26
|
-
onError?: ((err: Error) => void) | undefined;
|
|
27
|
-
defaultLocale: string;
|
|
28
|
-
messages?: Messages;
|
|
29
|
-
setLocale: (language: string) => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { DEFAULT_LOCALE, I18nProvider, type I18nProviderProps, type LoadLocaleData, useI18n };
|
package/dist/index.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var __create = Object.create;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __export = (target, all) => {
|
|
11
|
-
for (var name in all) __defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
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
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return to;
|
|
24
|
-
};
|
|
25
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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);
|
|
37
|
-
|
|
38
|
-
// src/index.ts
|
|
39
|
-
var src_exports = {};
|
|
40
|
-
__export(src_exports, {
|
|
41
|
-
DEFAULT_LOCALE: () => DEFAULT_LOCALE,
|
|
42
|
-
FormattedMessage: () => import_react_intl3.FormattedMessage,
|
|
43
|
-
I18nProvider: () => I18nProvider,
|
|
44
|
-
defineMessage: () => import_react_intl3.defineMessage,
|
|
45
|
-
defineMessages: () => import_react_intl3.defineMessages,
|
|
46
|
-
useI18n: () => useI18n
|
|
47
|
-
});
|
|
48
|
-
module.exports = __toCommonJS(src_exports);
|
|
49
|
-
var import_react_intl3 = require("react-intl");
|
|
50
|
-
|
|
51
|
-
// src/i18Provider.tsx
|
|
52
|
-
var React = __toESM(require("react"));
|
|
53
|
-
var import_react_intl = require("react-intl");
|
|
54
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
55
|
-
var DEFAULT_LOCALE = "en";
|
|
56
|
-
var I18nConfigContext = React.createContext({
|
|
57
|
-
defaultLocale: DEFAULT_LOCALE,
|
|
58
|
-
messages: {},
|
|
59
|
-
setLocale: () => {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
var I18nProvider = ({
|
|
64
|
-
children,
|
|
65
|
-
locale: initialLocale,
|
|
66
|
-
loadLocaleData,
|
|
67
|
-
...intlConfig
|
|
68
|
-
}) => {
|
|
69
|
-
const [locale, setLocale] = React.useState(initialLocale || DEFAULT_LOCALE);
|
|
70
|
-
const [messagesAndLocale, setMessagesAndLocale] = React.useState({
|
|
71
|
-
locale: DEFAULT_LOCALE
|
|
72
|
-
});
|
|
73
|
-
React.useEffect(() => {
|
|
74
|
-
if (loadLocaleData && locale) {
|
|
75
|
-
Promise.resolve(loadLocaleData(locale)).then(messages => {
|
|
76
|
-
setMessagesAndLocale({
|
|
77
|
-
messages,
|
|
78
|
-
locale
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}, [loadLocaleData, locale]);
|
|
83
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(I18nConfigContext.Provider, {
|
|
84
|
-
value: {
|
|
85
|
-
locale,
|
|
86
|
-
defaultLocale: DEFAULT_LOCALE,
|
|
87
|
-
messages: messagesAndLocale.messages,
|
|
88
|
-
setLocale,
|
|
89
|
-
...intlConfig
|
|
90
|
-
},
|
|
91
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_intl.IntlProvider, {
|
|
92
|
-
defaultLocale: DEFAULT_LOCALE,
|
|
93
|
-
locale: messagesAndLocale.locale,
|
|
94
|
-
messages: messagesAndLocale.messages,
|
|
95
|
-
...intlConfig,
|
|
96
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
97
|
-
children
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// src/useI18n.ts
|
|
104
|
-
var React2 = __toESM(require("react"));
|
|
105
|
-
var import_react_intl2 = require("react-intl");
|
|
106
|
-
var useI18n = () => {
|
|
107
|
-
const intl = (0, import_react_intl2.useIntl)();
|
|
108
|
-
const config = React2.useContext(I18nConfigContext);
|
|
109
|
-
return {
|
|
110
|
-
...config,
|
|
111
|
-
intl
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
-
0 && (module.exports = {
|
|
116
|
-
DEFAULT_LOCALE,
|
|
117
|
-
FormattedMessage,
|
|
118
|
-
I18nProvider,
|
|
119
|
-
defineMessage,
|
|
120
|
-
defineMessages,
|
|
121
|
-
useI18n
|
|
122
|
-
});
|