locadex 0.1.2 → 0.1.4

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 (71) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli.d.ts +1 -0
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +14 -0
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands/fixErrors.d.ts +4 -0
  7. package/dist/commands/fixErrors.d.ts.map +1 -0
  8. package/dist/commands/fixErrors.js +41 -0
  9. package/dist/commands/fixErrors.js.map +1 -0
  10. package/dist/logging/logger.d.ts.map +1 -1
  11. package/dist/logging/logger.js.map +1 -1
  12. package/dist/mcp/getGuide.d.ts.map +1 -1
  13. package/dist/mcp/getGuide.js +2 -1
  14. package/dist/mcp/getGuide.js.map +1 -1
  15. package/dist/mcp/tools/guides.d.ts.map +1 -1
  16. package/dist/mcp/tools/guides.js +25 -55
  17. package/dist/mcp/tools/guides.js.map +1 -1
  18. package/dist/mcp.d.ts.map +1 -1
  19. package/dist/mcp.js +4 -2
  20. package/dist/mcp.js.map +1 -1
  21. package/dist/tasks/concurrency.d.ts.map +1 -1
  22. package/dist/tasks/concurrency.js +15 -23
  23. package/dist/tasks/concurrency.js.map +1 -1
  24. package/dist/tasks/fixErrors.d.ts +2 -0
  25. package/dist/tasks/fixErrors.d.ts.map +1 -0
  26. package/dist/tasks/fixErrors.js +82 -0
  27. package/dist/tasks/fixErrors.js.map +1 -0
  28. package/dist/tasks/i18n.d.ts.map +1 -1
  29. package/dist/tasks/i18n.js +25 -82
  30. package/dist/tasks/i18n.js.map +1 -1
  31. package/dist/tasks/setup.d.ts.map +1 -1
  32. package/dist/tasks/setup.js +21 -9
  33. package/dist/tasks/setup.js.map +1 -1
  34. package/dist/types/claude-sdk.d.ts +13 -9
  35. package/dist/types/claude-sdk.d.ts.map +1 -1
  36. package/dist/types/claude-sdk.js.map +1 -1
  37. package/dist/utils/claudeCode.d.ts +13 -1
  38. package/dist/utils/claudeCode.d.ts.map +1 -1
  39. package/dist/utils/claudeCode.js +173 -66
  40. package/dist/utils/claudeCode.js.map +1 -1
  41. package/dist/utils/errors.d.ts +20 -0
  42. package/dist/utils/errors.d.ts.map +1 -0
  43. package/dist/utils/errors.js +39 -0
  44. package/dist/utils/errors.js.map +1 -0
  45. package/dist/utils/packages/installPackage.d.ts +1 -2
  46. package/dist/utils/packages/installPackage.d.ts.map +1 -1
  47. package/dist/utils/packages/installPackage.js +19 -28
  48. package/dist/utils/packages/installPackage.js.map +1 -1
  49. package/dist/utils/shared.d.ts +1 -1
  50. package/dist/utils/shared.js +1 -1
  51. package/dist/utils/shared.js.map +1 -1
  52. package/dist/utils/shutdown.d.ts +1 -2
  53. package/dist/utils/shutdown.d.ts.map +1 -1
  54. package/dist/utils/shutdown.js +1 -5
  55. package/dist/utils/shutdown.js.map +1 -1
  56. package/guides/next/advanced/{ternary-operators.md → conditional-rendering.md} +97 -39
  57. package/guides/next/advanced/external-strings.md +346 -0
  58. package/guides/next/advanced/interpolated-strings.md +35 -115
  59. package/guides/next/advanced/{complicated-mapping-expressions.md → mapping-expressions.md} +58 -51
  60. package/guides/next/basic/branches.md +62 -45
  61. package/guides/next/basic/jsx.md +35 -33
  62. package/guides/next/basic/strings.md +43 -25
  63. package/guides/next/basic/variables.md +12 -12
  64. package/guides/next/important/functions.md +13 -11
  65. package/guides/next/{advanced → migration}/migrating.md +2 -3
  66. package/package.json +1 -1
  67. package/guides/next/advanced/var-outside-client-component.md +0 -446
  68. package/guides/next/advanced/var-outside-client-server-component.md +0 -550
  69. package/guides/next/advanced/var-outside-server-component.md +0 -545
  70. package/guides/next/basic/client-side-components.md +0 -221
  71. package/guides/next/basic/server-side-components.md +0 -165
@@ -0,0 +1,346 @@
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,14 +1,10 @@
1
- # String Interpolation Internationalization Patterns
1
+ # Guide: Internationalizing dynamic strings
2
2
 
3
- **Objective**: Transform template literal strings with dynamic variables into translatable strings using `useGT()`/`getGT()` and `useDict()`/`getDict()`.
3
+ **Objective**: Transform template literal strings with dynamic variables into translatable strings using `<T>` and `useGT()`.
4
4
 
5
- ## Core Pattern: Variable Injection
5
+ ## The `<T>` component (preferred for JSX/HTML):
6
6
 
7
- ### `useGT()`/`getGT()` Method
8
-
9
- **Transform**: Template literals → Translatable strings with variable placeholders
10
-
11
- **Non-internationalized pattern**:
7
+ Original:
12
8
 
13
9
  ```jsx
14
10
  const MyComponent = ({ name, count }) => {
@@ -16,147 +12,71 @@ const MyComponent = ({ name, count }) => {
16
12
  };
17
13
  ```
18
14
 
19
- **Internationalized implementation**:
20
-
21
- **Option A** the `<T>` component (preferred for JSX/HTML):
22
-
23
- ```jsx
24
- import { T } from 'gt-next';
25
-
26
- const MyComponent = ({ name, count }) => {
27
- return (
28
- <div>
29
- <T>
30
- Welcome <Var>{name}</Var>, you have <Var>{count}</Var> items
31
- </T>
32
- </div>
33
- );
34
- };
35
- ```
36
-
37
- **Option B** the `useGT()` hook:
15
+ After:
38
16
 
39
17
  ```jsx
40
- 'use client';
41
- import { useGT } from 'gt-next/client';
42
-
18
+ import { T, Var, Num } from 'gt-next';
43
19
  const MyComponent = ({ name, count }) => {
44
- const t = useGT(); // Client-side
45
- // const t = await getGT(); // Server-side
46
20
  return (
47
- <div>
48
- {t('Welcome {name}, you have {count} items', {
49
- variables: { name, count },
50
- })}
51
- </div>
21
+ <T>
22
+ <div>
23
+ Welcome <Var>{name}</Var>, you have <Num>{count}</Num> items
24
+ </div>
25
+ </T>
52
26
  );
53
27
  };
54
28
  ```
55
29
 
56
- **Key requirements**:
57
-
58
- - Replace `${variable}` syntax with `{variable}` placeholders
59
- - Pass dynamic values via `variables` object
60
- - Variable names must match placeholder names exactly
30
+ **Notes**:
61
31
 
62
- ### `useDict()`/`getDict()` Method
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.
63
35
 
64
- **Option C**: Template literals → Dictionary keys with variable placeholders
36
+ ## `useGT()` hook
65
37
 
66
- **Non-internationalized pattern**:
38
+ Original:
67
39
 
68
40
  ```jsx
69
- const MyComponent = ({ username, role }) => {
70
- return <div>{`User ${username} has the role of ${role}`}</div>;
71
- };
72
- ```
73
-
74
- **Dictionary structure**:
75
-
76
- ```json
77
- {
78
- "Users": {
79
- "Profile": "User {username} has the role of {role}"
80
- }
81
- }
82
- ```
83
-
84
- **Implementation**:
85
-
86
- ```jsx
87
- 'use client';
88
- import { useDict } from 'gt-next/client';
89
- const MyComponent = ({ username, role }) => {
90
- const t = useDict(); // Client-side
91
- // const t = await getDict(); // Server-side
92
- return (
93
- <div>
94
- {t('Users.Profile', {
95
- variables: { username, role },
96
- })}
97
- </div>
98
- );
41
+ const MyComponent = ({ name, count }) => {
42
+ return <div>{`Welcome ${name}, you have ${count} items`}</div>;
99
43
  };
100
44
  ```
101
45
 
102
- ## Advanced Patterns
103
-
104
- ### Multi-Variable Interpolation
105
-
106
- **Scenario**: Multiple dynamic values in a single translatable string
107
-
108
- **Implementation**:
46
+ After:
109
47
 
110
48
  ```jsx
111
- 'use client';
112
- import { useGT } from 'gt-next/client';
113
- const MyComponent = ({ firstName, lastName, age, city }) => {
114
- const t = useGT(); // Client-side
115
- // const t = await getGT(); // Server-side
49
+ import { useGT } from 'gt-next';
50
+ const MyComponent = ({ name, count }) => {
51
+ const t = useGT();
116
52
  return (
117
53
  <div>
118
- {t('{firstName} {lastName} is {age} years old and lives in {city}', {
119
- variables: { firstName, lastName, age, city },
54
+ {t('Welcome {name}, you have {count} items', {
55
+ variables: { name, count },
120
56
  })}
121
57
  </div>
122
58
  );
123
59
  };
124
60
  ```
125
61
 
126
- **Requirements**: All placeholder names must have corresponding entries in `variables` object.
127
-
128
- ### Object Property Extraction
62
+ **Notes**:
129
63
 
130
- **Scenario**: Extract values from nested objects for interpolation
131
-
132
- **Dictionary definition**:
133
-
134
- ```json
135
- {
136
- "Users": {
137
- "Details": "{name} works as a {role} in the {department} department"
138
- }
139
- }
140
- ```
64
+ - Replace `${variable}` syntax with `{variable}` placeholders
65
+ - Pass dynamic values via `variables` object
66
+ - Variable names must match placeholder names exactly
141
67
 
142
- **Implementation**:
68
+ **IMPORTANT:** If the function scope is async, use `getGT()` instead of `useGT()`. `getGT()` must be awaited. Otherwise, their usage is identical.
143
69
 
144
70
  ```jsx
145
- const MyComponent = ({ user }) => {
146
- const t = useDict(); // Client-side
147
- // const t = await getDict(); // Server-side
71
+ import { getGT } from 'gt-next/server';
72
+ const MyComponent = async ({ name, count }) => {
73
+ const t = await getGT();
148
74
  return (
149
75
  <div>
150
- {t('Users.Details', {
151
- variables: {
152
- name: user.name,
153
- role: user.role,
154
- department: user.department,
155
- },
76
+ {t('Welcome {name}, you have {count} items', {
77
+ variables: { name, count },
156
78
  })}
157
79
  </div>
158
80
  );
159
81
  };
160
82
  ```
161
-
162
- **Pattern**: Explicitly map object properties to named variables for clear placeholder relationships.