gt-react 9.2.2 → 9.2.4-alpha.1
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 +61 -28
- package/dist/client.cjs.min.cjs +3 -3
- package/dist/client.d.ts +49 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.esm.min.mjs +3 -3
- package/dist/{messages/createMessages.d.ts → errors/createErrors.d.ts} +4 -2
- package/dist/errors/createErrors.d.ts.map +1 -0
- package/dist/hooks/internal/useCreateInternalUseDictFunction.d.ts +4 -4
- package/dist/hooks/internal/useCreateInternalUseDictFunction.d.ts.map +1 -1
- package/dist/hooks/useLocaleSelector.d.ts +11 -0
- package/dist/hooks/useLocaleSelector.d.ts.map +1 -0
- package/dist/index.cjs.min.cjs +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.min.mjs +3 -3
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/provider/ClientProvider.d.ts +1 -1
- package/dist/provider/ClientProvider.d.ts.map +1 -1
- package/dist/provider/GTProvider.d.ts +4 -3
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/types/providers.d.ts +3 -1
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/types.d.ts +9 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/ui/LocaleSelector.d.ts +2 -4
- package/dist/ui/LocaleSelector.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/messages/createMessages.d.ts.map +0 -1
package/README.md
CHANGED
@@ -16,12 +16,7 @@ Install `gt-react` via npm:
|
|
16
16
|
|
17
17
|
```bash
|
18
18
|
npm install gt-react
|
19
|
-
|
20
|
-
|
21
|
-
Or with yarn:
|
22
|
-
|
23
|
-
```bash
|
24
|
-
yarn add gt-react
|
19
|
+
npm install gt-react-cli --save-dev
|
25
20
|
```
|
26
21
|
|
27
22
|
## Getting Started
|
@@ -37,48 +32,86 @@ GT_PROJECT_ID="your-project-id"
|
|
37
32
|
|
38
33
|
- Get your `API Key` and `Project ID` from the [General Translation Dashboard](https://generaltranslation.com).
|
39
34
|
|
40
|
-
###
|
35
|
+
### 2. Select languages
|
41
36
|
|
42
|
-
|
37
|
+
`<GTProvider>` is used to configure the behavior of `gt-react`.
|
38
|
+
It should be placed as high up in your app as possible, ideally at the root.
|
39
|
+
|
40
|
+
Just pass a list of [locale codes](https://generaltranslation.com/docs/reference/supported-locales) to add them to your app.
|
43
41
|
|
44
42
|
```jsx
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
>
|
51
|
-
<
|
43
|
+
import { GTProvider } from "gt-react";
|
44
|
+
import MyApp from "./MyApp";
|
45
|
+
|
46
|
+
export default function App() {
|
47
|
+
return (
|
48
|
+
<GTProvider locales={['fr', 'zh']}> // French and Chinese support
|
49
|
+
<MyApp />
|
52
50
|
</GTProvider>
|
53
|
-
|
54
|
-
|
51
|
+
);
|
52
|
+
}
|
55
53
|
```
|
56
54
|
|
57
|
-
### Step 3: Translate Content with `<T>`
|
58
55
|
|
59
|
-
|
56
|
+
### 3. Add the `<T>` component
|
57
|
+
|
58
|
+
Wrap any nested JSX content in the `<T>` component to make it translatable.
|
59
|
+
For more information, check out the [guide on using `<T>` components](https://generaltranslation.com/docs/react/reference/t-reference).
|
60
60
|
|
61
61
|
```jsx
|
62
|
-
import { T } from
|
62
|
+
import { T } from "gt-react";
|
63
63
|
|
64
|
-
export default function
|
64
|
+
export default function Example() {
|
65
65
|
return (
|
66
|
-
<T
|
67
|
-
<p>
|
66
|
+
<T>
|
67
|
+
<p>
|
68
|
+
This gets translated.
|
69
|
+
</p>
|
68
70
|
</T>
|
69
71
|
);
|
70
72
|
}
|
71
73
|
```
|
72
74
|
|
73
|
-
|
75
|
+
Use the `<Var>` component to designate JSX content that should not be translated.
|
74
76
|
|
75
|
-
```
|
76
|
-
|
77
|
-
|
77
|
+
```jsx
|
78
|
+
import { T, Var } from "gt-react";
|
79
|
+
|
80
|
+
export default function Example() {
|
81
|
+
return (
|
82
|
+
<T>
|
83
|
+
<p>
|
84
|
+
This gets translated. <Var>This does not.</Var>
|
85
|
+
</p>
|
86
|
+
</T>
|
87
|
+
);
|
88
|
+
}
|
89
|
+
```
|
90
|
+
|
91
|
+
**Tip:**
|
92
|
+
To save time, run the setup command.
|
93
|
+
It will scan your codebase for translatable JSX and insert the `<T>` tags for you.
|
94
|
+
|
95
|
+
```bash title="shell" copy
|
96
|
+
npx gt-react-cli setup
|
78
97
|
```
|
79
98
|
|
80
|
-
|
99
|
+
**Strings:**
|
100
|
+
For strings, you can use `useGT()` for translation.
|
101
|
+
For more information, check out [this guide](/docs/react/tutorials/translating-strings).
|
81
102
|
|
103
|
+
```jsx
|
104
|
+
import { useGT } from "gt-react";
|
105
|
+
|
106
|
+
export default function Example() {
|
107
|
+
const t = useGT();
|
108
|
+
return (
|
109
|
+
<p>
|
110
|
+
{t("This gets translated.")}
|
111
|
+
</p>
|
112
|
+
);
|
113
|
+
}
|
114
|
+
```
|
82
115
|
## Documentation
|
83
116
|
|
84
117
|
Full documentation, including guides, examples, and API references, can be found at [General Translation Docs](generaltranslation.com/docs).
|