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
@@ -1,545 +0,0 @@
1
- # Internationalizing Variables Outside Function Scope in Server Components
2
-
3
- ## When to Apply This Pattern
4
-
5
- Apply this pattern when you encounter variable declarations (`let`, `const`, or `var`) outside of function scope that contain strings needing internationalization, and these variables are exclusively used within server-side components.
6
-
7
- ## Rules
8
-
9
- 1. **Minimal footprint**: Minimize code changes by keeping internationalized content in the same file where it originated
10
- 2. **No file movement**: Avoid moving content between files unless absolutely necessary
11
- 3. **Simple cases**: For single-use cases, move variable into component and use `getGT()`
12
- 4. **Complex cases**: For complex scenarios, create async function to access translated strings
13
- 5. **Scope**: Only use this implementation for string translation (for HTML translation use ALWAYS `<T>`)
14
- 6. **No adding async**: Never mark a function as async that wasn't already marked async (unless they are a component function)
15
-
16
- Rule of thumb for implementation:
17
-
18
- - If data is being imported, wrap it in a function that takes `t()` as a parameter
19
- - If data is in the same file, you can either wrap it in a function or move it directly into the components that need it
20
-
21
- ## Required Approach Based on Usage Pattern
22
-
23
- ## Pattern 1: Single Variable Used in One Component
24
-
25
- **Scenario:** Constant declared outside server component function scope.
26
-
27
- ```jsx
28
- const OUTSIDE_CONST = 'Hello there!';
29
-
30
- export function Example() {
31
- return <>{OUTSIDE_CONST}</>;
32
- }
33
- ```
34
-
35
- **Solution:** Move declaration inside server component and make function async:
36
-
37
- 1. Move the variable inside the component
38
- 2. Add the `getGT()` function.
39
- 3. Translate with the `t()` function
40
-
41
- ```jsx
42
- import { getGT } from 'gt-next/server';
43
- export async function Example() {
44
- const t = await getGT();
45
- const OUTSIDE_CONST = t('Hello there!');
46
-
47
- return <>{OUTSIDE_CONST}</>;
48
- }
49
- ```
50
-
51
- **Common Pitfalls:**
52
-
53
- - importing `getGT()` from `'gt-next'` instead of `'gt-next/server'`
54
- - using the `useGT()` hook or adding the `'use client'` directive, even though this is a server component
55
- - trying to use `getGT()` in a client component, it should only be used for server components
56
-
57
- ## Pattern 2: Variable Reused Across Multiple Components
58
-
59
- **Scenario:** Variable used in multiple server components within SAME FILE.
60
-
61
- ```jsx
62
- const OUTSIDE_CONST = 'Hello there!';
63
-
64
- export function Example1() {
65
- return <>{OUTSIDE_CONST}</>;
66
- }
67
-
68
- export function Example2() {
69
- return <>{OUTSIDE_CONST}</>;
70
- }
71
- ```
72
-
73
- **Solution:** Convert variable to async function that returns translated value:
74
-
75
- 1. Turn the variable into an async function beginning with the word "get" (`OUTSIDE_CONST` -> `getOutsideConst()`)
76
- 2. Add the `getGT()` function inside of the new function
77
- 3. Translate with the `t()` function and return the translated string
78
- 4. Access the translated string by awaiting your newly defined function
79
-
80
- ```jsx
81
- import { getGT } from 'gt-next/server';
82
- const getOutsideConst = async () => {
83
- const t = await getGT();
84
- return t('Hello there!');
85
- };
86
-
87
- export async function Example1() {
88
- const outsideConst = await getOutsideConst();
89
-
90
- return <>{outsideConst}</>;
91
- }
92
-
93
- export async function Example2() {
94
- const outsideConst = await getOutsideConst();
95
-
96
- return <>{outsideConst}</>;
97
- }
98
- ```
99
-
100
- ## Pattern 3: Complex Data Structures Across Multiple Files
101
-
102
- **Scenario:** Centralized data structure with translatable strings used ACCROSS MULTIPLE FILES.
103
-
104
- ```jsx title="navMap.ts"
105
- const navMap = [
106
- {
107
- name: 'dashboard',
108
- url: '/dashboard',
109
- type: 'page',
110
- },
111
- {
112
- name: 'landing',
113
- url: '/landing',
114
- type: 'page',
115
- },
116
- {
117
- name: 'links',
118
- type: 'divider',
119
- children: [
120
- {
121
- name: 'blog',
122
- url: '/blog',
123
- },
124
- {
125
- name: 'help',
126
- url: '/help',
127
- },
128
- ],
129
- },
130
- ];
131
- export default navMap;
132
- ```
133
-
134
- Usage: Imported and used in different server-side component files.
135
-
136
- ```jsx title="Example1.tsx"
137
- import navMap from './navMap';
138
- import NavItem from './NavItem';
139
- export default function Example1() {
140
- return (
141
- <>
142
- {navMap.map((navItem) => (
143
- <NavItem item={navItem} />
144
- ))}
145
- </>
146
- );
147
- }
148
- ```
149
-
150
- ```jsx title="Example2.tsx"
151
- import navMap from './navMap';
152
- import NavItem from './NavItem';
153
- export default function Example2() {
154
- return (
155
- <>
156
- {navMap
157
- .filter(() => navItem.type === 'page')
158
- .map((navItem) => (
159
- <NavItem item={navItem} />
160
- ))}
161
- </>
162
- );
163
- }
164
- ```
165
-
166
- **Solution:** Convert data structure export to async function:
167
-
168
- 1. Turn the variable into an async function beginning with the word "get" (`navMap` -> `getNavMap()`) that takes `t()` as a parameter
169
- 2. Wrap all string content with the `t()` function
170
- 3. Import your newly defined function into the server components that require the data
171
- 4. Import `getGT()` in the server components that require the data
172
- 5. Invoke `getGT()` and your new function passing `t()` as a parameter
173
-
174
- ```jsx title="navMap.ts"
175
- import { getGT } from 'gt-next/server';
176
- const getNavMap = (t: (string: string, options?: InlineTranslationOptions) => string) => {
177
- return [
178
- {
179
- name: t('dashboard'),
180
- url: '/dashboard',
181
- type: 'page',
182
- },
183
- {
184
- name: t('landing'),
185
- url: '/landing',
186
- type: 'page',
187
- },
188
- {
189
- name: t('links'),
190
- type: 'divider',
191
- children: [
192
- {
193
- name: t('blog'),
194
- url: '/blog',
195
- },
196
- {
197
- name: t('help'),
198
- url: '/help',
199
- },
200
- ],
201
- },
202
- ];
203
- };
204
- export default getNavMap;
205
- ```
206
-
207
- **Updated Components:** Make components async and await the function call:
208
-
209
- ```jsx title="Example1.tsx"
210
- import { getGT } from 'gt-next/server';
211
- import getNavMap from './navMap';
212
- import NavItem from './NavItem';
213
- export default async function Example1() {
214
- const t = await getGT();
215
- const navMap = getNavMap(t);
216
- return (
217
- <>
218
- {navMap.map((navItem) => (
219
- <NavItem item={navItem} />
220
- ))}
221
- </>
222
- );
223
- }
224
- ```
225
-
226
- ```jsx title="Example2.tsx"
227
- import { getGT } from 'gt-next/server';
228
- import getNavMap from './navMap';
229
- import NavItem from './NavItem';
230
- export default async function Example2() {
231
- const t = await getGT();
232
- const navMap = getNavMap(t);
233
- return (
234
- <>
235
- {navMap
236
- .filter(() => navItem.type === 'page')
237
- .map((navItem) => (
238
- <NavItem item={navItem} />
239
- ))}
240
- </>
241
- );
242
- }
243
- ```
244
-
245
- ## Pattern 4: Cross-File String Declaration with Single Import
246
-
247
- **Scenario:** String declared in one file, imported and used in only one other file.
248
- **Principle:** Keep variables in their original declaration file to minimize changes.
249
-
250
- ```jsx
251
- export const some_string = 'Hello, World!';
252
- ```
253
-
254
- ```jsx
255
- import { some_string } from './constants';
256
-
257
- export default function MyComponent() {
258
- return <>{some_string}</>;
259
- }
260
- ```
261
-
262
- **Solution:** Convert string export to async function in original file:
263
-
264
- 1. Turn the variable into an async function beginning with the word "get" (`some_string` -> `getSomeString()`) that takes `t()` as a parameter
265
- 2. Wrap all string content with the `t()` function
266
- 3. Import your newly defined function into the server components that require the string
267
- 4. Import `getGT()` in the server components that require the string
268
- 5. Invoke `getGT()` and your new function passing `t()` as a parameter
269
-
270
- ```jsx
271
- import { getGT } from 'gt-next/server';
272
-
273
- export const getSomeString = async (t: (string: string, options?: InlineTranslationOptions) => string) => {
274
- return t('Hello, World!');
275
- };
276
- ```
277
-
278
- ```jsx
279
- import { getGT } from 'gt-next/server';
280
- import { getSomeString } from './constants';
281
-
282
- export default async function MyComponent() {
283
- const t = getGT();
284
- const some_string = await getSomeString();
285
- return <>{some_string}</>;
286
- }
287
- ```
288
-
289
- ## IMPORTANT
290
-
291
- Be careful to only modify non-functional strings. Avoid modifying functional strings such as ids.
292
-
293
- ## Implementation Patterns: Functions
294
-
295
- ### Pattern 1: Function in Same File
296
-
297
- **Scenario**: Function declared outside component scope within SAME FILE
298
-
299
- ```jsx
300
- function getErrorMessage(errorType) {
301
- switch (errorType) {
302
- case 'network':
303
- return 'Network connection failed';
304
- case 'auth':
305
- return 'Authentication failed';
306
- default:
307
- return 'Unknown error occurred';
308
- }
309
- }
310
-
311
- export default function Example() {
312
- const error = 'network';
313
- const message = getErrorMessage(error);
314
-
315
- return <div>{message}</div>;
316
- }
317
- ```
318
-
319
- **Solution**: Pass `t()` function as parameter to the function
320
-
321
- 1. Import `getGT()` from `'gt-next/server'`
322
- 2. Modify the function to accept `t()` as a parameter
323
- 3. Use `t()` for string translations within the function
324
- 4. Make the component async and await `getGT()`
325
- 5. Pass `t()` when calling the function in the component
326
-
327
- ```jsx
328
- import { getGT } from 'gt-next/server';
329
-
330
- function getErrorMessage(errorType, t: (string: string, options?: InlineTranslationOptions) => string) {
331
- switch (errorType) {
332
- case 'network':
333
- return t('Network connection failed');
334
- case 'auth':
335
- return t('Authentication failed');
336
- default:
337
- return t('Unknown error occurred');
338
- }
339
- }
340
-
341
- export default async function Example() {
342
- const error = 'network';
343
- const t = await getGT();
344
- const message = getErrorMessage(error, t);
345
-
346
- return <div>{message}</div>;
347
- }
348
- ```
349
-
350
- ### Pattern 2: Function in Different File
351
-
352
- **Scenario**: Function exported from one file and imported in another (MULTIPLE FILES)
353
-
354
- ```jsx title="utils.ts"
355
- export function formatStatus(status) {
356
- switch (status) {
357
- case 'pending':
358
- return 'Pending approval';
359
- case 'approved':
360
- return 'Request approved';
361
- case 'rejected':
362
- return 'Request rejected';
363
- default:
364
- return 'Status unknown';
365
- }
366
- }
367
- ```
368
-
369
- ```jsx title="StatusComponent.tsx"
370
- import { formatStatus } from './utils';
371
-
372
- export default function StatusComponent() {
373
- const status = 'pending';
374
- const statusText = formatStatus(status);
375
-
376
- return <div>{statusText}</div>;
377
- }
378
- ```
379
-
380
- **Solution**: Modify function to accept `t()` parameter and pass it from component
381
-
382
- 1. Modify the function in the utils file to accept `t()` as a parameter
383
- 2. Use `t()` for string translations within the function
384
- 3. Import `getGT()` from `'gt-next/server'` in the component
385
- 4. Make the component async and await `getGT()`
386
- 5. Pass `t()` when calling the imported function
387
-
388
- ```jsx title="utils.ts"
389
- export function formatStatus(status, t: (string: string, options?: InlineTranslationOptions) => string) {
390
- switch (status) {
391
- case 'pending':
392
- return t('Pending approval');
393
- case 'approved':
394
- return t('Request approved');
395
- case 'rejected':
396
- return t('Request rejected');
397
- default:
398
- return t('Status unknown');
399
- }
400
- }
401
- ```
402
-
403
- ```jsx title="StatusComponent.tsx"
404
- import { getGT } from 'gt-next/server';
405
- import { formatStatus } from './utils';
406
-
407
- export default async function StatusComponent() {
408
- const status = 'pending';
409
- const t = await getGT();
410
- const statusText = formatStatus(status, t);
411
-
412
- return <div>{statusText}</div>;
413
- }
414
- ```
415
-
416
- ### Pattern 3: Complex Server Action Chain
417
-
418
- **Scenario**: Server action that calls functions across multiple files to reach translatable content
419
-
420
- ```jsx title="actions.ts"
421
- 'use server';
422
-
423
- import { handleOrderSubmission } from './orderProcessor';
424
-
425
- export async function submitOrderAction(formData) {
426
- const result = handleOrderSubmission(formData);
427
- return result;
428
- }
429
- ```
430
-
431
- ```jsx title="orderProcessor.ts"
432
- import { validatePayment } from './paymentValidator';
433
-
434
- export function handleOrderSubmission(orderData) {
435
- const paymentResult = validatePayment(orderData.payment);
436
-
437
- if (!paymentResult.success) {
438
- return {
439
- success: false,
440
- message: paymentResult.errorMessage,
441
- };
442
- }
443
-
444
- return {
445
- success: true,
446
- message: 'Order processed successfully',
447
- };
448
- }
449
- ```
450
-
451
- ```jsx title="paymentValidator.ts"
452
- export function validatePayment(paymentData) {
453
- if (!paymentData.cardNumber) {
454
- return {
455
- success: false,
456
- errorMessage: 'Credit card number is required',
457
- };
458
- }
459
-
460
- if (!paymentData.expiryDate) {
461
- return {
462
- success: false,
463
- errorMessage: 'Expiry date is required',
464
- };
465
- }
466
-
467
- return {
468
- success: true,
469
- message: 'Payment validated successfully',
470
- };
471
- }
472
- ```
473
-
474
- **Solution**: Pass `t()` function through the entire call chain
475
-
476
- 1. Import `getGT()` in the server action file
477
- 2. Await `getGT()` in the server action and pass `t()` down the chain
478
- 3. Modify each function in the chain to accept and pass through the `t()` parameter
479
- 4. Use `t()` for string translations at the final destination
480
-
481
- ```jsx title="actions.ts"
482
- 'use server';
483
-
484
- import { getGT } from 'gt-next/server';
485
- import { handleOrderSubmission } from './orderProcessor';
486
-
487
- export async function submitOrderAction(formData) {
488
- const t = await getGT();
489
- const result = handleOrderSubmission(formData, t);
490
- return result;
491
- }
492
- ```
493
-
494
- ```jsx title="orderProcessor.ts"
495
- import { validatePayment } from './paymentValidator';
496
-
497
- export function handleOrderSubmission(orderData, t: (string: string, options?: InlineTranslationOptions) => string) {
498
- const paymentResult = validatePayment(orderData.payment, t);
499
-
500
- if (!paymentResult.success) {
501
- return {
502
- success: false,
503
- message: paymentResult.errorMessage
504
- };
505
- }
506
-
507
- return {
508
- success: true,
509
- message: t('Order processed successfully')
510
- };
511
- }
512
- ```
513
-
514
- ```jsx title="paymentValidator.ts"
515
- export function validatePayment(paymentData, t: (string: string, options?: InlineTranslationOptions) => string) {
516
- if (!paymentData.cardNumber) {
517
- return {
518
- success: false,
519
- errorMessage: t('Credit card number is required')
520
- };
521
- }
522
-
523
- if (!paymentData.expiryDate) {
524
- return {
525
- success: false,
526
- errorMessage: t('Expiry date is required')
527
- };
528
- }
529
-
530
- return {
531
- success: true,
532
- message: t('Payment validated successfully')
533
- };
534
- }
535
- ```
536
-
537
- **Common Pitfalls for Functions**
538
-
539
- - Forgetting to add the `t` parameter to the function signature
540
- - Not passing `t()` when calling the function
541
- - Importing `getGT()` from `'gt-next'` instead of `'gt-next/server'`
542
- - Making utility functions async when they shouldn't be (only component functions should be made async)
543
- - Using `useGT()` or `'use client'` in server components
544
- - Not making the component async when using `getGT()`
545
- - Breaking the `t()` parameter chain when passing through multiple function calls