locadex 0.0.2-alpha.3 → 0.0.2-alpha.5
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/dist/cli.js +4 -4
- package/dist/cli.js.map +1 -1
- package/dist/commands/i18n.d.ts +2 -1
- package/dist/commands/i18n.d.ts.map +1 -1
- package/dist/commands/i18n.js +100 -56
- package/dist/commands/i18n.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +64 -8
- package/dist/commands/setup.js.map +1 -1
- package/dist/logging/console.d.ts +1 -0
- package/dist/logging/console.d.ts.map +1 -1
- package/dist/logging/console.js +6 -3
- package/dist/logging/console.js.map +1 -1
- package/dist/logging/logger.d.ts +20 -0
- package/dist/logging/logger.d.ts.map +1 -1
- package/dist/logging/logger.js +76 -4
- package/dist/logging/logger.js.map +1 -1
- package/dist/mcp/tools/guides.d.ts.map +1 -1
- package/dist/mcp/tools/guides.js +10 -22
- package/dist/mcp/tools/guides.js.map +1 -1
- package/dist/mcp-sse.d.ts.map +1 -1
- package/dist/mcp-sse.js +29 -6
- package/dist/mcp-sse.js.map +1 -1
- package/dist/mcp.js +2 -4
- package/dist/mcp.js.map +1 -1
- package/dist/prompts/system.d.ts.map +1 -1
- package/dist/prompts/system.js +2 -8
- package/dist/prompts/system.js.map +1 -1
- package/dist/utils/agentManager.d.ts +18 -6
- package/dist/utils/agentManager.d.ts.map +1 -1
- package/dist/utils/agentManager.js +27 -14
- package/dist/utils/agentManager.js.map +1 -1
- package/dist/utils/claudeCode.d.ts +3 -3
- package/dist/utils/claudeCode.d.ts.map +1 -1
- package/dist/utils/claudeCode.js +29 -14
- package/dist/utils/claudeCode.js.map +1 -1
- package/dist/utils/dag/createDag.d.ts.map +1 -1
- package/dist/utils/dag/createDag.js +8 -2
- package/dist/utils/dag/createDag.js.map +1 -1
- package/dist/utils/shared.d.ts +2 -0
- package/dist/utils/shared.d.ts.map +1 -1
- package/dist/utils/shared.js +13 -2
- package/dist/utils/shared.js.map +1 -1
- package/dist/utils/stats.d.ts +27 -0
- package/dist/utils/stats.d.ts.map +1 -0
- package/dist/utils/stats.js +44 -0
- package/dist/utils/stats.js.map +1 -0
- package/guides/next/basic/branches.md +40 -12
- package/guides/next/basic/client-side-components.md +30 -23
- package/guides/next/basic/jsx.md +11 -2
- package/guides/next/basic/server-side-components.md +16 -15
- package/guides/next/basic/strings.md +144 -0
- package/guides/next/basic/variables.md +10 -34
- package/package.json +5 -4
- package/dist/logging/constructInfo.d.ts +0 -3
- package/dist/logging/constructInfo.d.ts.map +0 -1
- package/dist/logging/constructInfo.js +0 -15
- package/dist/logging/constructInfo.js.map +0 -1
- package/dist/mcp/tools/fileManager.d.ts +0 -6
- package/dist/mcp/tools/fileManager.d.ts.map +0 -1
- package/dist/mcp/tools/fileManager.js +0 -233
- package/dist/mcp/tools/fileManager.js.map +0 -1
- package/guides/next/basic/locale-selector.md +0 -5
- package/guides/next/basic/setup.md +0 -139
- package/guides/next/basic/translating-html.md +0 -36
|
@@ -41,11 +41,13 @@ Branch components use condition-based prop patterns:
|
|
|
41
41
|
</Plural>
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
### Integration with `<T>` Components
|
|
44
|
+
### Integration with `<T>` Components
|
|
45
45
|
|
|
46
46
|
Branch components require translation context for localized content. Use within `<T>` components for automatic translation:
|
|
47
47
|
|
|
48
48
|
```tsx
|
|
49
|
+
import { T, Branch } from 'gt-next';
|
|
50
|
+
|
|
49
51
|
<T>
|
|
50
52
|
<Branch
|
|
51
53
|
branch={status}
|
|
@@ -54,18 +56,20 @@ Branch components require translation context for localized content. Use within
|
|
|
54
56
|
>
|
|
55
57
|
Status unknown
|
|
56
58
|
</Branch>
|
|
57
|
-
</T
|
|
59
|
+
</T>;
|
|
58
60
|
```
|
|
59
61
|
|
|
60
62
|
The `<T>` component provides translation context and localizes branch content.
|
|
61
63
|
|
|
62
|
-
### Pluralization Behavior
|
|
64
|
+
### Pluralization Behavior
|
|
63
65
|
|
|
64
66
|
**Automatic Rule Selection:** `<Plural>` uses Unicode CLDR rules to determine correct plural form based on `n` value and current locale.
|
|
65
67
|
|
|
66
68
|
**Customization:** Override default plural forms with specific CLDR categories:
|
|
67
69
|
|
|
68
70
|
```tsx
|
|
71
|
+
import { Plural } from 'gt-next';
|
|
72
|
+
|
|
69
73
|
<Plural
|
|
70
74
|
n={count}
|
|
71
75
|
zero={<>No items</>}
|
|
@@ -78,7 +82,7 @@ The `<T>` component provides translation context and localizes branch content.
|
|
|
78
82
|
// OR simplified
|
|
79
83
|
singular={<>One item</>}
|
|
80
84
|
plural={<>Multiple items</>}
|
|
81
|
-
|
|
85
|
+
/>;
|
|
82
86
|
```
|
|
83
87
|
|
|
84
88
|
**Available Forms:** zero, one, two, few, many, other, dual (locale-dependent), plus simplified singular/plural.
|
|
@@ -87,7 +91,7 @@ The `<T>` component provides translation context and localizes branch content.
|
|
|
87
91
|
|
|
88
92
|
## Implementation Examples
|
|
89
93
|
|
|
90
|
-
### `<Branch>` - Conditional Logic Replacement
|
|
94
|
+
### `<Branch>` - Conditional Logic Replacement
|
|
91
95
|
|
|
92
96
|
**Replacing Ternary Operators:** Convert inline conditional logic to declarative branch syntax.
|
|
93
97
|
|
|
@@ -102,15 +106,39 @@ The `<T>` component provides translation context and localizes branch content.
|
|
|
102
106
|
For example, if isActive is a boolean, convert it to a string first.
|
|
103
107
|
|
|
104
108
|
**Replacing Conditional Rendering:** Convert `&&` operator patterns to branch syntax.
|
|
109
|
+
This is only applicable if the content is being used in a `<T>` component.
|
|
110
|
+
|
|
111
|
+
**Invalid Syntax**:
|
|
105
112
|
|
|
106
113
|
```tsx
|
|
107
|
-
|
|
108
|
-
<Branch branch={isActive} true={<p>Active</p>}>
|
|
109
|
-
<></>
|
|
110
|
-
</Branch>
|
|
114
|
+
<T>{isActive && <p>Active</p>}</T>
|
|
111
115
|
```
|
|
112
116
|
|
|
113
|
-
|
|
117
|
+
**Valid Syntax**:
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
<T>
|
|
121
|
+
<Branch branch={isActive} true={<p>Active</p>}>
|
|
122
|
+
<></>
|
|
123
|
+
</Branch>
|
|
124
|
+
</T>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Alternative Valid Syntax**:
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
{
|
|
131
|
+
isActive && (
|
|
132
|
+
<T>
|
|
133
|
+
<p>Active</p>
|
|
134
|
+
</T>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
In this case, the `<T>` component is not wrapping the conditional, so the branch component is not needed.
|
|
140
|
+
|
|
141
|
+
### `<Plural>` - Number-Based Rendering
|
|
114
142
|
|
|
115
143
|
**Basic Pluralization:** Replace manual plural logic with locale-aware components.
|
|
116
144
|
|
|
@@ -227,7 +255,7 @@ import { T, Plural, Num } from 'gt-next';
|
|
|
227
255
|
|
|
228
256
|
## Common Implementation Issues
|
|
229
257
|
|
|
230
|
-
### Missing Branch Values
|
|
258
|
+
### Missing Branch Values
|
|
231
259
|
|
|
232
260
|
**Critical:** Unmatched branch values fall back to children content. Ensure branch prop values match defined keys.
|
|
233
261
|
|
|
@@ -243,7 +271,7 @@ import { T, Plural, Num } from 'gt-next';
|
|
|
243
271
|
|
|
244
272
|
**Rule:** Always provide fallback children for robust error handling.
|
|
245
273
|
|
|
246
|
-
### Missing Plural Forms
|
|
274
|
+
### Missing Plural Forms
|
|
247
275
|
|
|
248
276
|
**Critical:** Provide required plural forms for your default locale to ensure fallback content availability.
|
|
249
277
|
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
# Client-Side Component Internationalization
|
|
1
|
+
# Client-Side Component Internationalization Guide
|
|
2
|
+
|
|
3
|
+
RULES:
|
|
4
|
+
|
|
5
|
+
- NEVER INTERNATIONALIZE ERROR STRINGS OR OTHER FUNCTIONAL STRINGS
|
|
6
|
+
- Always use `<T>` for HTML/JSX content
|
|
7
|
+
- Always add `'use client'` when working with `useGT()` and `useDict()`
|
|
2
8
|
|
|
3
9
|
## Available Methods
|
|
4
10
|
|
|
5
11
|
Three methods exist for internationalizing client-side components:
|
|
6
12
|
|
|
7
|
-
- `<T>` component (syntax identical to server-side) (
|
|
8
|
-
- `useGT()` hook (client-side specific) (string
|
|
9
|
-
- `useDict()` hook (client-side specific) (string
|
|
13
|
+
- `<T>` component (syntax identical to server-side) (For HTML/JSX content)
|
|
14
|
+
- `useGT()` hook (client-side specific) (For string content)
|
|
15
|
+
- `useDict()` hook (client-side specific) (For string content)
|
|
10
16
|
|
|
11
|
-
**
|
|
17
|
+
**Imports:** The `useGT()` and `useDict()` hooks are exported from `gt-next/client`.
|
|
12
18
|
|
|
13
19
|
```tsx
|
|
14
20
|
import { useGT } from 'gt-next/client';
|
|
@@ -20,9 +26,12 @@ The `<T>` component is exported from `gt-next`.
|
|
|
20
26
|
import { T } from 'gt-next';
|
|
21
27
|
```
|
|
22
28
|
|
|
23
|
-
##
|
|
29
|
+
## RULES
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
- If a component is explicitly marked as async, this guide does NOT apply.
|
|
32
|
+
- You should refer to the server-side guide instead.
|
|
33
|
+
- If you decided to use `useGT()` or `useDict()`, the file MUST have the "use client" directive at the top of the file.
|
|
34
|
+
- If it does not, you must add it.
|
|
26
35
|
|
|
27
36
|
## useGT() Hook
|
|
28
37
|
|
|
@@ -43,6 +52,7 @@ export default function Example() {
|
|
|
43
52
|
**After internationalization:**
|
|
44
53
|
|
|
45
54
|
```jsx
|
|
55
|
+
'use client'; // Must always add this directive when adding the useGT hook
|
|
46
56
|
import { useGT } from 'gt-next/client';
|
|
47
57
|
export default function Example() {
|
|
48
58
|
const t = useGT();
|
|
@@ -53,7 +63,7 @@ export default function Example() {
|
|
|
53
63
|
|
|
54
64
|
### Important: T Component as Props
|
|
55
65
|
|
|
56
|
-
**NEVER pass `<T>` components as props to non
|
|
66
|
+
**NEVER pass `<T>` components as props to non gt-next components** - this will cause rendering errors.
|
|
57
67
|
|
|
58
68
|
**Before internationalization:**
|
|
59
69
|
|
|
@@ -64,7 +74,7 @@ import { Dialog } from '@/primitives/Dialog';
|
|
|
64
74
|
export default function Example() {
|
|
65
75
|
return (
|
|
66
76
|
<Dialog
|
|
67
|
-
title={<T>Delete document</T>}
|
|
77
|
+
title={<T>Delete document</T>} // This will break!
|
|
68
78
|
/>
|
|
69
79
|
);
|
|
70
80
|
}
|
|
@@ -73,6 +83,7 @@ export default function Example() {
|
|
|
73
83
|
**After internationalization:**
|
|
74
84
|
|
|
75
85
|
```jsx
|
|
86
|
+
'use client'; // Must always add this directive when adding the useGT hook
|
|
76
87
|
import { useGT } from 'gt-next/client';
|
|
77
88
|
import { Dialog } from '@/primitives/Dialog';
|
|
78
89
|
|
|
@@ -80,15 +91,15 @@ export default function Example() {
|
|
|
80
91
|
const t = useGT();
|
|
81
92
|
return (
|
|
82
93
|
<Dialog
|
|
83
|
-
title={t('Delete document')}
|
|
94
|
+
title={t('Delete document')} // Use string for props
|
|
84
95
|
>
|
|
85
|
-
<T>This content works fine</T>
|
|
96
|
+
<T>This content works fine</T> {/* T component in JSX content is OK */}
|
|
86
97
|
</Dialog>
|
|
87
98
|
);
|
|
88
99
|
}
|
|
89
100
|
```
|
|
90
101
|
|
|
91
|
-
**Rule**: Use `useGT()` for
|
|
102
|
+
**Rule**: Use `useGT()` for strings, `<T>` only for JSX content.
|
|
92
103
|
|
|
93
104
|
### Reusable Content Pattern
|
|
94
105
|
|
|
@@ -103,7 +114,7 @@ export const content = 'hi';
|
|
|
103
114
|
// Example 2
|
|
104
115
|
export const nestedContent = {
|
|
105
116
|
name: 'Brian',
|
|
106
|
-
|
|
117
|
+
description: 'Brian is an engineer',
|
|
107
118
|
};
|
|
108
119
|
```
|
|
109
120
|
|
|
@@ -123,7 +134,7 @@ export const useNestedContent = () => {
|
|
|
123
134
|
const t = useGT();
|
|
124
135
|
return {
|
|
125
136
|
name: 'Brian',
|
|
126
|
-
|
|
137
|
+
description: t('Brian is an engineer'),
|
|
127
138
|
};
|
|
128
139
|
};
|
|
129
140
|
```
|
|
@@ -166,12 +177,9 @@ export default function NotificationComponent() {
|
|
|
166
177
|
|
|
167
178
|
```json
|
|
168
179
|
{
|
|
169
|
-
"
|
|
170
|
-
|
|
171
|
-
"
|
|
172
|
-
"name": "User Name",
|
|
173
|
-
"title": "Job Title"
|
|
174
|
-
}
|
|
180
|
+
"home": {
|
|
181
|
+
"name": "Home",
|
|
182
|
+
"description": "Home is a place where you live"
|
|
175
183
|
}
|
|
176
184
|
}
|
|
177
185
|
```
|
|
@@ -185,9 +193,8 @@ export default function MyComponent() {
|
|
|
185
193
|
const t = useDict();
|
|
186
194
|
return (
|
|
187
195
|
<>
|
|
188
|
-
<div>{t('
|
|
189
|
-
<div>{t('
|
|
190
|
-
<div>{t('user.profile.title')}</div>
|
|
196
|
+
<div>{t('home.name')}</div>
|
|
197
|
+
<div>{t('home.description')}</div>
|
|
191
198
|
</>
|
|
192
199
|
);
|
|
193
200
|
}
|
package/guides/next/basic/jsx.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Use the `<T>` component to internationalize HTML and JSX content.
|
|
4
4
|
|
|
5
|
+
**Import:** The `<T>` component is exported from `gt-next`.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { T } from 'gt-next';
|
|
9
|
+
```
|
|
10
|
+
|
|
5
11
|
Before:
|
|
6
12
|
|
|
7
13
|
```jsx
|
|
@@ -34,7 +40,10 @@ Add `context` prop when content meaning is ambiguous:
|
|
|
34
40
|
</T>
|
|
35
41
|
```
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
RULES:
|
|
44
|
+
|
|
45
|
+
- Provide context for words with multiple meanings (e.g., "toast" = bread vs notification).
|
|
46
|
+
- Provide context when the additional context can help the translator understand the meaning of the content.
|
|
38
47
|
|
|
39
48
|
# Usage Rules
|
|
40
49
|
|
|
@@ -139,7 +148,7 @@ Solution: Wrap dynamic content in variable components or branching components, t
|
|
|
139
148
|
</T>
|
|
140
149
|
```
|
|
141
150
|
|
|
142
|
-
|
|
151
|
+
NOTE: `<T>` handles any nested content within the same component.
|
|
143
152
|
|
|
144
153
|
# Common Pitfalls
|
|
145
154
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# Server-Side Component Internationalization
|
|
1
|
+
# Server-Side Component Internationalization Guide
|
|
2
2
|
|
|
3
3
|
## Available Methods
|
|
4
4
|
|
|
5
5
|
Three methods exist for internationalizing server-side components:
|
|
6
6
|
|
|
7
|
-
- `<T>` component (syntax identical to client-side) (
|
|
8
|
-
- `getGT()` function (server-side specific) (string
|
|
9
|
-
- `getDict()` function (server-side specific) (string
|
|
7
|
+
- `<T>` component (syntax identical to client-side) (For HTML/JSX content)
|
|
8
|
+
- `getGT()` function (server-side specific) (For string content)
|
|
9
|
+
- `getDict()` function (server-side specific) (For string content)
|
|
10
10
|
|
|
11
|
-
**
|
|
11
|
+
**Imports:** The `getGT()` and `getDict()` functions are exported from `gt-next/server`.
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
14
|
import { getGT } from 'gt-next/server';
|
|
@@ -20,9 +20,12 @@ The `<T>` component is exported from `gt-next`.
|
|
|
20
20
|
import { T } from 'gt-next';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## RULES
|
|
24
24
|
|
|
25
|
-
NEVER add
|
|
25
|
+
- NEVER add "use server" to server-side components.
|
|
26
|
+
- This guide only applies to async server-side components.
|
|
27
|
+
- If a component is not explicitly marked as async, this guide does NOT apply.
|
|
28
|
+
- You should refer to the client-side guide instead.
|
|
26
29
|
|
|
27
30
|
## getGT() Function
|
|
28
31
|
|
|
@@ -65,7 +68,7 @@ export const content = 'hi';
|
|
|
65
68
|
// Example 2
|
|
66
69
|
export const nestedContent = {
|
|
67
70
|
name: 'Brian',
|
|
68
|
-
|
|
71
|
+
description: 'Brian is an engineer',
|
|
69
72
|
};
|
|
70
73
|
```
|
|
71
74
|
|
|
@@ -85,7 +88,7 @@ export const useNestedContent = async () => {
|
|
|
85
88
|
const t = await getGT();
|
|
86
89
|
return {
|
|
87
90
|
name: 'Brian',
|
|
88
|
-
|
|
91
|
+
description: t('Brian is an engineer'),
|
|
89
92
|
};
|
|
90
93
|
};
|
|
91
94
|
```
|
|
@@ -124,11 +127,9 @@ export default async function NotificationComponent() {
|
|
|
124
127
|
|
|
125
128
|
```json
|
|
126
129
|
{
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
"title": "Job Title"
|
|
131
|
-
}
|
|
130
|
+
"home": {
|
|
131
|
+
"name": "Home",
|
|
132
|
+
"description": "Home is a place where you live"
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
```
|
|
@@ -139,7 +140,7 @@ export default async function NotificationComponent() {
|
|
|
139
140
|
import { getDict } from 'gt-next/server';
|
|
140
141
|
export default async function MyComponent() {
|
|
141
142
|
const t = await getDict();
|
|
142
|
-
return t('
|
|
143
|
+
return t('home.description');
|
|
143
144
|
}
|
|
144
145
|
```
|
|
145
146
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# How to internationalize strings with `gt-next`
|
|
2
|
+
|
|
3
|
+
Use `useGT()` and `getGT()` to internationalize strings.
|
|
4
|
+
|
|
5
|
+
**RULES:**
|
|
6
|
+
|
|
7
|
+
- For JSX and HTML content, ALWAYS use the `<T>` component over `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. Read the "basic_next-branches" for instructions.
|
|
9
|
+
- NEVER internationalize functional strings (error strings, logical strings, etc.) that could jeporadize the functionality of the application.
|
|
10
|
+
|
|
11
|
+
**Import:** The `useGT()` and `getGT()` functions are exported from `gt-next/client` and `gt-next/server` respectively.
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { useGT } from 'gt-next/client';
|
|
15
|
+
import { getGT } from 'gt-next/server';
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Both `useGT()` and `getGT()` return a translation function callback.
|
|
21
|
+
Pass the string to the callback function to get the translated string.
|
|
22
|
+
|
|
23
|
+
The usage of the callback is the same for both `useGT()` and `getGT()`.
|
|
24
|
+
|
|
25
|
+
`getGT()` is asynchronous and returns a promise that resolves to the translation function callback.
|
|
26
|
+
|
|
27
|
+
Before:
|
|
28
|
+
|
|
29
|
+
```jsx
|
|
30
|
+
function Greeting() {
|
|
31
|
+
const greeting = 'Hello, world!';
|
|
32
|
+
return greeting;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
After:
|
|
37
|
+
|
|
38
|
+
```jsx
|
|
39
|
+
'use client';
|
|
40
|
+
import { useGT } from 'gt-next/client';
|
|
41
|
+
|
|
42
|
+
function Greeting() {
|
|
43
|
+
const t = useGT();
|
|
44
|
+
const greeting = t('Hello, world!');
|
|
45
|
+
return greeting;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Server Side
|
|
50
|
+
|
|
51
|
+
Before:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
export async function Greeting() {
|
|
55
|
+
const greeting = t('Hello, world!');
|
|
56
|
+
return greeting;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
After:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { getGT } from 'gt-next/server';
|
|
64
|
+
|
|
65
|
+
export async function Greeting() {
|
|
66
|
+
const t = await getGT();
|
|
67
|
+
const greeting = t('Hello, world!');
|
|
68
|
+
return greeting;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
# Context Prop
|
|
73
|
+
|
|
74
|
+
Add `context` when content meaning is ambiguous:
|
|
75
|
+
|
|
76
|
+
```jsx
|
|
77
|
+
'use client';
|
|
78
|
+
import { useGT } from 'gt-next/client';
|
|
79
|
+
|
|
80
|
+
function Greeting() {
|
|
81
|
+
const t = useGT();
|
|
82
|
+
const toast = t('Click on the toast to dismiss it.', {
|
|
83
|
+
context: 'toast, as in a pop-up notification',
|
|
84
|
+
});
|
|
85
|
+
return toast;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
RULES:
|
|
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.
|
|
93
|
+
|
|
94
|
+
# Usage Rules
|
|
95
|
+
|
|
96
|
+
**USE `useGT()` and `getGT()` for:**
|
|
97
|
+
|
|
98
|
+
- Static strings
|
|
99
|
+
- Dynamic strings if escaped with `{}` syntax
|
|
100
|
+
|
|
101
|
+
# Valid Usage Examples
|
|
102
|
+
|
|
103
|
+
In the following examples, `t` is the translation function callback.
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
const greeting = t('Hello, world!');
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
const greeting = t('Hello, {name}!', { variables: { name: 'John' } });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
const message = t('You have {dollars} dollars!', {
|
|
115
|
+
variables: { dollars: 123 },
|
|
116
|
+
variableOptions: { dollars: { style: 'currency', currency: 'USD' } },
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`variables` is an object that maps variable names to their values.
|
|
121
|
+
|
|
122
|
+
`variableOptions` is an object that maps variable names to their options.
|
|
123
|
+
|
|
124
|
+
The options are the same as the options for the Intl.NumberFormat and Intl.DateTimeFormat APIs.
|
|
125
|
+
|
|
126
|
+
# Invalid Usage Examples
|
|
127
|
+
|
|
128
|
+
Never use the `${}` syntax for dynamic strings inside the translation callback.
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
const invalidUsage = t(`Hello, ${name}!`);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Never use double curly braces `{{}}` to indicate variables
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
const invalidUsage = t(`Hello, {{name}}!`);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Always add the `variable` key in the options field of `t()` when specifying variables. The following is invalid:
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
const invalidUsage = t(`Hello, {name}!`, { name: 'Brian' });
|
|
144
|
+
```
|
|
@@ -15,16 +15,6 @@ import { Var, Num, Currency, DateTime } from 'gt-next';
|
|
|
15
15
|
- `<Currency>`: Formats currency with symbols and localization
|
|
16
16
|
- `<DateTime>`: Formats dates/times with locale conventions
|
|
17
17
|
|
|
18
|
-
**Processing Model:**
|
|
19
|
-
|
|
20
|
-
- JSX content → General Translation API for translation
|
|
21
|
-
- Variable components → Local formatting only (never sent to API)
|
|
22
|
-
- `<Num>`, `<Currency>`, `<DateTime>` → Use JS Intl API for locale formatting
|
|
23
|
-
|
|
24
|
-
**Important:** Content wrapped in variable components is never sent to the General Translation API, ensuring data privacy and security.
|
|
25
|
-
|
|
26
|
-
See the section on [Data Privacy](#privacy) for more information.
|
|
27
|
-
|
|
28
18
|
---
|
|
29
19
|
|
|
30
20
|
## Usage Patterns
|
|
@@ -34,13 +24,15 @@ See the section on [Data Privacy](#privacy) for more information.
|
|
|
34
24
|
All variable components use identical wrapping syntax:
|
|
35
25
|
|
|
36
26
|
```tsx
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<
|
|
40
|
-
<
|
|
27
|
+
import { Var, Num, Currency, DateTime } from 'gt-next';
|
|
28
|
+
|
|
29
|
+
<Var>{user.name}</Var>;
|
|
30
|
+
<Num>{user.age}</Num>;
|
|
31
|
+
<Currency>{user.balance}</Currency>;
|
|
32
|
+
<DateTime>{user.birthday}</DateTime>;
|
|
41
33
|
```
|
|
42
34
|
|
|
43
|
-
### Integration with `<T>` Components
|
|
35
|
+
### Integration with `<T>` Components
|
|
44
36
|
|
|
45
37
|
Variable components require locale context for formatting. Use within `<T>` components for automatic locale handling:
|
|
46
38
|
|
|
@@ -52,7 +44,7 @@ Variable components require locale context for formatting. Use within `<T>` comp
|
|
|
52
44
|
|
|
53
45
|
The `<T>` component provides locale context and translates surrounding text while preserving variable formatting.
|
|
54
46
|
|
|
55
|
-
### Localization Behavior
|
|
47
|
+
### Localization Behavior
|
|
56
48
|
|
|
57
49
|
**Automatic Formatting:**
|
|
58
50
|
|
|
@@ -62,29 +54,13 @@ The `<T>` component provides locale context and translates surrounding text whil
|
|
|
62
54
|
|
|
63
55
|
**Customization:** Override default locale and formatting via component props.
|
|
64
56
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
**Security Model:** Variable components process content locally and never send data to General Translation APIs.
|
|
57
|
+
## Use Cases by Component
|
|
68
58
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
- `<Var>`: Unformatted private data (user names, account numbers)
|
|
59
|
+
- `<Var>`: Unformatted private data (user names, account numbers), or conditional content that should be excluded from translation
|
|
72
60
|
- `<Num>`: Private numbers needing locale formatting (quantities, ages, distances)
|
|
73
61
|
- `<Currency>`: Private currency values (transactions, balances)
|
|
74
62
|
- `<DateTime>`: Private dates/times (timestamps, creation dates)
|
|
75
63
|
|
|
76
|
-
**Warning - API Data Transmission Rules:**
|
|
77
|
-
- [Branching Components](/docs/next/guides/branches) and [`<T>` components](/docs/next/guides/jsx) → Sent to API
|
|
78
|
-
- `<T>` nested inside `<Var>` → Sent to API
|
|
79
|
-
|
|
80
|
-
```tsx
|
|
81
|
-
<T>
|
|
82
|
-
<Var>
|
|
83
|
-
<T>Hello, World!</T> // → API Goodbye, World! // → Local only
|
|
84
|
-
</Var>
|
|
85
|
-
</T>
|
|
86
|
-
```
|
|
87
|
-
|
|
88
64
|
---
|
|
89
65
|
|
|
90
66
|
## Implementation Examples
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locadex",
|
|
3
|
-
"version": "0.0.2-alpha.
|
|
3
|
+
"version": "0.0.2-alpha.5",
|
|
4
4
|
"description": "An AI agent for internationalization",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"locadex": "dist/cli.js",
|
|
9
|
-
"locadex-mcp": "dist/mcp.js"
|
|
9
|
+
"locadex-mcp": "dist/mcp.js",
|
|
10
|
+
"locadex-mcp-sse": "dist/mcp-sse.js"
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
12
13
|
"dist",
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
"guides"
|
|
17
18
|
],
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@anthropic-ai/claude-code": "^1.0.
|
|
20
|
+
"@anthropic-ai/claude-code": "^1.0.16",
|
|
20
21
|
"@anthropic-ai/sdk": "^0.52.0",
|
|
21
22
|
"@clack/prompts": "^1.0.0-alpha.1",
|
|
22
23
|
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"release:latest": "npm run build:release && npm publish --access public --tag latest",
|
|
59
60
|
"test": "vitest run",
|
|
60
61
|
"test:watch": "vitest",
|
|
61
|
-
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org general-translation --project locadex ./dist && sentry-cli sourcemaps upload --org general-translation --project locadex ./dist"
|
|
62
|
+
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org general-translation --project locadex ./dist && sentry-cli sourcemaps upload --org general-translation --project locadex ./dist --release=${npm_package_version}"
|
|
62
63
|
},
|
|
63
64
|
"repository": {
|
|
64
65
|
"type": "git",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constructInfo.d.ts","sourceRoot":"/","sources":["logging/constructInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,UAc3D"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="82a0b27e-2354-5b05-88ad-9a8482391e79")}catch(e){}}();
|
|
3
|
-
export function constructResultInfo(result) {
|
|
4
|
-
if (result.type === 'result') {
|
|
5
|
-
if (result.subtype === 'success') {
|
|
6
|
-
return `Done!\nCost: $${Number(result.cost_usd).toFixed(2)}\nDuration: ${Number(result.duration_ms) / 1000}s`;
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
return `Error: ${result.subtype}\nCost: $${result.cost_usd}\nDuration: ${Number(result.duration_ms) / 1000}s`;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return '';
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=constructInfo.js.map
|
|
15
|
-
//# debugId=82a0b27e-2354-5b05-88ad-9a8482391e79
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constructInfo.js","sources":["logging/constructInfo.ts"],"sourceRoot":"/","sourcesContent":["import { ClaudeSDKMessage } from '../types/claude-sdk.js';\n\nexport function constructResultInfo(result: ClaudeSDKMessage) {\n if (result.type === 'result') {\n if (result.subtype === 'success') {\n return `Done!\\nCost: $${Number(result.cost_usd).toFixed(2)}\\nDuration: ${\n Number(result.duration_ms) / 1000\n }s`;\n } else {\n return `Error: ${result.subtype}\\nCost: $${result.cost_usd}\\nDuration: ${\n Number(result.duration_ms) / 1000\n }s`;\n }\n }\n\n return '';\n}\n"],"names":[],"mappings":";;AAEA,MAAM,UAAU,mBAAmB,CAAC,MAAwB;IAC1D,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,iBAAiB,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,eACxD,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,IAC/B,GAAG,CAAC;QACN,CAAC;aAAM,CAAC;YACN,OAAO,UAAU,MAAM,CAAC,OAAO,YAAY,MAAM,CAAC,QAAQ,eACxD,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,IAC/B,GAAG,CAAC;QACN,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC","debug_id":"82a0b27e-2354-5b05-88ad-9a8482391e79"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
export declare const fileManagerTools: {
|
|
3
|
-
[id: string]: string;
|
|
4
|
-
};
|
|
5
|
-
export declare function addFileManagerTools(server: McpServer, stateFilePath: string): void;
|
|
6
|
-
//# sourceMappingURL=fileManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fileManager.d.ts","sourceRoot":"/","sources":["mcp/tools/fileManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE,eAAO,MAAM,gBAAgB,EAAE;IAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CAYpD,CAAC;AAqCF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,QA6O3E"}
|