locadex 0.1.17 → 1.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.
Files changed (186) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE.md +3 -101
  3. package/dist/cli.d.ts +0 -1
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +13 -52
  6. package/dist/cli.js.map +1 -1
  7. package/dist/index.js +1 -4
  8. package/dist/index.js.map +1 -1
  9. package/dist/logging/console.d.ts +1 -1
  10. package/dist/logging/console.d.ts.map +1 -1
  11. package/dist/logging/console.js +5 -9
  12. package/dist/logging/console.js.map +1 -1
  13. package/dist/logging/logger.js +1 -4
  14. package/dist/logging/logger.js.map +1 -1
  15. package/dist/utils/getPaths.js +1 -4
  16. package/dist/utils/getPaths.js.map +1 -1
  17. package/dist/utils/shutdown.js +1 -4
  18. package/dist/utils/shutdown.js.map +1 -1
  19. package/package.json +6 -20
  20. package/dist/commands/fixErrors.d.ts +0 -4
  21. package/dist/commands/fixErrors.d.ts.map +0 -1
  22. package/dist/commands/fixErrors.js +0 -42
  23. package/dist/commands/fixErrors.js.map +0 -1
  24. package/dist/commands/i18n.d.ts +0 -4
  25. package/dist/commands/i18n.d.ts.map +0 -1
  26. package/dist/commands/i18n.js +0 -42
  27. package/dist/commands/i18n.js.map +0 -1
  28. package/dist/commands/setup.d.ts +0 -11
  29. package/dist/commands/setup.d.ts.map +0 -1
  30. package/dist/commands/setup.js +0 -74
  31. package/dist/commands/setup.js.map +0 -1
  32. package/dist/mcp/getDocs.d.ts +0 -10
  33. package/dist/mcp/getDocs.d.ts.map +0 -1
  34. package/dist/mcp/getDocs.js +0 -55
  35. package/dist/mcp/getDocs.js.map +0 -1
  36. package/dist/mcp/getGuide.d.ts +0 -5
  37. package/dist/mcp/getGuide.d.ts.map +0 -1
  38. package/dist/mcp/getGuide.js +0 -18
  39. package/dist/mcp/getGuide.js.map +0 -1
  40. package/dist/mcp/getPort.d.ts +0 -2
  41. package/dist/mcp/getPort.d.ts.map +0 -1
  42. package/dist/mcp/getPort.js +0 -25
  43. package/dist/mcp/getPort.js.map +0 -1
  44. package/dist/mcp/tools/docs.d.ts +0 -6
  45. package/dist/mcp/tools/docs.d.ts.map +0 -1
  46. package/dist/mcp/tools/docs.js +0 -93
  47. package/dist/mcp/tools/docs.js.map +0 -1
  48. package/dist/mcp/tools/guides.d.ts +0 -11
  49. package/dist/mcp/tools/guides.d.ts.map +0 -1
  50. package/dist/mcp/tools/guides.js +0 -91
  51. package/dist/mcp/tools/guides.js.map +0 -1
  52. package/dist/mcp/tools/validate.d.ts +0 -3
  53. package/dist/mcp/tools/validate.d.ts.map +0 -1
  54. package/dist/mcp/tools/validate.js +0 -37
  55. package/dist/mcp/tools/validate.js.map +0 -1
  56. package/dist/mcp/validateEnv.d.ts +0 -9
  57. package/dist/mcp/validateEnv.d.ts.map +0 -1
  58. package/dist/mcp/validateEnv.js +0 -27
  59. package/dist/mcp/validateEnv.js.map +0 -1
  60. package/dist/mcp-sse.d.ts +0 -3
  61. package/dist/mcp-sse.d.ts.map +0 -1
  62. package/dist/mcp-sse.js +0 -79
  63. package/dist/mcp-sse.js.map +0 -1
  64. package/dist/mcp-stdio.d.ts +0 -3
  65. package/dist/mcp-stdio.d.ts.map +0 -1
  66. package/dist/mcp-stdio.js +0 -39
  67. package/dist/mcp-stdio.js.map +0 -1
  68. package/dist/prompts/system.d.ts +0 -5
  69. package/dist/prompts/system.d.ts.map +0 -1
  70. package/dist/prompts/system.js +0 -29
  71. package/dist/prompts/system.js.map +0 -1
  72. package/dist/resources/getResource.d.ts +0 -5
  73. package/dist/resources/getResource.d.ts.map +0 -1
  74. package/dist/resources/getResource.js +0 -19
  75. package/dist/resources/getResource.js.map +0 -1
  76. package/dist/tasks/concurrency.d.ts +0 -72
  77. package/dist/tasks/concurrency.d.ts.map +0 -1
  78. package/dist/tasks/concurrency.js +0 -130
  79. package/dist/tasks/concurrency.js.map +0 -1
  80. package/dist/tasks/fixErrors.d.ts +0 -2
  81. package/dist/tasks/fixErrors.d.ts.map +0 -1
  82. package/dist/tasks/fixErrors.js +0 -82
  83. package/dist/tasks/fixErrors.js.map +0 -1
  84. package/dist/tasks/i18n.d.ts +0 -7
  85. package/dist/tasks/i18n.d.ts.map +0 -1
  86. package/dist/tasks/i18n.js +0 -246
  87. package/dist/tasks/i18n.js.map +0 -1
  88. package/dist/tasks/setup.d.ts +0 -8
  89. package/dist/tasks/setup.d.ts.map +0 -1
  90. package/dist/tasks/setup.js +0 -272
  91. package/dist/tasks/setup.js.map +0 -1
  92. package/dist/telemetry.d.ts +0 -9
  93. package/dist/telemetry.d.ts.map +0 -1
  94. package/dist/telemetry.js +0 -105
  95. package/dist/telemetry.js.map +0 -1
  96. package/dist/types/cli.d.ts +0 -20
  97. package/dist/types/cli.d.ts.map +0 -1
  98. package/dist/types/cli.js +0 -5
  99. package/dist/types/cli.js.map +0 -1
  100. package/dist/utils/claudeCode.d.ts +0 -49
  101. package/dist/utils/claudeCode.d.ts.map +0 -1
  102. package/dist/utils/claudeCode.js +0 -290
  103. package/dist/utils/claudeCode.js.map +0 -1
  104. package/dist/utils/config.d.ts +0 -11
  105. package/dist/utils/config.d.ts.map +0 -1
  106. package/dist/utils/config.js +0 -84
  107. package/dist/utils/config.js.map +0 -1
  108. package/dist/utils/dag/createDag.d.ts +0 -24
  109. package/dist/utils/dag/createDag.d.ts.map +0 -1
  110. package/dist/utils/dag/createDag.js +0 -146
  111. package/dist/utils/dag/createDag.js.map +0 -1
  112. package/dist/utils/dag/extractFiles.d.ts +0 -7
  113. package/dist/utils/dag/extractFiles.d.ts.map +0 -1
  114. package/dist/utils/dag/extractFiles.js +0 -32
  115. package/dist/utils/dag/extractFiles.js.map +0 -1
  116. package/dist/utils/dag/getFiles.d.ts +0 -18
  117. package/dist/utils/dag/getFiles.d.ts.map +0 -1
  118. package/dist/utils/dag/getFiles.js +0 -116
  119. package/dist/utils/dag/getFiles.js.map +0 -1
  120. package/dist/utils/dag/matchFiles.d.ts +0 -3
  121. package/dist/utils/dag/matchFiles.d.ts.map +0 -1
  122. package/dist/utils/dag/matchFiles.js +0 -61
  123. package/dist/utils/dag/matchFiles.js.map +0 -1
  124. package/dist/utils/errors.d.ts +0 -20
  125. package/dist/utils/errors.d.ts.map +0 -1
  126. package/dist/utils/errors.js +0 -42
  127. package/dist/utils/errors.js.map +0 -1
  128. package/dist/utils/exec.d.ts +0 -6
  129. package/dist/utils/exec.d.ts.map +0 -1
  130. package/dist/utils/exec.js +0 -68
  131. package/dist/utils/exec.js.map +0 -1
  132. package/dist/utils/fs/findConfigs.d.ts +0 -11
  133. package/dist/utils/fs/findConfigs.d.ts.map +0 -1
  134. package/dist/utils/fs/findConfigs.js +0 -60
  135. package/dist/utils/fs/findConfigs.js.map +0 -1
  136. package/dist/utils/fs/formatFiles.d.ts +0 -3
  137. package/dist/utils/fs/formatFiles.d.ts.map +0 -1
  138. package/dist/utils/fs/formatFiles.js +0 -16
  139. package/dist/utils/fs/formatFiles.js.map +0 -1
  140. package/dist/utils/fs/getFiles.d.ts +0 -2
  141. package/dist/utils/fs/getFiles.d.ts.map +0 -1
  142. package/dist/utils/fs/getFiles.js +0 -8
  143. package/dist/utils/fs/getFiles.js.map +0 -1
  144. package/dist/utils/fs/git.d.ts +0 -7
  145. package/dist/utils/fs/git.d.ts.map +0 -1
  146. package/dist/utils/fs/git.js +0 -38
  147. package/dist/utils/fs/git.js.map +0 -1
  148. package/dist/utils/fs/writeFiles.d.ts +0 -2
  149. package/dist/utils/fs/writeFiles.d.ts.map +0 -1
  150. package/dist/utils/fs/writeFiles.js +0 -19
  151. package/dist/utils/fs/writeFiles.js.map +0 -1
  152. package/dist/utils/locadexManager.d.ts +0 -86
  153. package/dist/utils/locadexManager.d.ts.map +0 -1
  154. package/dist/utils/locadexManager.js +0 -305
  155. package/dist/utils/locadexManager.js.map +0 -1
  156. package/dist/utils/lockfile.d.ts +0 -16
  157. package/dist/utils/lockfile.d.ts.map +0 -1
  158. package/dist/utils/lockfile.js +0 -109
  159. package/dist/utils/lockfile.js.map +0 -1
  160. package/dist/utils/packages/installPackage.d.ts +0 -5
  161. package/dist/utils/packages/installPackage.d.ts.map +0 -1
  162. package/dist/utils/packages/installPackage.js +0 -60
  163. package/dist/utils/packages/installPackage.js.map +0 -1
  164. package/dist/utils/session.d.ts +0 -2
  165. package/dist/utils/session.d.ts.map +0 -1
  166. package/dist/utils/session.js +0 -12
  167. package/dist/utils/session.js.map +0 -1
  168. package/dist/utils/shared.d.ts +0 -5
  169. package/dist/utils/shared.d.ts.map +0 -1
  170. package/dist/utils/shared.js +0 -54
  171. package/dist/utils/shared.js.map +0 -1
  172. package/dist/utils/stats.d.ts +0 -40
  173. package/dist/utils/stats.d.ts.map +0 -1
  174. package/dist/utils/stats.js +0 -97
  175. package/dist/utils/stats.js.map +0 -1
  176. package/guides/next/advanced/conditional-rendering.md +0 -275
  177. package/guides/next/advanced/external-strings.md +0 -346
  178. package/guides/next/advanced/interpolated-strings.md +0 -82
  179. package/guides/next/advanced/mapping-expressions.md +0 -208
  180. package/guides/next/basic/branches.md +0 -327
  181. package/guides/next/basic/jsx.md +0 -270
  182. package/guides/next/basic/strings.md +0 -162
  183. package/guides/next/basic/variables.md +0 -161
  184. package/guides/next/important/functions.md +0 -39
  185. package/guides/next/migration/migrating.md +0 -85
  186. package/resources/ghaYaml.yml +0 -24
@@ -1,327 +0,0 @@
1
- # Guide: Branch Components Overview
2
-
3
- Branch components dynamically render different content based on conditional values or numeric quantities. They handle locale-aware conditional logic and pluralization rules.
4
-
5
- **Import:** Branch components are exported from `gt-next`.
6
-
7
- ```tsx
8
- import { Branch, Plural } from 'gt-next';
9
- ```
10
-
11
- **Key Behavior:**
12
-
13
- - `<Branch>`: Renders content based on conditional branch values.
14
- - `<Plural>`: Handles pluralization with locale-specific rules. Uses Unicode CLDR pluralization rules.
15
-
16
- **Important:** When used within `<T>` components, branch content is translated. When used standalone, content renders without translation.
17
-
18
- **Integration with Variables:** Branch components are often combined with variable components like `<Num>` for locale-aware dynamic content.
19
-
20
- ---
21
-
22
- ## Usage Patterns
23
-
24
- ### Basic Syntax
25
-
26
- Branch components use condition-based prop patterns:
27
-
28
- ```tsx
29
- <Branch branch={condition} key1={content1} key2={content2}>
30
- Fallback content
31
- </Branch>
32
-
33
- <Plural n={number} one={singular} other={plural}>
34
- Fallback content
35
- </Plural>
36
- ```
37
-
38
- ### Integration with `<T>` Components
39
-
40
- Branch components require translation context for localized content. Use within `<T>` components to automatically translate content.
41
-
42
- ```tsx
43
- import { T, Branch } from 'gt-next';
44
-
45
- <T>
46
- <Branch
47
- branch={status}
48
- active={<p>User is active</p>} // This content is translated by the <T> component
49
- inactive={<p>User is inactive</p>} // This content is translated by the <T> component
50
- >
51
- Status unknown {/* This content is translated by the <T> component */}
52
- </Branch>
53
- </T>;
54
- ```
55
-
56
- The `<T>` component provides translation context and localizes branch content.
57
-
58
- ### Pluralization Behavior
59
-
60
- **Automatic Rule Selection:** `<Plural>` uses Unicode CLDR rules to determine correct plural form based on `n` value and current locale.
61
-
62
- **Customization:** Override default plural forms with specific CLDR categories:
63
-
64
- ```tsx
65
- import { Plural } from 'gt-next';
66
-
67
- // All content inside the <Plural> component is translated by the <T> component
68
- <T>
69
- He has
70
- <Plural
71
- n={count}
72
- zero={<>No items</>}
73
- one={<>One item</>}
74
- two={<>Two items</>}
75
- few={<>Few items</>}
76
- many={<>Many items</>}
77
- other={<>Other items</>}
78
- dual={<>Dual items</>}
79
- // OR simplified
80
- singular={<>One item</>}
81
- plural={<>Multiple items</>}
82
- />
83
- .
84
- </T>;
85
- ```
86
-
87
- **Available Forms:** zero, one, two, few, many, other, dual (locale-dependent), plus simplified singular/plural.
88
-
89
- ---
90
-
91
- ## Implementation Examples
92
-
93
- ### `<Branch>` - Conditional Logic Replacement
94
-
95
- **Replacing Ternary Operators:** Convert inline conditional logic to declarative branch syntax.
96
-
97
- ```tsx
98
- // Original:
99
- {
100
- isActive ? <p>Active</p> : <p>Inactive</p>;
101
- }
102
-
103
- // After:
104
- <Branch branch={isActive} true={<p>Active</p>} false={<p>Inactive</p>}>
105
- Status unknown
106
- </Branch>;
107
- ```
108
-
109
- **Important**: the `branch` prop only accepts string values.
110
- For example, if isActive is a boolean, convert it to a string first.
111
-
112
- **Replacing Conditional Rendering:** Convert `?` operator patterns to branch syntax.
113
- This should only be done if the content is being used in a `<T>` component.
114
-
115
- **Invalid Syntax**:
116
-
117
- ```tsx
118
- <T>{isActive ? <p>Active</p> : <p>Inactive</p>}</T>
119
- ```
120
-
121
- **Valid Syntax**:
122
-
123
- ```tsx
124
- <T>
125
- <Branch branch={isActive} true={<p>Active</p>} false={<p>Inactive</p>}>
126
- <></>
127
- </Branch>
128
- </T>
129
- ```
130
-
131
- **Alternative Valid Syntax**:
132
-
133
- ```tsx
134
- {
135
- isActive ? (
136
- <T>
137
- <p>Active</p>
138
- </T>
139
- ) : (
140
- <T>
141
- <p>Inactive</p>
142
- </T>
143
- );
144
- }
145
- ```
146
-
147
- In the previous example, the `<T>` component is not wrapping the conditional, so the branch component is not needed.
148
-
149
- ### `<Plural>` - Number-Based Rendering
150
-
151
- **Basic Pluralization:** Replace manual plural logic with locale-aware components.
152
-
153
- ```tsx
154
- // Original:
155
- {
156
- count === 1 ? <p>1 item</p> : <p>{count} items</p>;
157
- }
158
-
159
- // After:
160
- <Plural n={count} one={<p>1 item</p>} other={<p>{count} items</p>} />;
161
- ```
162
-
163
- **Note:** `n` only accepts numbers.
164
-
165
- **With Variable Integration:** Combine with `<Num>` for formatted numbers.
166
-
167
- ```tsx
168
- <T>
169
- <Plural
170
- n={count}
171
- one={
172
- <>
173
- You have <Num>{count}</Num> unread message.
174
- </>
175
- }
176
- other={
177
- <>
178
- You have <Num>{count}</Num> unread messages.
179
- </>
180
- }
181
- />
182
- </T>
183
- ```
184
-
185
- **Translation Context:** Use within `<T>` for translated content, standalone for raw rendering.
186
-
187
- ---
188
-
189
- ## Complete Implementation Examples
190
-
191
- ### `<Branch>` - Multi-State Logic
192
-
193
- **Status Management:** Handle multiple conditional states with fallback.
194
-
195
- ```tsx
196
- import { T, Branch, Var } from 'gt-next';
197
- const status: string = 'active';
198
- <T>
199
- <Branch
200
- branch={status}
201
- active={
202
- <p>
203
- User <Var>{name}</Var> is active.
204
- </p>
205
- }
206
- inactive={
207
- <p>
208
- User <Var>{name}</Var> is inactive.
209
- </p>
210
- }
211
- >
212
- Status unknown.
213
- </Branch>
214
- </T>;
215
- ```
216
-
217
- **Behavior:**
218
-
219
- - `status === "active"` → renders active content
220
- - `status === "inactive"` → renders inactive content
221
- - Other values → renders fallback content
222
- - Content within `<T>` is automatically translated
223
-
224
- **Subscription Tiers:** Standalone usage without translation.
225
-
226
- ```tsx
227
- <T>
228
- <Branch
229
- branch={plan}
230
- free={<p>Free plan - upgrade to unlock features</p>}
231
- premium={<p>Premium plan - full access</p>}
232
- enterprise={<p>Enterprise plan - contact support</p>}
233
- >
234
- No subscription detected
235
- </Branch>
236
- </T>
237
- ```
238
-
239
- ### `<Plural>` - Quantity-Based Content
240
-
241
- **Message Count:** Number-dependent content with locale formatting.
242
-
243
- ```tsx
244
- import { T, Plural, Num } from 'gt-next';
245
-
246
- <T>
247
- <Plural
248
- n={unreadCount}
249
- one={
250
- <>
251
- You have <Num>{unreadCount}</Num> unread message.
252
- </>
253
- }
254
- other={
255
- <>
256
- You have <Num>{unreadCount}</Num> unread messages.
257
- </>
258
- }
259
- />
260
- </T>;
261
- ```
262
-
263
- **Behavior:**
264
-
265
- - `n === 1` (locale-specific) → renders singular form
266
- - Other values → renders plural form
267
- - `<Num>` provides locale-aware number formatting
268
-
269
- ---
270
-
271
- ## Common Implementation Issues
272
-
273
- ### Missing Branch Values
274
-
275
- **Critical:** Unmatched branch values fall back to children content. Ensure branch prop values match defined keys.
276
-
277
- ```tsx
278
- <Branch
279
- branch={status} // If status is "pending" but no pending={} prop exists
280
- active={<p>Active</p>}
281
- inactive={<p>Inactive</p>}
282
- >
283
- Status unknown. // ← This renders for unmatched values
284
- </Branch>
285
- ```
286
-
287
- **Rule:** Always provide fallback children for robust error handling.
288
-
289
- ### Missing Plural Forms
290
-
291
- **Critical:** Provide required plural forms for your default locale to ensure fallback content availability.
292
-
293
- **Minimum English Requirements:**
294
-
295
- ```tsx
296
- <Plural
297
- n={count}
298
- one={<>One message</>} // Required for English
299
- other={<>Multiple messages</>} // Required fallback
300
- />
301
-
302
- // OR simplified form
303
- <Plural
304
- n={count}
305
- singular={<>One message</>}
306
- plural={<>Multiple messages</>}
307
- />
308
- ```
309
-
310
- **Optimization:** Use `one`/`other` for CLDR compliance or `singular`/`plural` for simplicity.
311
-
312
- ---
313
-
314
- ## Key Principles
315
-
316
- - **Conditional Logic:** Branch components replace ternary operators and conditional rendering with declarative syntax
317
- - **Locale Awareness:** `<Plural>` automatically handles pluralization rules across different languages
318
- - **Fallback Handling:** Always provide children content for unmatched conditions
319
- - **Translation Integration:** Use within `<T>` for translated content, standalone for raw rendering
320
-
321
- ## API References
322
-
323
- - [`<Branch>`](/docs/next/api/components/branch) - Conditional rendering options
324
- - [`<Plural>`](/docs/next/api/components/plural) - Pluralization configuration
325
- - [Variable Components](/docs/next/guides/variables) - Integration patterns
326
-
327
- For more information on Variable Components, see the `mcp__locadex__next_basic_variables` guide.
@@ -1,270 +0,0 @@
1
- # Guide: JSX Translation with `<T>` Component
2
-
3
- Use the `<T>` component to internationalize HTML and JSX content.
4
-
5
- **Key Notes**:
6
-
7
- - `<T>` components can contain any valid JSX/HTML content, including other components, strings, and other JSX/HTML content.
8
- - `<T>` components can contain dynamic content, but it must be wrapped in Variable Components or Branching Components.
9
-
10
- **Import:** The `<T>` component is exported from `gt-next`.
11
-
12
- ```tsx
13
- import { T } from 'gt-next';
14
- ```
15
-
16
- Before:
17
-
18
- ```jsx
19
- function Greeting() {
20
- return <p>Hello, world!</p>;
21
- }
22
- ```
23
-
24
- After:
25
-
26
- ```jsx
27
- import { T } from 'gt-next';
28
-
29
- function Greeting() {
30
- return (
31
- <T>
32
- <p>Hello, world!</p>
33
- </T>
34
- );
35
- }
36
- ```
37
-
38
- ## Context Prop
39
-
40
- Add `context` prop when content meaning is ambiguous:
41
-
42
- ```jsx
43
- <T context='Crop, as in cropping an image'>Crop</T>
44
- ```
45
-
46
- RULES:
47
-
48
- - Provide context for words with multiple meanings (e.g., "crop" = cropping an image vs the food crop).
49
- - Provide context when the additional context can provide more information to the translator about the surrounding content, that is not obvious from the content itself.
50
-
51
- ## Usage Rules
52
-
53
- **USE `<T>` for:**
54
-
55
- - Static HTML or JSX content
56
- - Dynamic content wrapped in Variable Components or Branching Components
57
-
58
- **DO NOT USE `<T>` for:** Raw dynamic content (unwrapped variables, expressions, conditionals)
59
-
60
- ### Notes on Variable Components
61
-
62
- Variable components are safe for `<T>` because content is wrapped and sanitized. Variable component content is never translated directly by `<T>`.
63
-
64
- ### Invalid Usage Examples (Raw Dynamic Content)
65
-
66
- ```jsx
67
- <T>
68
- <p>Your username is {username}</p>
69
- </T>
70
- ```
71
-
72
- ```jsx
73
- <T>
74
- <p>Current date: {new Date().toLocaleDateString()}</p>
75
- </T>
76
- ```
77
-
78
- ```jsx
79
- <T>
80
- <p>Logical Expressions: {username === 'admin' ? 'Yes' : 'No'}</p>
81
- </T>
82
- ```
83
-
84
- ```jsx
85
- <T>
86
- <p>Conditional Rendering: {isAdmin ? 'Yes' : 'No'}</p>
87
- </T>
88
- ```
89
-
90
- **Solution: Wrap dynamic content in variable components or branching components, then use with `<T>`.**
91
-
92
- ## Valid Usage Examples
93
-
94
- ### HTML and JSX Content
95
-
96
- ```jsx
97
- // Before
98
- <p>Hello, world!</p>
99
- <Button>Click me!</Button>
100
-
101
- // After
102
- <T>
103
- <p>Hello, world!</p>
104
- </T>
105
- <T>
106
- <Button>Click me!</Button>
107
- </T>
108
-
109
- // Or, you can wrap both components with `<T>`
110
- <T>
111
- <p>Hello, world!</p>
112
- <Button>Click me!</Button>
113
- </T>
114
- ```
115
-
116
- ### Complex JSX Content
117
-
118
- ```jsx
119
- // Before
120
- <Tooltip>
121
- <TooltipTrigger>
122
- <div className='flex items-center gap-2 rounded-full bg-destructive px-3 py-1.5 text-sm text-destructive-foreground'>
123
- <AlertCircle className='h-4 w-4' />
124
- <span>Free Usage</span>
125
- </div>
126
- </TooltipTrigger>
127
- <TooltipContent>
128
- <p>
129
- You are nearing your free monthly limit. Please upgrade your plan to avoid
130
- any disruptions to your service.
131
- </p>
132
- </TooltipContent>
133
- </Tooltip>
134
-
135
- // After
136
- <T>
137
- <Tooltip>
138
- <TooltipTrigger>
139
- <div className='flex items-center gap-2 rounded-full bg-destructive px-3 py-1.5 text-sm text-destructive-foreground'>
140
- <AlertCircle className='h-4 w-4' />
141
- <span>Free Usage</span>
142
- </div>
143
- </TooltipTrigger>
144
- <TooltipContent>
145
- <p>
146
- You are nearing your free monthly limit. Please upgrade your plan to
147
- avoid any disruptions to your service.
148
- </p>
149
- </TooltipContent>
150
- </Tooltip>
151
- </T>
152
- ```
153
-
154
- **NOTE: `<T>` handles any nested content within the same component.**
155
-
156
- ## Common Pitfalls and Solutions
157
-
158
- ### Direct Descendants Only
159
-
160
- Rule: `<T>` only translates content directly between its tags. Content inside nested components is not translated.
161
-
162
- ```jsx
163
- // INCORRECT - UntranslatedContent not translated
164
- function UntranslatedContent() {
165
- return <p>This content is not translated</p>;
166
- }
167
-
168
- export default function DisplayGreetings() {
169
- return (
170
- <T>
171
- <h1>Hello, this text will be translated</h1>
172
- <UntranslatedContent />
173
- </T>
174
- );
175
- }
176
- ```
177
-
178
- Only content literally between `<T>` tags is translated. The `<h1>` is translated, but `<UntranslatedContent>` is not.
179
-
180
- **Solution:**
181
-
182
- ```jsx
183
- // CORRECT - Each component wraps its own content
184
- function TranslatedContent() {
185
- return (
186
- <T>
187
- <p>
188
- This content <b>IS</b> translated
189
- </p>
190
- </T>
191
- );
192
- }
193
-
194
- export default function DisplayGreetings() {
195
- return (
196
- <>
197
- <T>
198
- <h1>Hello, this text will be translated</h1>
199
- </T>
200
- <TranslatedContent />
201
- </>
202
- );
203
- }
204
- ```
205
-
206
- ### Nested `<T>` Components
207
-
208
- Rule: Never nest `<T>` components. This causes unexpected behavior and performance issues.
209
-
210
- ```jsx
211
- // INCORRECT - Nested T components
212
- function SomeComponent() {
213
- return <T>Hello, friend!</T>;
214
- }
215
-
216
- export default function NestedTranslation() {
217
- return (
218
- <T>
219
- <T>Hello, world!</T> {/* Don't nest */}
220
- <SomeComponent /> {/* This also nests */}
221
- </T>
222
- );
223
- }
224
- ```
225
-
226
- Solution: Remove the outer `<T>` component.
227
-
228
- ### Raw Dynamic Content Error
229
-
230
- Raw dynamic content in `<T>` will cause an error.
231
-
232
- ```jsx
233
- // WILL ERROR - Raw dynamic content
234
- const username = 'John Doe';
235
- <T>
236
- <p>Your username is {username}</p>
237
- </T>;
238
- ```
239
-
240
- **Solutions:**
241
-
242
- 1. Wrap dynamic content in Variable Components or Branching Components, then use with `<T>`
243
- 2. Use `<Tx>` component for on-demand translation (**use only when necessary, and on server components**)
244
-
245
- ### Implementing Variable contents incorrectly
246
-
247
- The following syntax is wrong and was likely confused with the `useGT()` hook.
248
-
249
- ```jsx
250
- // WILL ERROR - Improper syntax
251
- const username = 'John Doe';
252
- <T variables={{ username }}>Hello, {username}</T>;
253
- ```
254
-
255
- The correct implementation is as follows:
256
-
257
- ```jsx
258
- const username = 'John Doe';
259
- <T>
260
- Hello, <Var>{username}</Var>
261
- </T>;
262
- ```
263
-
264
- ## Summary
265
-
266
- - Use `<T>` to internationalize static JSX content
267
- - Use `<T>` with dynamic content only when wrapped in Variable/Branching Components
268
- - Never use `<T>` for raw dynamic content (unwrapped variables, expressions, conditionals)
269
- - Never nest `<T>` components
270
- - Only content directly between `<T>` tags is translated