locadex 0.1.17 → 1.0.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.
Files changed (186) hide show
  1. package/CHANGELOG.md +13 -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 +6 -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,346 +0,0 @@
1
- # Guide: Internationalizing Strings Outside of Component Scope
2
-
3
- ## When to use this guide
4
-
5
- Follow this guide when you encounter variable declarations (`let`, `const`, or `var`) outside of a component scope that contain strings needing internationalization. Additionally, this guide is also applicable to functions that contain strings outside of a component scope.
6
-
7
- ## Rules
8
-
9
- 1. **Scope**: Apply this pattern ONLY for internationalizing variables, constants, or functions that contain strings outside of a component scope.
10
- 2. **Minimal footprint**: Keep internationalized content in the same file as the original declaration
11
-
12
- Rule of thumb for implementation:
13
-
14
- - Always turn variables and constants into functions that take `t()` as a parameter
15
- - When modifying functions, always pass `t()` as an additional parameter to the function
16
-
17
- ## Implementation Patterns: Variables
18
-
19
- ### Pattern 1: Single Variable Outside Function
20
-
21
- **Scenario**: Variable declared outside component scope within SAME FILE
22
-
23
- ```jsx
24
- const OUTSIDE_CONST = 'Hello there!';
25
- export function Example() {
26
- const [state, setState] = useState();
27
- return <>{OUTSIDE_CONST}</>;
28
- }
29
- ```
30
-
31
- **Solution**: Move variable inside component and use `useGT()` hook
32
-
33
- 1. Move the variable inside the component
34
- 2. Add the `useGT()` hook.
35
- 3. Call the `t()` translation callback function returned by the hook to translate the variable.
36
-
37
- This pattern is the only exception to the rule of thumb.
38
-
39
- ```jsx
40
- import { useGT } from 'gt-next';
41
- export function Example() {
42
- const [state, setState] = useState();
43
- const t = useGT();
44
- const outside_const = t('Hello there!');
45
- return <>{outside_const}</>;
46
- }
47
- ```
48
-
49
- ### Pattern 2: Variable Reused Across Multiple Components
50
-
51
- **Scenario**: Variable shared between multiple components (in the same file or across files)
52
-
53
- ```jsx
54
- export const OUTSIDE_CONST = 'Hello there!';
55
- export function Example1() {
56
- const [state, setState] = useState();
57
- return <>{OUTSIDE_CONST}</>;
58
- }
59
- export function Example2() {
60
- const [state, setState] = useState();
61
- return <>{OUTSIDE_CONST}</>;
62
- }
63
- ```
64
-
65
- **Solution**: Convert data structure to custom function with internationalization
66
-
67
- 1. Turn the constant into a function that takes `t()` as a parameter, adding the word 'get' infront (i.e., `OUTSIDE_CONST` becomes `getOutsideConst()`)
68
- 2. For each use, import `useGT()` from `gt-next` and import the new function you defined
69
- 3. Call the `useGT()` hook
70
- 4. Pass the `t` translation callback function to the newly defined function
71
-
72
- ```jsx
73
- import { useGT } from 'gt-next';
74
- const getOutsideConst = (t: (content: string) => string) => {
75
- return t('Hello there!');
76
- };
77
- export function Example1() {
78
- const [state, setState] = useState();
79
- const t = useGT();
80
- const outsideConst = getOutsideConst(t);
81
- return <>{outsideConst}</>;
82
- }
83
- export function Example2() {
84
- const [state, setState] = useState();
85
- const t = useGT();
86
- const outsideConst = getOutsideConst(t);
87
- return <>{outsideConst}</>;
88
- }
89
- ```
90
-
91
- ### Pattern 3: Complex Data Structures
92
-
93
- **Scenario**: Centralized data structure with hardcoded strings
94
-
95
- ```jsx title="navMap.ts"
96
- export const navMap = [
97
- {
98
- name: 'dashboard',
99
- url: '/dashboard',
100
- type: 'page',
101
- },
102
- {
103
- name: 'landing',
104
- url: '/landing',
105
- type: 'page',
106
- },
107
- {
108
- name: 'links',
109
- type: 'divider',
110
- children: [
111
- {
112
- name: 'blog',
113
- url: '/blog',
114
- },
115
- {
116
- name: 'help',
117
- url: '/help',
118
- },
119
- ],
120
- },
121
- ];
122
- ```
123
-
124
- Usage: Imported and used in different components.
125
-
126
- ```jsx title="Example1.tsx"
127
- import navMap from './navMap';
128
- import NavItem from './NavItem';
129
- export default function Example1() {
130
- return (
131
- <>
132
- {navMap.map((navItem) => (
133
- <NavItem item={navItem} />
134
- ))}
135
- </>
136
- );
137
- }
138
- ```
139
-
140
- ```jsx title="Example2.tsx"
141
- import navMap from './navMap';
142
- import NavItem from './NavItem';
143
- export default function Example2() {
144
- return (
145
- <>
146
- {navMap
147
- .filter((navItem) => navItem.type === 'page')
148
- .map((navItem) => (
149
- <NavItem item={navItem} />
150
- ))}
151
- </>
152
- );
153
- }
154
- ```
155
-
156
- **Solution**: The solution is exactly the same as in Pattern 2.
157
-
158
- 1. Turn the constant into a function that takes `t()` as a parameter, adding the word 'get' infront (i.e., `navMap` becomes `getNavMap()`)
159
- 2. For each use in a component, import `useGT()` from `gt-next` and import the new function you defined
160
- 3. Call the `useGT()` hook
161
- 4. Pass the `t` translation callback function to the newly defined function
162
-
163
- ```jsx title="navMap.ts"
164
- export const getNavMap = (t: (content: string) => string) => {
165
- return [
166
- {
167
- name: t('dashboard'),
168
- url: '/dashboard',
169
- type: 'page',
170
- },
171
- {
172
- name: t('landing'),
173
- url: '/landing',
174
- type: 'page',
175
- },
176
- {
177
- name: t('links'),
178
- type: 'divider',
179
- children: [
180
- {
181
- name: t('blog'),
182
- url: '/blog',
183
- },
184
- {
185
- name: t('help'),
186
- url: '/help',
187
- },
188
- ],
189
- },
190
- ];
191
- };
192
- ```
193
-
194
- **Updated Components**: Components now call the function to get internationalized data
195
-
196
- ```jsx title="Example1.tsx"
197
- import { useGT } from 'gt-next';
198
- import getNavMap from './navMap';
199
- import NavItem from './NavItem';
200
- export default function Example1() {
201
- const t = useGT();
202
- const navMap = getNavMap(t);
203
- return (
204
- <>
205
- {navMap.map((navItem) => (
206
- <NavItem item={navItem} />
207
- ))}
208
- </>
209
- );
210
- }
211
- ```
212
-
213
- ```jsx title="Example2.tsx"
214
- import { useGT } from 'gt-next';
215
- import getNavMap from './navMap';
216
- import NavItem from './NavItem';
217
- export default function Example2() {
218
- const t = useGT();
219
- const navMap = getNavMap(t);
220
- return (
221
- <>
222
- {navMap
223
- .filter(() => navItem.type === 'page')
224
- .map((navItem) => (
225
- <NavItem item={navItem} />
226
- ))}
227
- </>
228
- );
229
- }
230
- ```
231
-
232
- **Common Pitfalls**
233
-
234
- - Forgetting to call the `useGT()` hook
235
- - Not passing the `t` function to the newly defined getter function
236
- - Forgetting to add the word `get` at the beginning of the function
237
- - Treating the function like an object instead of a function (syntax error)
238
-
239
- ## Implementation Patterns: Functions
240
-
241
- Similar to internationalizing variables, you can also internationalize functions. Simply pass the `t()` function as an additional parameter to the function.
242
-
243
- **Scenario**: Function declared outside component scope
244
-
245
- ```jsx
246
- function getErrorMessage(errorType) {
247
- switch (errorType) {
248
- case 'network':
249
- return 'Network connection failed';
250
- case 'auth':
251
- return 'Authentication failed';
252
- default:
253
- return 'Unknown error occurred';
254
- }
255
- }
256
- export function Example() {
257
- const [error, setError] = useState('network');
258
- const message = getErrorMessage(error);
259
- return <div>{message}</div>;
260
- }
261
- ```
262
-
263
- **Solution**: Pass `t()` function as parameter to the function
264
-
265
- 1. Import `useGT()` from `'gt-next'`
266
- 2. Modify the function to accept `t()` as a parameter
267
- 3. Use `t()` for string translations within the function
268
- 4. Pass `t()` when calling the function in the component
269
-
270
- ```jsx
271
- import { useGT } from 'gt-next';
272
- function getErrorMessage(errorType, t: (content: string) => string) {
273
- switch (errorType) {
274
- case 'network':
275
- return t('Network connection failed');
276
- case 'auth':
277
- return t('Authentication failed');
278
- default:
279
- return t('Unknown error occurred');
280
- }
281
- }
282
- export function Example() {
283
- const [error, setError] = useState('network');
284
- const t = useGT();
285
- const message = getErrorMessage(error, t);
286
- return <div>{message}</div>;
287
- }
288
- ```
289
-
290
- If the function is exported and used in multiple components, the same solution applies.
291
-
292
- **Common Pitfalls for Functions**
293
-
294
- - Forgetting to add the `t` parameter to the function signature
295
- - Not passing `t()` when calling the function
296
- - Modifying functional strings that shouldn't be translated (e.g., IDs)
297
-
298
- ## SPECIAL CASES
299
-
300
- **IMPORTANT:** These are special cases that are not covered by the general rules.
301
-
302
- ### async components
303
-
304
- When internationalizing a component or function that is marked as `async`, you should use the `getGT()` hook to get the translation callback function. `getGT()` must be awaited. Other than this, the usage of `getGT()` and `useGT()` is the same.
305
-
306
- Pass the `t()` callback function returned by the `getGT()` hook to the component or function as a parameter.
307
-
308
- ```jsx
309
- import { getGT } from 'gt-next/server';
310
- const getOutsideConst = (t: (content: string) => string) => {
311
- return t('Hello there!');
312
- };
313
- export async function Example1() {
314
- const t = await getGT();
315
- const outsideConst = getOutsideConst(t);
316
- return <>{outsideConst}</>;
317
- }
318
- ```
319
-
320
- ### Additional props and typing
321
-
322
- When necessary, you pass additional props such as a context prop to the `t()` callback function.
323
-
324
- If the app you are internationalizing is TypeScript, you may need to edit the type of the `t()` callback function.
325
-
326
- ```jsx
327
- import { useGT } from 'gt-next';
328
- import { InlineTranslationOptions } from 'gt-next/types';
329
- const getOutsideConst = (t: (content: string, options?: InlineTranslationOptions) => string) => {
330
- return t('Crop', { context: 'Crop, as in cropping an image' });
331
- };
332
- export function Example1() {
333
- const [state, setState] = useState();
334
- const t = useGT();
335
- const outsideConst = getOutsideConst(t);
336
- return <>{outsideConst}</>;
337
- }
338
- ```
339
-
340
- ## IMPORTANT REMINDERS
341
-
342
- Pay attention to these rules:
343
-
344
- - Only modify non-functional strings. Functional strings are strings which serve logical purposes other than purely being used as UI, such as ids. Do not modify these functional strings.
345
- - If a variable is used in UI, but is also functional, keep the original variable and create a separate function that returns the translated string.
346
- - See the `mcp__locadex__next_advanced_mapping-expressions` guide for more information on how to internationalize dynamic content.
@@ -1,82 +0,0 @@
1
- # Guide: Internationalizing dynamic strings
2
-
3
- **Objective**: Transform template literal strings with dynamic variables into translatable strings using `<T>` and `useGT()`.
4
-
5
- ## The `<T>` component (preferred for JSX/HTML):
6
-
7
- Original:
8
-
9
- ```jsx
10
- const MyComponent = ({ name, count }) => {
11
- return <div>{`Welcome ${name}, you have ${count} items`}</div>;
12
- };
13
- ```
14
-
15
- After:
16
-
17
- ```jsx
18
- import { T, Var, Num } from 'gt-next';
19
- const MyComponent = ({ name, count }) => {
20
- return (
21
- <T>
22
- <div>
23
- Welcome <Var>{name}</Var>, you have <Num>{count}</Num> items
24
- </div>
25
- </T>
26
- );
27
- };
28
- ```
29
-
30
- **Notes**:
31
-
32
- - Replace `${variable}` syntax with `<Var>{variable}</Var>`
33
- - Additional variable components include `<Num>`, `<Currency>`, and `<DateTime>`
34
- - See the `mcp__locadex__next_basic_variables` guide for more information on Variable Components.
35
-
36
- ## `useGT()` hook
37
-
38
- Original:
39
-
40
- ```jsx
41
- const MyComponent = ({ name, count }) => {
42
- return <div>{`Welcome ${name}, you have ${count} items`}</div>;
43
- };
44
- ```
45
-
46
- After:
47
-
48
- ```jsx
49
- import { useGT } from 'gt-next';
50
- const MyComponent = ({ name, count }) => {
51
- const t = useGT();
52
- return (
53
- <div>
54
- {t('Welcome {name}, you have {count} items', {
55
- variables: { name, count },
56
- })}
57
- </div>
58
- );
59
- };
60
- ```
61
-
62
- **Notes**:
63
-
64
- - Replace `${variable}` syntax with `{variable}` placeholders
65
- - Pass dynamic values via `variables` object
66
- - Variable names must match placeholder names exactly
67
-
68
- **IMPORTANT:** If the function scope is async, use `getGT()` instead of `useGT()`. `getGT()` must be awaited. Otherwise, their usage is identical.
69
-
70
- ```jsx
71
- import { getGT } from 'gt-next/server';
72
- const MyComponent = async ({ name, count }) => {
73
- const t = await getGT();
74
- return (
75
- <div>
76
- {t('Welcome {name}, you have {count} items', {
77
- variables: { name, count },
78
- })}
79
- </div>
80
- );
81
- };
82
- ```
@@ -1,208 +0,0 @@
1
- # Guide: Internationalization Patterns for Mapped Content
2
-
3
- **Objective**: Implement internationalization for mapping expressions using `<T>`, `useGT()`, and `useTranslations()`.
4
-
5
- ## `<T>` Component Usage
6
-
7
- **Rule**: `<T>` components translate static JSX content only. Dynamic content requires alternative approaches.
8
-
9
- **Valid pattern**:
10
-
11
- ```jsx
12
- <T>
13
- <div> Here's some translated text </div>
14
- Here is some more translated text!
15
- </T>
16
- ```
17
-
18
- **Invalid pattern** - `<T>` cannot process dynamic mapping:
19
-
20
- ```jsx
21
- const MyComponent = () => {
22
- const someList = [
23
- <div>Hello, World!</div>,
24
- <div>Welcome to the website!</div>,
25
- <div>Goodbye!</div>,
26
- ];
27
- return <T>{someList.map((item) => item)}</T>; // INVALID
28
- };
29
- ```
30
-
31
- **Solution**: Apply `<T>` to individual static items, not the mapping operation:
32
-
33
- ```jsx
34
- const MyComponent = () => {
35
- const someList = [
36
- <T>
37
- <div>Hello, World!</div>
38
- </T>,
39
- <T>
40
- <div>Welcome to the website!</div>
41
- </T>,
42
- <T>
43
- <div>Goodbye!</div>
44
- </T>,
45
- ];
46
- return <>{someList.map((item) => item)}</>;
47
- };
48
- ```
49
-
50
- **Key requirement**: Each `<T>` component must have direct access to static text content.
51
-
52
- ## `useGT()` Pattern
53
-
54
- **Implementation**: Translate individual strings within data structures before mapping:
55
-
56
- ```jsx
57
- import { useGT } from 'gt-next';
58
- const MyComponent = () => {
59
- const t = useGT();
60
- const someList = [
61
- t('Hello, World!'),
62
- t('Welcome to the website!'),
63
- t('Goodbye!'),
64
- ];
65
- return <>{someList.map((item) => item)}</>;
66
- };
67
- ```
68
-
69
- **Note:** When a function or component is marked as `async`, you should use the `getGT()` hook to get the translation callback function. `getGT()` must be awaited. Other than this, the usage of `getGT()` and `useGT()` is the same.
70
-
71
- **Key requirement**: Each string must be static.
72
-
73
- ## `useTranslations()` Pattern
74
-
75
- ### Notes
76
-
77
- - This is the classic dictionary approach. It separates content from implementation context.
78
- - **Use sparingly** - only use this approach when content reuse across components justifies the separation.
79
- - Additionally, this approach may be used to internationalize complex strings that are both logically functional and are also displayed in UI.
80
- - If you use this approach, your dictionary entries must be stored in a file called `dictionary.json` in the root of the project. (or in `src/dictionary.json` if there is a `src` directory). `dictionary.js` and `dictionary.ts` are also valid. This is the only case in which you are allowed to create a file. **DO NOT** create any other files.
81
-
82
- **Dictionary structure**:
83
-
84
- ```json title="dictionary.json"
85
- {
86
- "greetings": {
87
- "world": "Hello, World!",
88
- "welcome": "Welcome to the website!",
89
- "goodbye": "Goodbye!"
90
- }
91
- }
92
- ```
93
-
94
- **Implementation**:
95
-
96
- ```jsx
97
- import { useTranslations } from 'gt-next';
98
- const MyComponent = () => {
99
- const t = useTranslations();
100
- const someListOfIds = ['world', 'welcome', 'goodbye'];
101
- return <>{someListOfIds.map((id) => t(`greetings.${id}`))}</>;
102
- };
103
- ```
104
-
105
- ### Notes
106
-
107
- - Strings, when used with `useTranslations()`, are always accessed dynamically as dictionary keys.
108
- - When a function or component is marked as `async`, you should use the `getTranslations()` hook to get the translation callback function. `getTranslations()` must be awaited. Other than this, the usage of `getTranslations()` and `useTranslations()` is the same.
109
-
110
- ## Complex Nested Object Translation
111
-
112
- ### Challenge: Multi-level Data Structures
113
-
114
- **Scenario**: This is an example scenario where nested objects with translatable content at multiple levels require a systematic translation approach.
115
-
116
- **Non-internationalized example**:
117
-
118
- ```jsx
119
- const MyComponent = () => {
120
- const users = {
121
- archie: {
122
- name: 'Archie',
123
- role: 'Developer',
124
- skills: ['JavaScript', 'React', 'TypeScript'],
125
- },
126
- ernest: {
127
- name: 'Ernest',
128
- role: 'Designer',
129
- skills: ['UI/UX', 'Figma', 'Illustration'],
130
- },
131
- brian: {
132
- name: 'Brian',
133
- role: 'Product Manager',
134
- skills: ['Strategy', 'Planning', 'Communication'],
135
- },
136
- };
137
- return (
138
- <div>
139
- {Object.entries(users).map(([key, user]) => (
140
- <div key={key}>
141
- <h2>{user.name}</h2>
142
- <p>Role: {user.role}</p>
143
- <ul>
144
- {user.skills.map((skill, index) => (
145
- <li key={index}>{skill}</li>
146
- ))}
147
- </ul>
148
- </div>
149
- ))}
150
- </div>
151
- );
152
- };
153
- ```
154
-
155
- ### Solution: Comprehensive Translation Strategy
156
-
157
- **Requirements**:
158
-
159
- - Translate role labels and skill names
160
- - Handle string interpolation for template text
161
- - Provide contextual information for ambiguous terms
162
-
163
- **Implementation**:
164
-
165
- ```jsx
166
- import { useGT } from 'gt-next';
167
- const MyComponent = () => {
168
- const t = useGT();
169
- const users = {
170
- archie: {
171
- name: 'Archie',
172
- role: t('Developer', { context: 'As in a software developer' }),
173
- skills: [t('JavaScript'), t('React'), t('TypeScript')],
174
- },
175
- ernest: {
176
- name: 'Ernest',
177
- role: t('Designer', { context: 'As in a UI/UX designer' }),
178
- skills: [t('UI/UX'), t('Figma'), t('Illustration')],
179
- },
180
- brian: {
181
- name: 'Brian',
182
- role: t('Product Manager'),
183
- skills: [t('Strategy'), t('Planning'), t('Communication')],
184
- },
185
- };
186
- return (
187
- <div>
188
- {Object.entries(users).map(([key, user]) => (
189
- <div key={key}>
190
- <h2>{user.name}</h2>
191
- <p>{t('Role: {role}', { variables: { role: user.role } })}</p>
192
- <ul>
193
- {user.skills.map((skill, index) => (
194
- <li key={index}>{skill}</li>
195
- ))}
196
- </ul>
197
- </div>
198
- ))}
199
- </div>
200
- );
201
- };
202
- ```
203
-
204
- **Key techniques**:
205
-
206
- 1. **Context provision**: `{ context: 'As in a software developer' }` for disambiguation
207
- 2. **Variable interpolation**: `t('Role: {role}', { variables: { role: user.role } })`
208
- 3. **Systematic translation**: Apply `t()` to all user-facing strings within data structure