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.
- package/CHANGELOG.md +12 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +14 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/fixErrors.d.ts +4 -0
- package/dist/commands/fixErrors.d.ts.map +1 -0
- package/dist/commands/fixErrors.js +41 -0
- package/dist/commands/fixErrors.js.map +1 -0
- package/dist/logging/logger.d.ts.map +1 -1
- package/dist/logging/logger.js.map +1 -1
- package/dist/mcp/getGuide.d.ts.map +1 -1
- package/dist/mcp/getGuide.js +2 -1
- package/dist/mcp/getGuide.js.map +1 -1
- package/dist/mcp/tools/guides.d.ts.map +1 -1
- package/dist/mcp/tools/guides.js +25 -55
- package/dist/mcp/tools/guides.js.map +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +4 -2
- package/dist/mcp.js.map +1 -1
- package/dist/tasks/concurrency.d.ts.map +1 -1
- package/dist/tasks/concurrency.js +15 -23
- package/dist/tasks/concurrency.js.map +1 -1
- package/dist/tasks/fixErrors.d.ts +2 -0
- package/dist/tasks/fixErrors.d.ts.map +1 -0
- package/dist/tasks/fixErrors.js +82 -0
- package/dist/tasks/fixErrors.js.map +1 -0
- package/dist/tasks/i18n.d.ts.map +1 -1
- package/dist/tasks/i18n.js +25 -82
- package/dist/tasks/i18n.js.map +1 -1
- package/dist/tasks/setup.d.ts.map +1 -1
- package/dist/tasks/setup.js +21 -9
- package/dist/tasks/setup.js.map +1 -1
- package/dist/types/claude-sdk.d.ts +13 -9
- package/dist/types/claude-sdk.d.ts.map +1 -1
- package/dist/types/claude-sdk.js.map +1 -1
- package/dist/utils/claudeCode.d.ts +13 -1
- package/dist/utils/claudeCode.d.ts.map +1 -1
- package/dist/utils/claudeCode.js +173 -66
- package/dist/utils/claudeCode.js.map +1 -1
- package/dist/utils/errors.d.ts +20 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +39 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/packages/installPackage.d.ts +1 -2
- package/dist/utils/packages/installPackage.d.ts.map +1 -1
- package/dist/utils/packages/installPackage.js +19 -28
- package/dist/utils/packages/installPackage.js.map +1 -1
- package/dist/utils/shared.d.ts +1 -1
- package/dist/utils/shared.js +1 -1
- package/dist/utils/shared.js.map +1 -1
- package/dist/utils/shutdown.d.ts +1 -2
- package/dist/utils/shutdown.d.ts.map +1 -1
- package/dist/utils/shutdown.js +1 -5
- package/dist/utils/shutdown.js.map +1 -1
- package/guides/next/advanced/{ternary-operators.md → conditional-rendering.md} +97 -39
- package/guides/next/advanced/external-strings.md +346 -0
- package/guides/next/advanced/interpolated-strings.md +35 -115
- package/guides/next/advanced/{complicated-mapping-expressions.md → mapping-expressions.md} +58 -51
- package/guides/next/basic/branches.md +62 -45
- package/guides/next/basic/jsx.md +35 -33
- package/guides/next/basic/strings.md +43 -25
- package/guides/next/basic/variables.md +12 -12
- package/guides/next/important/functions.md +13 -11
- package/guides/next/{advanced → migration}/migrating.md +2 -3
- package/package.json +1 -1
- package/guides/next/advanced/var-outside-client-component.md +0 -446
- package/guides/next/advanced/var-outside-client-server-component.md +0 -550
- package/guides/next/advanced/var-outside-server-component.md +0 -545
- package/guides/next/basic/client-side-components.md +0 -221
- package/guides/next/basic/server-side-components.md +0 -165
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
# How to internationalize strings with `gt-next`
|
|
1
|
+
# Guide: How to internationalize strings with `gt-next`
|
|
2
2
|
|
|
3
3
|
Use `useGT()` and `getGT()` to internationalize strings.
|
|
4
4
|
|
|
5
5
|
**RULES:**
|
|
6
6
|
|
|
7
|
-
- For JSX and HTML content, ALWAYS use the `<T>` component
|
|
8
|
-
- If you see strings present in HTML that you think need pluralization, do not use strings. Instead use the `<T>` component and the `<Plural>` component.
|
|
9
|
-
- NEVER internationalize functional strings (error strings, logical strings, etc.) that could
|
|
7
|
+
- For JSX and HTML content, ALWAYS use the `<T>` component instead of `useGT()` and `getGT()`.
|
|
8
|
+
- If you see strings present in HTML that you think need pluralization, do not use strings. Instead use the `<T>` component and the `<Plural>` component. See the `mcp__locadex__next_basic_branches` guide for instructions.
|
|
9
|
+
- NEVER internationalize **functional strings** (error strings, logical strings, etc.) that could jeopardize the functionality of the application.
|
|
10
|
+
- **IMPORTANT:** Functional strings can also include strings returned from server actions and API endpoints.
|
|
10
11
|
|
|
11
|
-
**Import:** The `useGT()` and `getGT()` functions are exported from `gt-next
|
|
12
|
+
**Import:** The `useGT()` and `getGT()` functions are exported from `gt-next` and `gt-next/server` respectively.
|
|
12
13
|
|
|
13
14
|
```tsx
|
|
14
|
-
import { useGT } from 'gt-next
|
|
15
|
+
import { useGT } from 'gt-next';
|
|
15
16
|
import { getGT } from 'gt-next/server';
|
|
16
17
|
```
|
|
17
18
|
|
|
@@ -24,6 +25,12 @@ The usage of the callback is the same for both `useGT()` and `getGT()`.
|
|
|
24
25
|
|
|
25
26
|
`getGT()` is asynchronous and returns a promise that resolves to the translation function callback.
|
|
26
27
|
|
|
28
|
+
**IMPORTANT:**
|
|
29
|
+
|
|
30
|
+
- You should use `useGT()` as much as possible. The ONLY time you should use `getGT()` is when the function scope is async.
|
|
31
|
+
|
|
32
|
+
### Example of `useGT()`
|
|
33
|
+
|
|
27
34
|
Before:
|
|
28
35
|
|
|
29
36
|
```jsx
|
|
@@ -36,8 +43,7 @@ function Greeting() {
|
|
|
36
43
|
After:
|
|
37
44
|
|
|
38
45
|
```jsx
|
|
39
|
-
|
|
40
|
-
import { useGT } from 'gt-next/client';
|
|
46
|
+
import { useGT } from 'gt-next';
|
|
41
47
|
|
|
42
48
|
function Greeting() {
|
|
43
49
|
const t = useGT();
|
|
@@ -46,7 +52,9 @@ function Greeting() {
|
|
|
46
52
|
}
|
|
47
53
|
```
|
|
48
54
|
|
|
49
|
-
###
|
|
55
|
+
### Example of `getGT()`
|
|
56
|
+
|
|
57
|
+
**Important:** Only use `getGT()` in async functions. It must be awaited.
|
|
50
58
|
|
|
51
59
|
Before:
|
|
52
60
|
|
|
@@ -69,36 +77,33 @@ export async function Greeting() {
|
|
|
69
77
|
}
|
|
70
78
|
```
|
|
71
79
|
|
|
72
|
-
|
|
80
|
+
## Context Prop
|
|
73
81
|
|
|
74
82
|
Add `context` when content meaning is ambiguous:
|
|
75
83
|
|
|
76
84
|
```jsx
|
|
77
|
-
|
|
78
|
-
import { useGT } from 'gt-next/client';
|
|
85
|
+
import { useGT } from 'gt-next';
|
|
79
86
|
|
|
80
87
|
function Greeting() {
|
|
81
88
|
const t = useGT();
|
|
82
|
-
const
|
|
83
|
-
context: '
|
|
89
|
+
const crop = t('Crop', {
|
|
90
|
+
context: 'Crop, as in cropping an image',
|
|
84
91
|
});
|
|
85
|
-
return
|
|
92
|
+
return crop;
|
|
86
93
|
}
|
|
87
94
|
```
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- Provide context for words with multiple meanings (e.g., "toast" = bread vs notification).
|
|
92
|
-
- Provide context when the additional context can help the translator understand the meaning of the content.
|
|
96
|
+
**Rules:**
|
|
93
97
|
|
|
94
|
-
|
|
98
|
+
- Provide context for words with multiple meanings (e.g., "crop" = cropping an image vs the food crop).
|
|
99
|
+
- 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.
|
|
95
100
|
|
|
96
|
-
|
|
101
|
+
## Translation callback function usage rules
|
|
97
102
|
|
|
98
|
-
- Static strings
|
|
99
|
-
- Dynamic strings
|
|
103
|
+
- Static strings can always be wrapped in the translation callback function.
|
|
104
|
+
- Dynamic strings must be escaped with `{}` syntax (e.g., `t('Hello, {name}!', { variables: { name: 'John' } })`)
|
|
100
105
|
|
|
101
|
-
|
|
106
|
+
### Valid Usage Examples
|
|
102
107
|
|
|
103
108
|
In the following examples, `t` is the translation function callback.
|
|
104
109
|
|
|
@@ -123,7 +128,7 @@ const message = t('You have {dollars} dollars!', {
|
|
|
123
128
|
|
|
124
129
|
The options are the same as the options for the Intl.NumberFormat and Intl.DateTimeFormat APIs.
|
|
125
130
|
|
|
126
|
-
|
|
131
|
+
### Invalid Usage Examples
|
|
127
132
|
|
|
128
133
|
Never use the `${}` syntax for dynamic strings inside the translation callback.
|
|
129
134
|
|
|
@@ -142,3 +147,16 @@ Always add the `variable` key in the options field of `t()` when specifying vari
|
|
|
142
147
|
```tsx
|
|
143
148
|
const invalidUsage = t(`Hello, {name}!`, { name: 'Brian' });
|
|
144
149
|
```
|
|
150
|
+
|
|
151
|
+
**Correct Usage:**
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
const correctUsage = t(`Hello, {name}!`, { variables: { name: 'Brian' } });
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Summary
|
|
158
|
+
|
|
159
|
+
- Use `useGT()` as much as possible. The ONLY time you should use `getGT()` is when the function scope is async.
|
|
160
|
+
- Add `context` when content meaning is ambiguous.
|
|
161
|
+
- Use the translation callback function to wrap static strings.
|
|
162
|
+
- Use the translation callback function with dynamic strings if properly escaped with `{}` syntax.
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# Guide: Variable Components Overview
|
|
2
2
|
|
|
3
3
|
Variable components wrap dynamic content like user names, numerical values, dates, and currencies. They format and render dynamic values according to the user's locale without requiring external translations.
|
|
4
4
|
|
|
5
|
+
Variable components can be used as children of `<T>` components or as standalone components.
|
|
6
|
+
When used as children of `<T>` components, the variable components are correctly formatted according to the user's locale.
|
|
7
|
+
|
|
5
8
|
**Import:** The variable components are exported from `gt-next`.
|
|
6
9
|
|
|
7
10
|
```tsx
|
|
@@ -67,7 +70,7 @@ The `<T>` component provides locale context and translates surrounding text whil
|
|
|
67
70
|
|
|
68
71
|
### `<Var>` - Dynamic Content Isolation
|
|
69
72
|
|
|
70
|
-
**Basic Usage:** Always use with `<T>`
|
|
73
|
+
**Basic Usage:** Always use with `<T>` to isolate dynamic content from translation processing.
|
|
71
74
|
|
|
72
75
|
```jsx
|
|
73
76
|
<T>
|
|
@@ -102,6 +105,8 @@ The `<T>` component provides locale context and translates surrounding text whil
|
|
|
102
105
|
<Num>{quantity}</Num>
|
|
103
106
|
```
|
|
104
107
|
|
|
108
|
+
**Rule:** Wrap all dynamic numbers in `<Num>` when using `<T>` components.
|
|
109
|
+
|
|
105
110
|
### `<Currency>` - Currency Formatting
|
|
106
111
|
|
|
107
112
|
**Within `<T>`:** Requires `currency` prop for proper formatting.
|
|
@@ -118,6 +123,8 @@ The `<T>` component provides locale context and translates surrounding text whil
|
|
|
118
123
|
<Currency currency={'USD'}>{total}</Currency>
|
|
119
124
|
```
|
|
120
125
|
|
|
126
|
+
**Rule:** Wrap all dynamic currency values in `<Currency>` when using `<T>` components.
|
|
127
|
+
|
|
121
128
|
### `<DateTime>` - Date/Time Formatting
|
|
122
129
|
|
|
123
130
|
**Within `<T>`:** Automatic locale-aware date formatting.
|
|
@@ -134,28 +141,21 @@ The `<T>` component provides locale context and translates surrounding text whil
|
|
|
134
141
|
<DateTime>{date}</DateTime>
|
|
135
142
|
```
|
|
136
143
|
|
|
144
|
+
**Rule:** Wrap all dynamic date/time values in `<DateTime>` when using `<T>` components.
|
|
145
|
+
|
|
137
146
|
---
|
|
138
147
|
|
|
139
148
|
## Common Implementation Issues
|
|
140
149
|
|
|
141
|
-
### Missing Required Props
|
|
150
|
+
### Missing Required Props
|
|
142
151
|
|
|
143
152
|
**Critical:** `<Currency>` requires `currency` prop for proper symbol and formatting.
|
|
144
153
|
|
|
145
154
|
**Optimization:** All formatting components accept optional props for custom locale behavior.
|
|
146
155
|
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
## Key Principles
|
|
150
|
-
|
|
151
|
-
- **Data Isolation:** Variable components isolate dynamic content from translation processing
|
|
152
|
-
- **Privacy:** No data transmission to General Translation APIs
|
|
153
|
-
- **Flexibility:** Use as child of `<T>` or standalone component
|
|
154
|
-
|
|
155
156
|
## API References
|
|
156
157
|
|
|
157
158
|
- [`<Var>`](/docs/next/api/components/var) - Dynamic content wrapper
|
|
158
159
|
- [`<Num>`](/docs/next/api/components/num) - Number formatting options
|
|
159
160
|
- [`<Currency>`](/docs/next/api/components/currency) - Currency formatting options
|
|
160
161
|
- [`<DateTime>`](/docs/next/api/components/datetime) - Date/time formatting options
|
|
161
|
-
- [Branching Components](/docs/next/guides/branches) - Conditional logic patterns
|
|
@@ -13,25 +13,27 @@
|
|
|
13
13
|
import {
|
|
14
14
|
GTProvider,
|
|
15
15
|
T,
|
|
16
|
-
Tx,
|
|
17
16
|
Var,
|
|
18
17
|
Num,
|
|
19
18
|
Currency,
|
|
20
19
|
DateTime,
|
|
21
20
|
Branch,
|
|
22
21
|
Plural,
|
|
22
|
+
useGT,
|
|
23
|
+
useTranslations,
|
|
24
|
+
LocaleSelector,
|
|
23
25
|
} from 'gt-next';
|
|
24
26
|
|
|
27
|
+
import { useLocale } from 'gt-next/client';
|
|
28
|
+
|
|
25
29
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
LocaleSelector,
|
|
33
|
-
useLocaleSelector,
|
|
34
|
-
} from 'gt-next/client';
|
|
30
|
+
Tx, // Tx is different from tx
|
|
31
|
+
tx,
|
|
32
|
+
getGT,
|
|
33
|
+
getLocale,
|
|
34
|
+
getTranslations,
|
|
35
|
+
} from 'gt-next/server';
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
// Typing
|
|
38
|
+
import { InlineTranslationOptions } from 'gt-next/types';
|
|
37
39
|
```
|
|
@@ -59,8 +59,7 @@ export default function MyComponent() {
|
|
|
59
59
|
**Option B - Hook-based**:
|
|
60
60
|
|
|
61
61
|
```tsx
|
|
62
|
-
|
|
63
|
-
import { useGT } from 'gt-next/client';
|
|
62
|
+
import { useGT } from 'gt-next';
|
|
64
63
|
export default function MyComponent() {
|
|
65
64
|
const t = useGT();
|
|
66
65
|
return <div>{t('Hello, world!')}</div>;
|
|
@@ -73,7 +72,7 @@ export default function MyComponent() {
|
|
|
73
72
|
|
|
74
73
|
### Primary Pattern Preference
|
|
75
74
|
|
|
76
|
-
**Rule**: Prioritize `useGT()` hook
|
|
75
|
+
**Rule**: Prioritize `useGT()` hook and `<T>` component usage whenever possible.
|
|
77
76
|
|
|
78
77
|
**Benefits**:
|
|
79
78
|
|