@tolgee/react 5.0.0-rc.0b3e627.0 → 5.0.0-rc.704ada9.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/README.md +138 -27
- package/README.njk.md +84 -0
- package/dist/GlobalContextPlugin.d.ts +1 -1
- package/dist/T.d.ts +3 -2
- package/dist/TolgeeProvider.d.ts +2 -1
- package/dist/hooks.d.ts +4 -1
- package/dist/index.d.ts +2 -3
- package/dist/tagsTools.d.ts +2 -1
- package/dist/tolgee-react.cjs.js +41 -68
- package/dist/tolgee-react.cjs.js.map +1 -1
- package/dist/tolgee-react.cjs.min.js +1 -1
- package/dist/tolgee-react.cjs.min.js.map +1 -1
- package/dist/{tolgee-react.esm.mjs → tolgee-react.esm.js} +39 -61
- package/dist/tolgee-react.esm.js.map +1 -0
- package/dist/tolgee-react.esm.min.mjs +1 -1
- package/dist/tolgee-react.esm.min.mjs.map +1 -1
- package/dist/tolgee-react.umd.js +44 -70
- package/dist/tolgee-react.umd.js.map +1 -1
- package/dist/tolgee-react.umd.min.js +1 -1
- package/dist/tolgee-react.umd.min.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/useTolgee.d.ts +1 -1
- package/dist/useTranslate.d.ts +1 -1
- package/dist/useTranslateInternal.d.ts +2 -2
- package/lib/GlobalContextPlugin.d.ts +1 -1
- package/lib/T.d.ts +3 -2
- package/lib/TolgeeProvider.d.ts +2 -1
- package/lib/hooks.d.ts +4 -1
- package/lib/index.d.ts +2 -3
- package/lib/tagsTools.d.ts +2 -1
- package/lib/types.d.ts +1 -1
- package/lib/useTolgee.d.ts +1 -1
- package/lib/useTranslate.d.ts +1 -1
- package/lib/useTranslateInternal.d.ts +2 -2
- package/package.json +10 -7
- package/dist/ReactPlugin.d.ts +0 -6
- package/dist/TolgeeProvider.spec.d.ts +0 -1
- package/dist/__integration/T.spec.d.ts +0 -1
- package/dist/__integration/TolgeeProvider.spec.d.ts +0 -6
- package/dist/__integration/mockTranslations.d.ts +0 -23
- package/dist/__integration/namespaces.spec.d.ts +0 -1
- package/dist/__integration/testConfig.d.ts +0 -9
- package/dist/__integration/tools.d.ts +0 -1
- package/dist/__integration/useTolgee.spec.d.ts +0 -1
- package/dist/__integration/useTranslation.spec.d.ts +0 -1
- package/dist/tolgee-react.esm.mjs.map +0 -1
- package/index.js +0 -7
- package/lib/ReactPlugin.d.ts +0 -6
package/README.md
CHANGED
|
@@ -1,44 +1,90 @@
|
|
|
1
|
+
<!-- This file was generated using pnpm generate-readmes script
|
|
2
|
+
|
|
3
|
+
Don't edit this file. Edit the README.md.njk. Macros can be found in readmeMacros/macros.njk
|
|
4
|
+
|
|
5
|
+
-->
|
|
6
|
+
|
|
7
|
+
<h1 align="center" style="border-bottom: none">
|
|
8
|
+
<b>
|
|
9
|
+
<a href="https://tolgee.io">Tolgee for React</a><br>
|
|
10
|
+
</b>
|
|
11
|
+
The Tolgee i18n SDK for React
|
|
12
|
+
<br>
|
|
13
|
+
</h1>
|
|
14
|
+
|
|
15
|
+
<div align="center">
|
|
16
|
+
|
|
17
|
+
[](https://tolgee.io)
|
|
18
|
+
|
|
19
|
+
Tolgee is an open-source alternative to Crowdin, Phrase, or Lokalise with its very own revolutionary integrations.
|
|
20
|
+
|
|
1
21
|

|
|
2
|
-
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
3
25
|

|
|
26
|
+

|
|
4
27
|

|
|
5
|
-
[](https://github.com/tolgee/tolgee-js)
|
|
29
|
+
[](https://github.com/tolgee/server)
|
|
30
|
+
[](https://github.com/tolgee/tolgee-platform/discussions)
|
|
31
|
+
</div>
|
|
7
32
|
|
|
8
|
-
|
|
33
|
+
<div align="center">
|
|
9
34
|
|
|
10
|
-
|
|
11
|
-
[
|
|
35
|
+
[<img src="https://img.shields.io/badge/-Facebook-424549?style=social&logo=facebook" height=25 />](https://www.facebook.com/Tolgee.i18n)
|
|
36
|
+
[<img src="https://img.shields.io/badge/-Twitter-424549?style=social&logo=twitter" height=25 />](https://twitter.com/Tolgee_i18n)
|
|
37
|
+
[<img src="https://img.shields.io/badge/-Linkedin-424549?style=social&logo=linkedin" height=25 />](https://www.linkedin.com/company/tolgee)
|
|
12
38
|
|
|
13
|
-
[<img src="https://
|
|
39
|
+
**Become part of the family. Join [slack channel <img src="https://img.shields.io/badge/-Tolgee Comunity-424549?style=social&logo=slack" height=25 />](https://join.slack.com/t/tolgeecommunity/shared_invite/zt-195isb5u8-_RcSRgVJfvgsPpOBIok~IQ)**
|
|
14
40
|
|
|
15
|
-
|
|
16
|
-
Tolgee is extremely simple! 🇯🇵 🇰🇷 🇩🇪 🇨🇳 🇺🇸 🇫🇷 🇪🇸 🇮🇹 🇷🇺 🇬🇧
|
|
41
|
+
</div>
|
|
17
42
|
|
|
18
|
-
## Features
|
|
19
43
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
|
|
45
|
+
# What is Tolgee for React?
|
|
46
|
+
React integration library of Tolgee. This package makes it super simple to add i18n to your React app!
|
|
47
|
+
For more information about using Tolgee with React, visit the [docs 📖](https://tolgee.io/integrations/react).
|
|
48
|
+
|
|
49
|
+
Localize (translate) your CRA, Gatsby, Next.js, or other React projects to multiple languages with Tolgee. Integration of Tolgee is extremely simple! 🇯🇵 🇰🇷 🇩🇪 🇨🇳 🇺🇸 🇫🇷 🇪🇸 🇮🇹 🇷🇺 🇬🇧
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Quick links
|
|
53
|
+
- [Tolgee for React docs](https://tolgee.io/js-sdk/5.0.0-alpha.1/integrations/react/installation)
|
|
54
|
+
- [Tolgee JS SDK docs](https://tolgee.io/js-sdk)
|
|
55
|
+
- [Tolgee Website](https://tolgee.io)
|
|
56
|
+
- Product (Learn more about the great features)
|
|
57
|
+
- [Dev tools](https://tolgee.io/features/dev-tools)
|
|
58
|
+
- [Translation assistance](https://tolgee.io/features/translation-assistance)
|
|
59
|
+
- [Collaboration](https://tolgee.io/features/collaboration)
|
|
60
|
+
- [Tolgee platform docs](https://tolgee.io/platform)
|
|
61
|
+
|
|
62
|
+
|
|
25
63
|
|
|
26
64
|
## Installation
|
|
27
65
|
|
|
28
|
-
|
|
66
|
+
```
|
|
67
|
+
npm install @tolgee/react
|
|
68
|
+
```
|
|
29
69
|
|
|
30
|
-
npm install @tolgee/react
|
|
31
70
|
|
|
32
71
|
Then use the library in your app:
|
|
33
72
|
|
|
34
73
|
```typescript jsx
|
|
35
|
-
import { TolgeeProvider } from "@tolgee/react";
|
|
74
|
+
import { TolgeeProvider, ReactPlugin, FormatSimple } from "@tolgee/react";
|
|
75
|
+
|
|
76
|
+
const tolgee = Tolgee()
|
|
77
|
+
.use(ReactPlugin())
|
|
78
|
+
.use(FormatSimple())
|
|
79
|
+
.init({
|
|
80
|
+
language: 'en',
|
|
81
|
+
apiUrl: process.env.REACT_APP_TOLGEE_API_URL,
|
|
82
|
+
apiKey: process.env.REACT_APP_TOLGEE_API_KEY
|
|
83
|
+
});
|
|
36
84
|
|
|
37
|
-
...
|
|
38
85
|
|
|
39
86
|
<TolgeeProvider
|
|
40
|
-
|
|
41
|
-
apiKey={process.env.REACT_APP_TOLGEE_API_KEY}
|
|
87
|
+
tolgee={tolgee}
|
|
42
88
|
>
|
|
43
89
|
<Your app components>
|
|
44
90
|
</TolgeeProvider>
|
|
@@ -73,20 +119,85 @@ import { useTranslate } from "@tolgee/react";
|
|
|
73
119
|
|
|
74
120
|
...
|
|
75
121
|
|
|
76
|
-
const t = useTranslate();
|
|
122
|
+
const { t } = useTranslate();
|
|
77
123
|
|
|
78
124
|
...
|
|
79
125
|
|
|
80
126
|
t("key_to_translate")
|
|
81
127
|
```
|
|
82
128
|
|
|
129
|
+
|
|
83
130
|
## Prerequisites
|
|
84
131
|
|
|
85
|
-
1. You have some React
|
|
86
|
-
2. You have generated API key from [Tolgee Cloud](https://app.tolgee.io) or self-hosted Tolgee instance.
|
|
132
|
+
1. You have some React-based project
|
|
133
|
+
2. You have generated an API key from [Tolgee Cloud](https://app.tolgee.io) or a self-hosted Tolgee instance.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
## Why to use Tolgee?
|
|
138
|
+
Because it saves a lot of time, you would spend on localization tasks without it. Because it enables you to provide perfectly translated software.
|
|
139
|
+
|
|
140
|
+
### Features
|
|
141
|
+
|
|
142
|
+
- All-in-one localization solution for your JS application 🙌
|
|
143
|
+
- Out-of-box in-context localization 🎉
|
|
144
|
+
- Automated screenshot generation 📷
|
|
145
|
+
- Translation management platform 🎈
|
|
146
|
+
- Open-source 🔥
|
|
147
|
+
|
|
148
|
+

|
|
149
|
+
Read more on the [Tolgee website](https://tolgee.io)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
## Development
|
|
153
|
+
|
|
154
|
+
We welcome your PRs.
|
|
155
|
+
|
|
156
|
+
To develop the package locally:
|
|
157
|
+
1. Clone [the repository](https://github.com/tolgee/tolgee-js)
|
|
158
|
+
1. Install the packages in the repository root
|
|
159
|
+
```
|
|
160
|
+
pnpm install
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
1. Run the development script
|
|
165
|
+
```
|
|
166
|
+
pnpm develop:react
|
|
167
|
+
```
|
|
168
|
+
This runs the development suite of this monorepo for the `react` integration. The changes in each dependency package are
|
|
169
|
+
automatically built and propagated to the test application, which you can open and play within the browser.
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
### Testing
|
|
175
|
+
|
|
176
|
+
To run Jest tests of this package, execute
|
|
177
|
+
```
|
|
178
|
+
npm run test
|
|
179
|
+
```
|
|
180
|
+
In the `/packages/react` directory.
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### End-to-end (e2e) testing
|
|
186
|
+
To run the e2e tests, simply execute
|
|
187
|
+
```
|
|
188
|
+
pnpm run e2e run react
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
To open and play with e2e tests, run:
|
|
192
|
+
```
|
|
193
|
+
pnpm run e2e open react
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
|
|
87
197
|
|
|
88
|
-
##
|
|
198
|
+
## Contributors
|
|
89
199
|
|
|
90
|
-
|
|
200
|
+
<a href="https://github.com/tolgee/tolgee-platform/graphs/contributors">
|
|
201
|
+
<img alt="contributors" src="https://contrib.rocks/image?repo=tolgee/tolgee-js"/>
|
|
202
|
+
</a>
|
|
91
203
|
|
|
92
|
-
Learn more at our [documentation website 📖](https://tolgee.io).
|
package/README.njk.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{% import "../../readmeMacros/macros.njk.md" as macros %}
|
|
2
|
+
{{ macros.header('Tolgee for React', 'The Tolgee i18n SDK for React', packageName) }}
|
|
3
|
+
|
|
4
|
+
# What is Tolgee for React?
|
|
5
|
+
React integration library of Tolgee. This package makes it super simple to add i18n to your React app!
|
|
6
|
+
For more information about using Tolgee with React, visit the [docs 📖](https://tolgee.io/integrations/react).
|
|
7
|
+
|
|
8
|
+
Localize (translate) your CRA, Gatsby, Next.js, or other React projects to multiple languages with Tolgee. Integration of Tolgee is extremely simple! 🇯🇵 🇰🇷 🇩🇪 🇨🇳 🇺🇸 🇫🇷 🇪🇸 🇮🇹 🇷🇺 🇬🇧
|
|
9
|
+
|
|
10
|
+
{{ macros.integrationLinks('Tolgee for React docs', macros.v5link('integrations/react/installation')) }}
|
|
11
|
+
|
|
12
|
+
{{ macros.installation('react') }}
|
|
13
|
+
|
|
14
|
+
Then use the library in your app:
|
|
15
|
+
|
|
16
|
+
```typescript jsx
|
|
17
|
+
import { TolgeeProvider, ReactPlugin, FormatSimple } from "@tolgee/react";
|
|
18
|
+
|
|
19
|
+
const tolgee = Tolgee()
|
|
20
|
+
.use(ReactPlugin())
|
|
21
|
+
.use(FormatSimple())
|
|
22
|
+
.init({
|
|
23
|
+
language: 'en',
|
|
24
|
+
apiUrl: process.env.REACT_APP_TOLGEE_API_URL,
|
|
25
|
+
apiKey: process.env.REACT_APP_TOLGEE_API_KEY
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
<TolgeeProvider
|
|
30
|
+
tolgee={tolgee}
|
|
31
|
+
>
|
|
32
|
+
<Your app components>
|
|
33
|
+
</TolgeeProvider>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
To translate texts using Tolgee React integration, you can use `T` component or `useTranslate` hook.
|
|
41
|
+
|
|
42
|
+
### T component
|
|
43
|
+
|
|
44
|
+
```typescript jsx
|
|
45
|
+
import { T } from "@tolgee/react";
|
|
46
|
+
|
|
47
|
+
...
|
|
48
|
+
|
|
49
|
+
<T>translation_key</T>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
or
|
|
53
|
+
|
|
54
|
+
```typescript jsx
|
|
55
|
+
<T keyName="translation_key">Default value</T>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### useTranslate hook
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
import { useTranslate } from "@tolgee/react";
|
|
62
|
+
|
|
63
|
+
...
|
|
64
|
+
|
|
65
|
+
const { t } = useTranslate();
|
|
66
|
+
|
|
67
|
+
...
|
|
68
|
+
|
|
69
|
+
t("key_to_translate")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
{{ macros.prereq('React') }}
|
|
73
|
+
|
|
74
|
+
{{ macros.why() }}
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
{{ macros.developmentInstallation() }}
|
|
78
|
+
{{ macros.development('react') }}
|
|
79
|
+
|
|
80
|
+
{{ macros.developmentTesting('/packages/react') }}
|
|
81
|
+
|
|
82
|
+
{{ macros.e2eTesting('react') }}
|
|
83
|
+
|
|
84
|
+
{{ macros.contributors() }}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TolgeePlugin } from '@tolgee/
|
|
1
|
+
import type { TolgeePlugin } from '@tolgee/web';
|
|
2
2
|
import type { ReactOptions, TolgeeReactContext } from './types';
|
|
3
3
|
export declare const GlobalContextPlugin: (options?: Partial<ReactOptions>) => TolgeePlugin;
|
|
4
4
|
export declare function getGlobalContext(): TolgeeReactContext | undefined;
|
package/dist/T.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NsType, TranslateParams } from '@tolgee/web';
|
|
2
2
|
import { FunctionComponent } from 'react';
|
|
3
3
|
import { ParamsTags } from './types';
|
|
4
4
|
declare type TProps = {
|
|
@@ -6,7 +6,8 @@ declare type TProps = {
|
|
|
6
6
|
children?: string;
|
|
7
7
|
noWrap?: boolean;
|
|
8
8
|
keyName?: string;
|
|
9
|
-
ns?:
|
|
9
|
+
ns?: NsType;
|
|
10
|
+
defaultValue?: string;
|
|
10
11
|
};
|
|
11
12
|
export declare const T: FunctionComponent<TProps>;
|
|
12
13
|
export {};
|
package/dist/TolgeeProvider.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { TolgeeInstance } from '@tolgee/
|
|
2
|
+
import { TolgeeInstance } from '@tolgee/web';
|
|
3
3
|
import { ReactOptions, TolgeeReactContext } from './types';
|
|
4
4
|
export declare const DEFAULT_REACT_OPTIONS: ReactOptions;
|
|
5
5
|
export declare const TolgeeProviderContext: React.Context<TolgeeReactContext | undefined>;
|
|
6
6
|
declare type Props = {
|
|
7
|
+
children?: React.ReactNode;
|
|
7
8
|
tolgee: TolgeeInstance;
|
|
8
9
|
options?: ReactOptions;
|
|
9
10
|
fallback?: React.ReactNode;
|
package/dist/hooks.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export { useTranslate } from './useTranslate';
|
|
|
2
2
|
export { TolgeeProvider, TolgeeProviderContext } from './TolgeeProvider';
|
|
3
3
|
export { T } from './T';
|
|
4
4
|
export { useTolgee } from './useTolgee';
|
|
5
|
-
export {
|
|
5
|
+
export { GlobalContextPlugin } from './GlobalContextPlugin';
|
|
6
6
|
export * from './types';
|
|
7
|
-
export * from '@tolgee/
|
|
8
|
-
export * from '@tolgee/devtools-web';
|
|
7
|
+
export * from '@tolgee/web';
|
package/dist/tagsTools.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { TranslateParams } from '@tolgee/web';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { ParamsTags } from './types';
|
|
3
|
-
export declare const wrapTagHandlers: (params: ParamsTags) => any;
|
|
4
|
+
export declare const wrapTagHandlers: (params: TranslateParams<ParamsTags> | undefined) => any;
|
|
4
5
|
export declare const addReactKeys: (val: React.ReactNode | React.ReactNode[] | undefined) => React.ReactNode;
|
package/dist/tolgee-react.cjs.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var
|
|
7
|
-
var devtoolsWeb = require('@tolgee/devtools-web');
|
|
6
|
+
var web = require('@tolgee/web');
|
|
8
7
|
|
|
9
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
9
|
|
|
@@ -80,10 +79,9 @@ var TolgeeProvider = function (_a) {
|
|
|
80
79
|
}, []);
|
|
81
80
|
var optionsWithDefault = __assign(__assign({}, DEFAULT_REACT_OPTIONS), options);
|
|
82
81
|
if (optionsWithDefault.useSuspense) {
|
|
83
|
-
return (React__default["default"].createElement(TolgeeProviderContext.Provider, { value: { tolgee: tolgee, options: optionsWithDefault } },
|
|
84
|
-
React__default["default"].createElement(React.Suspense, { fallback: fallback || null }, children)));
|
|
82
|
+
return (React__default["default"].createElement(TolgeeProviderContext.Provider, { value: { tolgee: tolgee, options: optionsWithDefault } }, loading ? (fallback) : (React__default["default"].createElement(React.Suspense, { fallback: fallback || null }, children))));
|
|
85
83
|
}
|
|
86
|
-
return (React__default["default"].createElement(TolgeeProviderContext.Provider, { value: { tolgee: tolgee, options: optionsWithDefault } },
|
|
84
|
+
return (React__default["default"].createElement(TolgeeProviderContext.Provider, { value: { tolgee: tolgee, options: optionsWithDefault } }, loading ? fallback : children));
|
|
87
85
|
};
|
|
88
86
|
|
|
89
87
|
var globalContext;
|
|
@@ -103,60 +101,58 @@ function getGlobalContext() {
|
|
|
103
101
|
var useTolgeeContext = function () {
|
|
104
102
|
var context = React.useContext(TolgeeProviderContext) || getGlobalContext();
|
|
105
103
|
if (!context) {
|
|
106
|
-
throw new Error("Couldn't find tolgee instance, did you forgot to use `
|
|
104
|
+
throw new Error("Couldn't find tolgee instance, did you forgot to use `TolgeeProvider`?");
|
|
107
105
|
}
|
|
108
106
|
return context;
|
|
109
107
|
};
|
|
110
108
|
|
|
109
|
+
var useRerender = function () {
|
|
110
|
+
var _a = __read(React.useState(0), 2), instance = _a[0], setCounter = _a[1];
|
|
111
|
+
var rerender = React.useCallback(function () {
|
|
112
|
+
setCounter(function (num) { return num + 1; });
|
|
113
|
+
}, [setCounter]);
|
|
114
|
+
return { instance: instance, rerender: rerender };
|
|
115
|
+
};
|
|
116
|
+
|
|
111
117
|
var useTranslateInternal = function (ns, options) {
|
|
112
118
|
var _a = useTolgeeContext(), tolgee = _a.tolgee, defaultOptions = _a.options;
|
|
113
|
-
var namespaces =
|
|
114
|
-
var namespacesJoined =
|
|
119
|
+
var namespaces = web.getFallback(ns);
|
|
120
|
+
var namespacesJoined = web.getFallbackArray(namespaces).join(':');
|
|
115
121
|
var currentOptions = __assign(__assign({}, defaultOptions), options);
|
|
116
122
|
// dummy state to enable re-rendering
|
|
117
|
-
var _b =
|
|
118
|
-
var forceRerender = React.useCallback(function () {
|
|
119
|
-
setInstance(function (v) { return v + 1; });
|
|
120
|
-
}, [setInstance]);
|
|
123
|
+
var _b = useRerender(), rerender = _b.rerender, instance = _b.instance;
|
|
121
124
|
var subscriptionRef = React.useRef();
|
|
122
125
|
var subscriptionQueue = React.useRef([]);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
subscriptionQueue.current.push(key);
|
|
129
|
-
}
|
|
126
|
+
subscriptionQueue.current = [];
|
|
127
|
+
var subscribeToNs = function (ns) {
|
|
128
|
+
var _a;
|
|
129
|
+
subscriptionQueue.current.push(ns);
|
|
130
|
+
(_a = subscriptionRef.current) === null || _a === void 0 ? void 0 : _a.subscribeNs(ns);
|
|
130
131
|
};
|
|
131
|
-
React.useEffect(function () {
|
|
132
|
-
subscriptionRef.current = tolgee.onKeyUpdate(forceRerender);
|
|
133
|
-
subscriptionQueue.current.forEach(function (key) {
|
|
134
|
-
subscriptionRef.current.subscribeKey(key);
|
|
135
|
-
});
|
|
136
|
-
subscriptionQueue.current = [];
|
|
137
|
-
return function () {
|
|
138
|
-
subscriptionRef.current.unsubscribe();
|
|
139
|
-
};
|
|
140
|
-
}, []);
|
|
141
132
|
var isLoaded = tolgee.isLoaded(namespaces);
|
|
142
133
|
React.useEffect(function () {
|
|
134
|
+
var subscription = tolgee.onNsUpdate(rerender);
|
|
135
|
+
subscriptionRef.current = subscription;
|
|
143
136
|
if (!isLoaded) {
|
|
144
|
-
|
|
145
|
-
return function () {
|
|
146
|
-
subscriptionRef.current.unsubscribeNs(namespaces);
|
|
147
|
-
};
|
|
137
|
+
subscription.subscribeNs(namespaces);
|
|
148
138
|
}
|
|
149
|
-
|
|
139
|
+
subscriptionQueue.current.forEach(function (ns) {
|
|
140
|
+
subscription.subscribeNs(ns);
|
|
141
|
+
});
|
|
142
|
+
return function () {
|
|
143
|
+
subscription.unsubscribe();
|
|
144
|
+
};
|
|
145
|
+
}, [isLoaded, namespacesJoined]);
|
|
150
146
|
React.useEffect(function () {
|
|
151
147
|
tolgee.addActiveNs(namespaces);
|
|
152
148
|
return function () { return tolgee.removeActiveNs(namespaces); };
|
|
153
149
|
}, [namespacesJoined]);
|
|
154
150
|
var t = React.useCallback(function (props) {
|
|
155
151
|
var fallbackNs = props.ns || (namespaces === null || namespaces === void 0 ? void 0 : namespaces[0]);
|
|
156
|
-
|
|
152
|
+
subscribeToNs(fallbackNs);
|
|
157
153
|
return tolgee.t(__assign(__assign({}, props), { ns: fallbackNs }));
|
|
158
154
|
}, [tolgee, instance]);
|
|
159
|
-
if (
|
|
155
|
+
if (currentOptions.useSuspense && !isLoaded) {
|
|
160
156
|
throw tolgee.addActiveNs(namespaces, true);
|
|
161
157
|
}
|
|
162
158
|
return { t: t, isLoading: !isLoaded };
|
|
@@ -170,7 +166,7 @@ var useTranslate = function (ns, options) {
|
|
|
170
166
|
params[_i] = arguments[_i];
|
|
171
167
|
}
|
|
172
168
|
// @ts-ignore
|
|
173
|
-
var props =
|
|
169
|
+
var props = web.getTranslateProps.apply(void 0, __spreadArray([], __read(params), false));
|
|
174
170
|
return tInternal(props);
|
|
175
171
|
}, [tInternal]);
|
|
176
172
|
return { t: t, isLoading: isLoading };
|
|
@@ -191,9 +187,9 @@ var wrapTagHandlers = function (params) {
|
|
|
191
187
|
else if (React__default["default"].isValidElement(value)) {
|
|
192
188
|
var el_1 = value;
|
|
193
189
|
result[key] = function (chunk) {
|
|
194
|
-
return
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
return el_1.props.children !== undefined
|
|
191
|
+
? React__default["default"].cloneElement(el_1)
|
|
192
|
+
: React__default["default"].cloneElement(el_1, {}, addReactKeys(chunk));
|
|
197
193
|
};
|
|
198
194
|
}
|
|
199
195
|
else {
|
|
@@ -217,7 +213,7 @@ var T = function (props) {
|
|
|
217
213
|
// eslint-disable-next-line no-console
|
|
218
214
|
console.error('T component: keyName not defined');
|
|
219
215
|
}
|
|
220
|
-
var defaultValue = props.keyName ? props.children : undefined;
|
|
216
|
+
var defaultValue = props.defaultValue || (props.keyName ? props.children : undefined);
|
|
221
217
|
var t = useTranslateInternal().t;
|
|
222
218
|
var translation = addReactKeys(t({
|
|
223
219
|
key: key,
|
|
@@ -229,17 +225,9 @@ var T = function (props) {
|
|
|
229
225
|
return React__default["default"].createElement(React__default["default"].Fragment, null, translation);
|
|
230
226
|
};
|
|
231
227
|
|
|
232
|
-
var useRerender = function () {
|
|
233
|
-
var _a = __read(React.useState(0), 2); _a[0]; var setCounter = _a[1];
|
|
234
|
-
var rerender = React.useCallback(function () {
|
|
235
|
-
setCounter(function (num) { return num + 1; });
|
|
236
|
-
}, [setCounter]);
|
|
237
|
-
return rerender;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
228
|
var useTolgee = function (events) {
|
|
241
229
|
var tolgee = useTolgeeContext().tolgee;
|
|
242
|
-
var rerender = useRerender();
|
|
230
|
+
var rerender = useRerender().rerender;
|
|
243
231
|
React.useEffect(function () {
|
|
244
232
|
var listeners = events === null || events === void 0 ? void 0 : events.map(function (e) { return tolgee.on(e, rerender); });
|
|
245
233
|
return function () {
|
|
@@ -249,31 +237,16 @@ var useTolgee = function (events) {
|
|
|
249
237
|
return tolgee;
|
|
250
238
|
};
|
|
251
239
|
|
|
252
|
-
|
|
253
|
-
return function (tolgee) {
|
|
254
|
-
return tolgee
|
|
255
|
-
.use(devtoolsWeb.BrowserExtensionPlugin({ noReload: true }))
|
|
256
|
-
.use(devtoolsWeb.DevTools({ observer: props }))
|
|
257
|
-
.use(GlobalContextPlugin(props));
|
|
258
|
-
};
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
exports.ReactPlugin = ReactPlugin;
|
|
240
|
+
exports.GlobalContextPlugin = GlobalContextPlugin;
|
|
262
241
|
exports.T = T;
|
|
263
242
|
exports.TolgeeProvider = TolgeeProvider;
|
|
264
243
|
exports.TolgeeProviderContext = TolgeeProviderContext;
|
|
265
244
|
exports.useTolgee = useTolgee;
|
|
266
245
|
exports.useTranslate = useTranslate;
|
|
267
|
-
Object.keys(
|
|
268
|
-
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
269
|
-
enumerable: true,
|
|
270
|
-
get: function () { return core[k]; }
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
Object.keys(devtoolsWeb).forEach(function (k) {
|
|
246
|
+
Object.keys(web).forEach(function (k) {
|
|
274
247
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
275
248
|
enumerable: true,
|
|
276
|
-
get: function () { return
|
|
249
|
+
get: function () { return web[k]; }
|
|
277
250
|
});
|
|
278
251
|
});
|
|
279
252
|
//# sourceMappingURL=tolgee-react.cjs.js.map
|