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 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
- ### Step 2: Add the `<GTProvider>`
35
+ ### 2. Select languages
41
36
 
42
- Add the `<GTProvider>` component at the root of your application.
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
- createRoot(document.getElementById("root")!).render(
46
- <StrictMode>
47
- <GTProvider
48
- projectId={GT_PROJECT_ID}
49
- devApiKey={GT_API_KEY}
50
- >
51
- <App />
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
- </StrictMode>
54
- );
51
+ );
52
+ }
55
53
  ```
56
54
 
57
- ### Step 3: Translate Content with `<T>`
58
55
 
59
- The `<T>` component is the simplest way to translate inline JSX content.
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 'gt-react';
62
+ import { T } from "gt-react";
63
63
 
64
- export default function HomePage() {
64
+ export default function Example() {
65
65
  return (
66
- <T id='greeting'>
67
- <p>Hello, world!</p>
66
+ <T>
67
+ <p>
68
+ This gets translated.
69
+ </p>
68
70
  </T>
69
71
  );
70
72
  }
71
73
  ```
72
74
 
73
- If you have an existing project you would like to internationalize, you can use the `gt-react-cli` tool for initial setup.
75
+ Use the `<Var>` component to designate JSX content that should not be translated.
74
76
 
75
- ```bash
76
- npm install gt-react-cli
77
- npx gt-react-cli scan
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
- This will scan your project for all the text content that needs to be translated, and automatically wrap them in `<T>` and `<Var>` components.
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).