@contractspec/bundle.library 3.9.8 → 3.9.9
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/.turbo/turbo-build.log +222 -214
- package/CHANGELOG.md +52 -0
- package/dist/components/docs/DocsIndexPage.js +2 -2
- package/dist/components/docs/docsManifest.js +1 -1
- package/dist/components/docs/getting-started/DataViewTutorialPage.js +81 -6
- package/dist/components/docs/getting-started/index.js +94 -19
- package/dist/components/docs/guides/GuideDataExchangeImportTemplatesPage.content.d.ts +6 -0
- package/dist/components/docs/guides/GuideDataExchangeImportTemplatesPage.content.js +176 -0
- package/dist/components/docs/guides/GuideDataExchangeImportTemplatesPage.d.ts +1 -0
- package/dist/components/docs/guides/GuideDataExchangeImportTemplatesPage.js +176 -0
- package/dist/components/docs/guides/GuidesIndexPage.js +2 -2
- package/dist/components/docs/guides/index.d.ts +1 -0
- package/dist/components/docs/guides/index.js +220 -46
- package/dist/components/docs/index.js +1003 -309
- package/dist/components/docs/libraries/LibrariesApplicationShellPage.content.d.ts +22 -5
- package/dist/components/docs/libraries/LibrariesApplicationShellPage.content.js +125 -37
- package/dist/components/docs/libraries/LibrariesApplicationShellPage.js +125 -37
- package/dist/components/docs/libraries/LibrariesDataViewsPage.js +120 -3
- package/dist/components/docs/libraries/LibrariesDesignSystemPage.js +101 -2
- package/dist/components/docs/libraries/LibrariesOverviewPage.js +1 -1
- package/dist/components/docs/libraries/LibrariesPersonalizationPage.js +58 -4
- package/dist/components/docs/libraries/LibrariesTranslationRuntimePage.content.d.ts +10 -0
- package/dist/components/docs/libraries/LibrariesTranslationRuntimePage.content.js +43 -0
- package/dist/components/docs/libraries/LibrariesTranslationRuntimePage.d.ts +1 -0
- package/dist/components/docs/libraries/LibrariesTranslationRuntimePage.js +43 -0
- package/dist/components/docs/libraries/index.d.ts +1 -0
- package/dist/components/docs/libraries/index.js +496 -97
- package/dist/components/docs/specs/SpecsDataViewsPage.js +49 -3
- package/dist/components/docs/specs/index.js +60 -14
- package/dist/index.js +1014 -320
- package/dist/node/components/docs/DocsIndexPage.js +2 -2
- package/dist/node/components/docs/docsManifest.js +1 -1
- package/dist/node/components/docs/getting-started/DataViewTutorialPage.js +81 -6
- package/dist/node/components/docs/getting-started/index.js +94 -19
- package/dist/node/components/docs/guides/GuideDataExchangeImportTemplatesPage.content.js +175 -0
- package/dist/node/components/docs/guides/GuideDataExchangeImportTemplatesPage.js +175 -0
- package/dist/node/components/docs/guides/GuidesIndexPage.js +2 -2
- package/dist/node/components/docs/guides/index.js +220 -46
- package/dist/node/components/docs/index.js +1003 -309
- package/dist/node/components/docs/libraries/LibrariesApplicationShellPage.content.js +125 -37
- package/dist/node/components/docs/libraries/LibrariesApplicationShellPage.js +125 -37
- package/dist/node/components/docs/libraries/LibrariesDataViewsPage.js +120 -3
- package/dist/node/components/docs/libraries/LibrariesDesignSystemPage.js +101 -2
- package/dist/node/components/docs/libraries/LibrariesOverviewPage.js +1 -1
- package/dist/node/components/docs/libraries/LibrariesPersonalizationPage.js +58 -4
- package/dist/node/components/docs/libraries/LibrariesTranslationRuntimePage.content.js +42 -0
- package/dist/node/components/docs/libraries/LibrariesTranslationRuntimePage.js +42 -0
- package/dist/node/components/docs/libraries/index.js +496 -97
- package/dist/node/components/docs/specs/SpecsDataViewsPage.js +49 -3
- package/dist/node/components/docs/specs/index.js +60 -14
- package/dist/node/index.js +1014 -320
- package/package.json +74 -26
- package/src/components/docs/docsManifest.test.ts +87 -0
- package/src/components/docs/docsManifest.ts +90 -3
- package/src/components/docs/generated/docs-index.notifications.json +7 -7
- package/src/components/docs/getting-started/DataViewTutorialPage.tsx +181 -50
- package/src/components/docs/guides/GuideDataExchangeImportTemplatesPage.content.ts +185 -0
- package/src/components/docs/guides/GuideDataExchangeImportTemplatesPage.tsx +186 -0
- package/src/components/docs/guides/GuidesIndexPage.tsx +49 -42
- package/src/components/docs/guides/index.ts +1 -0
- package/src/components/docs/libraries/LibrariesApplicationShellPage.content.ts +148 -35
- package/src/components/docs/libraries/LibrariesApplicationShellPage.tsx +38 -5
- package/src/components/docs/libraries/LibrariesDataViewsPage.tsx +267 -64
- package/src/components/docs/libraries/LibrariesDesignSystemPage.tsx +235 -0
- package/src/components/docs/libraries/LibrariesOverviewPage.tsx +8 -2
- package/src/components/docs/libraries/LibrariesPersonalizationPage.tsx +141 -31
- package/src/components/docs/libraries/LibrariesTranslationRuntimePage.content.ts +78 -0
- package/src/components/docs/libraries/LibrariesTranslationRuntimePage.tsx +137 -0
- package/src/components/docs/libraries/index.ts +1 -0
- package/src/components/docs/specs/SpecsDataViewsPage.tsx +239 -113
|
@@ -1,31 +1,93 @@
|
|
|
1
1
|
import { CodeBlock, InstallCommand } from '@contractspec/lib.design-system';
|
|
2
|
+
import { HStack, VStack } from '@contractspec/lib.design-system/layout';
|
|
3
|
+
import {
|
|
4
|
+
Code,
|
|
5
|
+
H1,
|
|
6
|
+
H2,
|
|
7
|
+
P,
|
|
8
|
+
Text,
|
|
9
|
+
} from '@contractspec/lib.design-system/typography';
|
|
2
10
|
import Link from '@contractspec/lib.ui-link';
|
|
3
11
|
import { ChevronRight } from 'lucide-react';
|
|
4
12
|
|
|
13
|
+
const DATA_VIEW_PREFERENCE_EXAMPLE = `import { DataViewRenderer } from '@contractspec/lib.design-system';
|
|
14
|
+
import { resolveDataViewPreferences } from '@contractspec/lib.personalization/data-view-preferences';
|
|
15
|
+
|
|
16
|
+
const resolved = resolveDataViewPreferences({
|
|
17
|
+
spec: AccountsDataView,
|
|
18
|
+
preferences: profile.canonical,
|
|
19
|
+
insights,
|
|
20
|
+
record: savedAccountViewPreference,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<DataViewRenderer
|
|
25
|
+
spec={AccountsDataView}
|
|
26
|
+
items={accounts}
|
|
27
|
+
defaultViewMode={resolved.viewMode}
|
|
28
|
+
defaultDensity={resolved.density}
|
|
29
|
+
defaultDataDepth={resolved.dataDepth}
|
|
30
|
+
pagination={{
|
|
31
|
+
page,
|
|
32
|
+
pageSize: resolved.pageSize ?? 25,
|
|
33
|
+
total,
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
);`;
|
|
37
|
+
|
|
38
|
+
const DATA_VIEW_TRACKING_EXAMPLE = `tracker.trackDataViewInteraction({
|
|
39
|
+
dataViewKey: AccountsDataView.meta.key,
|
|
40
|
+
dataViewVersion: AccountsDataView.meta.version,
|
|
41
|
+
action: 'view_mode_changed',
|
|
42
|
+
viewMode: 'grid',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
tracker.trackDataViewInteraction({
|
|
46
|
+
dataViewKey: AccountsDataView.meta.key,
|
|
47
|
+
action: 'data_depth_changed',
|
|
48
|
+
dataDepth: 'detailed',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
tracker.trackDataViewInteraction({
|
|
52
|
+
dataViewKey: AccountsDataView.meta.key,
|
|
53
|
+
action: 'filter_changed',
|
|
54
|
+
filterKey: 'status',
|
|
55
|
+
});`;
|
|
56
|
+
|
|
57
|
+
const DATA_VIEW_PERSONALIZATION_PROMPT = `Add DataView personalization for <screen>.
|
|
58
|
+
|
|
59
|
+
Acceptance criteria:
|
|
60
|
+
- Resolve viewMode, density, dataDepth, and pageSize with resolveDataViewPreferences.
|
|
61
|
+
- Apply resolved values to DataViewRenderer as default or controlled props.
|
|
62
|
+
- Track opened, view_mode_changed, density_changed, data_depth_changed, search_changed, filter_changed, sort_changed, and page_changed actions with trackDataViewInteraction.
|
|
63
|
+
- Persist only the dimensions allowed by view.collection.personalization.persist.
|
|
64
|
+
- Ignore behavior-derived modes that are not allowed by view.collection.viewModes.allowedModes.
|
|
65
|
+
- Do not import React or design-system code into @contractspec/lib.personalization helpers.`;
|
|
66
|
+
|
|
5
67
|
export function LibrariesPersonalizationPage() {
|
|
6
68
|
return (
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
<
|
|
69
|
+
<VStack className="space-y-8">
|
|
70
|
+
<VStack className="space-y-4">
|
|
71
|
+
<H1 className="font-bold text-4xl">
|
|
10
72
|
@contractspec/lib.personalization
|
|
11
|
-
</
|
|
12
|
-
<
|
|
73
|
+
</H1>
|
|
74
|
+
<P className="text-lg text-muted-foreground">
|
|
13
75
|
Track field/feature/workflow usage, analyze drop-offs, and convert
|
|
14
76
|
insights into OverlaySpecs or workflow tweaks.
|
|
15
|
-
</
|
|
16
|
-
</
|
|
77
|
+
</P>
|
|
78
|
+
</VStack>
|
|
17
79
|
|
|
18
|
-
<
|
|
19
|
-
<
|
|
80
|
+
<VStack className="space-y-4">
|
|
81
|
+
<H2 className="font-bold text-2xl">Installation</H2>
|
|
20
82
|
<InstallCommand package="@contractspec/lib.personalization" />
|
|
21
|
-
</
|
|
83
|
+
</VStack>
|
|
22
84
|
|
|
23
|
-
<
|
|
24
|
-
<
|
|
25
|
-
<
|
|
85
|
+
<VStack className="space-y-4">
|
|
86
|
+
<H2 className="font-bold text-2xl">Tracker</H2>
|
|
87
|
+
<P className="text-muted-foreground">
|
|
26
88
|
Buffer events per tenant/user and emit OpenTelemetry counters
|
|
27
89
|
automatically.
|
|
28
|
-
</
|
|
90
|
+
</P>
|
|
29
91
|
<CodeBlock
|
|
30
92
|
language="typescript"
|
|
31
93
|
code={`import { createBehaviorTracker } from '@contractspec/lib.personalization';
|
|
@@ -38,29 +100,65 @@ const tracker = createBehaviorTracker({
|
|
|
38
100
|
tracker.trackFieldAccess({ operation: 'billing.createOrder', field: 'items' });
|
|
39
101
|
tracker.trackWorkflowStep({ workflow: 'invoice', step: 'review', status: 'entered' });`}
|
|
40
102
|
/>
|
|
41
|
-
</
|
|
103
|
+
</VStack>
|
|
104
|
+
|
|
105
|
+
<VStack className="space-y-4">
|
|
106
|
+
<H2 className="font-bold text-2xl">DataView Preferences</H2>
|
|
107
|
+
<P className="text-muted-foreground">
|
|
108
|
+
Use <Code>resolveDataViewPreferences</Code> when a collection DataView
|
|
109
|
+
should honor a user's preferred list/grid/table mode, compact or
|
|
110
|
+
comfortable density, data depth, and page size. The helper returns
|
|
111
|
+
plain values that can be passed into the renderer without coupling the
|
|
112
|
+
design-system package to personalization. Start from the{' '}
|
|
113
|
+
<Link
|
|
114
|
+
href="/docs/libraries/data-views"
|
|
115
|
+
className="text-[color:var(--rust)] underline underline-offset-4"
|
|
116
|
+
>
|
|
117
|
+
<Text>DataViews runtime guide</Text>
|
|
118
|
+
</Link>{' '}
|
|
119
|
+
when you need the contract and renderer shape.
|
|
120
|
+
</P>
|
|
121
|
+
<CodeBlock language="tsx" code={DATA_VIEW_PREFERENCE_EXAMPLE} />
|
|
122
|
+
</VStack>
|
|
42
123
|
|
|
43
|
-
<
|
|
44
|
-
<
|
|
45
|
-
<
|
|
124
|
+
<VStack className="space-y-4">
|
|
125
|
+
<H2 className="font-bold text-2xl">DataView Interaction Events</H2>
|
|
126
|
+
<P className="text-muted-foreground">
|
|
127
|
+
Track <Code>data_view_interaction</Code> events for view mode,
|
|
128
|
+
density, data depth, search, filters, sorting, and pagination. The
|
|
129
|
+
in-memory store summarizes those events, and the analyzer can derive a
|
|
130
|
+
scoped preferred collection mode from valid interaction counts.
|
|
131
|
+
</P>
|
|
132
|
+
<CodeBlock language="typescript" code={DATA_VIEW_TRACKING_EXAMPLE} />
|
|
133
|
+
</VStack>
|
|
134
|
+
|
|
135
|
+
<VStack className="space-y-4">
|
|
136
|
+
<H2 className="font-bold text-2xl">Analyzer</H2>
|
|
137
|
+
<P className="text-muted-foreground">
|
|
46
138
|
Summarize events and highlight unused UI, frequent fields, and
|
|
47
139
|
workflow bottlenecks.
|
|
48
|
-
</
|
|
140
|
+
</P>
|
|
49
141
|
<CodeBlock
|
|
50
142
|
language="typescript"
|
|
51
143
|
code={`import { BehaviorAnalyzer } from '@contractspec/lib.personalization/analyzer';
|
|
52
144
|
|
|
53
145
|
const analyzer = new BehaviorAnalyzer(store);
|
|
54
146
|
const insights = await analyzer.analyze({ tenantId: 'acme', userId: 'ops-42' });
|
|
55
|
-
// {
|
|
147
|
+
// {
|
|
148
|
+
// unusedFields: ['internalNotes'],
|
|
149
|
+
// workflowBottlenecks: [...],
|
|
150
|
+
// dataViewPreferences: {
|
|
151
|
+
// 'crm.accounts': { preferredViewMode: 'grid' }
|
|
152
|
+
// }
|
|
153
|
+
// }`}
|
|
56
154
|
/>
|
|
57
|
-
</
|
|
155
|
+
</VStack>
|
|
58
156
|
|
|
59
|
-
<
|
|
60
|
-
<
|
|
61
|
-
<
|
|
157
|
+
<VStack className="space-y-4">
|
|
158
|
+
<H2 className="font-bold text-2xl">Adapter</H2>
|
|
159
|
+
<P className="text-muted-foreground">
|
|
62
160
|
Convert insights into overlays or workflow extension hints.
|
|
63
|
-
</
|
|
161
|
+
</P>
|
|
64
162
|
<CodeBlock
|
|
65
163
|
language="typescript"
|
|
66
164
|
code={`import { insightsToOverlaySuggestion } from '@contractspec/lib.personalization/adapter';
|
|
@@ -71,16 +169,28 @@ const overlay = insightsToOverlaySuggestion(insights, {
|
|
|
71
169
|
capability: 'billing.createOrder',
|
|
72
170
|
});`}
|
|
73
171
|
/>
|
|
74
|
-
</
|
|
172
|
+
</VStack>
|
|
173
|
+
|
|
174
|
+
<VStack className="space-y-4">
|
|
175
|
+
<H2 className="font-bold text-2xl">Agent Prompt</H2>
|
|
176
|
+
<P className="text-muted-foreground">
|
|
177
|
+
Use this when asking an agent to wire DataView preferences while
|
|
178
|
+
preserving the personalization/design-system boundary.
|
|
179
|
+
</P>
|
|
180
|
+
<CodeBlock
|
|
181
|
+
language="markdown"
|
|
182
|
+
code={DATA_VIEW_PERSONALIZATION_PROMPT}
|
|
183
|
+
/>
|
|
184
|
+
</VStack>
|
|
75
185
|
|
|
76
|
-
<
|
|
186
|
+
<HStack className="items-center gap-4 pt-4">
|
|
77
187
|
<Link href="/docs/libraries" className="btn-ghost">
|
|
78
|
-
Back to Libraries
|
|
188
|
+
<Text>Back to Libraries</Text>
|
|
79
189
|
</Link>
|
|
80
190
|
<Link href="/docs/libraries/overlay-engine" className="btn-primary">
|
|
81
|
-
Next: Overlay Engine <ChevronRight size={16} />
|
|
191
|
+
<Text>Next: Overlay Engine</Text> <ChevronRight size={16} />
|
|
82
192
|
</Link>
|
|
83
|
-
</
|
|
84
|
-
</
|
|
193
|
+
</HStack>
|
|
194
|
+
</VStack>
|
|
85
195
|
);
|
|
86
196
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const translationRuntimeInstall = [
|
|
2
|
+
'@contractspec/lib.contracts-spec',
|
|
3
|
+
'@contractspec/lib.translation-runtime',
|
|
4
|
+
];
|
|
5
|
+
|
|
6
|
+
export const translationRuntimeExample = `import { createTranslationRuntime } from '@contractspec/lib.translation-runtime';
|
|
7
|
+
import { checkoutMessages } from './translations/checkout.messages';
|
|
8
|
+
|
|
9
|
+
const runtime = createTranslationRuntime({
|
|
10
|
+
catalogs: [checkoutMessages],
|
|
11
|
+
locale: 'fr-FR',
|
|
12
|
+
fallbackLocales: ['fr', 'en-US'],
|
|
13
|
+
onDiagnostic: (diagnostic) => reportTranslationIssue(diagnostic),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const label = runtime.t('checkout.pay', {
|
|
17
|
+
amount: 4200,
|
|
18
|
+
currency: 'EUR',
|
|
19
|
+
});`;
|
|
20
|
+
|
|
21
|
+
export const i18nextAdapterExample = `import { createInstance } from 'i18next';
|
|
22
|
+
import {
|
|
23
|
+
createI18nextInitOptions,
|
|
24
|
+
exportContractSpecToI18next,
|
|
25
|
+
} from '@contractspec/lib.translation-runtime/i18next';
|
|
26
|
+
|
|
27
|
+
const exported = exportContractSpecToI18next([checkoutMessages], {
|
|
28
|
+
locale: 'en-US',
|
|
29
|
+
assumeIcuFormatter: true,
|
|
30
|
+
});
|
|
31
|
+
const { options, diagnostics } = createI18nextInitOptions(exported, {
|
|
32
|
+
lng: 'en-US',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const i18next = createInstance();
|
|
36
|
+
await i18next.init(options);
|
|
37
|
+
reportAdapterDiagnostics(diagnostics);`;
|
|
38
|
+
|
|
39
|
+
export const ssrHydrationExample = `// Server: negotiate once, preload catalogs, and serialize the runtime snapshot.
|
|
40
|
+
const runtime = createTranslationRuntime({
|
|
41
|
+
catalogs,
|
|
42
|
+
locale: negotiatedLocale,
|
|
43
|
+
fallbackLocales,
|
|
44
|
+
});
|
|
45
|
+
const snapshot = runtime.createSnapshot();
|
|
46
|
+
|
|
47
|
+
// Client: hydrate from the same snapshot so locale, resources, and fallback state match.
|
|
48
|
+
const hydratedRuntime = createTranslationRuntime({ snapshot });`;
|
|
49
|
+
|
|
50
|
+
export const translationRuntimeChecks = [
|
|
51
|
+
'Keep TranslationSpec as the source of truth; do not flatten metadata into i18next JSON as the canonical model.',
|
|
52
|
+
'Keep stable bundle identity in TranslationSpec.meta.key and keep BCP 47 language tags in TranslationSpec.locale.',
|
|
53
|
+
'Use ICU messages for plural, select, selectordinal, number, date, currency, list, and relative-time formatting.',
|
|
54
|
+
'Create one runtime per SSR request when tenant, project, or user overrides are involved.',
|
|
55
|
+
'Serialize the same runtime snapshot or exported adapter resources used by the server for hydration.',
|
|
56
|
+
'Configure an ICU-capable i18next formatter plugin when rendering ContractSpec ICU messages through i18next.',
|
|
57
|
+
'Treat adapter diagnostics as release blockers in production pipelines instead of silently rendering raw keys.',
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
export const translationRuntimePrompt = `You are integrating ContractSpec translations into a production app.
|
|
61
|
+
Use @contractspec/lib.contracts-spec/translations as the canonical contract layer and @contractspec/lib.translation-runtime as the runtime layer.
|
|
62
|
+
Keep locale variants separate from stable bundle keys, support BCP 47 tags, preserve ICU plural/select/selectordinal messages, and use request-scoped runtime instances for SSR.
|
|
63
|
+
If the app already uses i18next, use @contractspec/lib.translation-runtime/i18next only as a downstream adapter. Do not make i18next the canonical translation model. Include diagnostics, fallback behavior, tenant/user override isolation, and hydration snapshot handling in the implementation and tests.`;
|
|
64
|
+
|
|
65
|
+
export const translationRuntimeLayers = [
|
|
66
|
+
{
|
|
67
|
+
title: 'Spec layer',
|
|
68
|
+
body: 'TranslationSpec owns keys, locales, domains, versions, owners, fallback declarations, direction, and validation metadata.',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
title: 'Runtime layer',
|
|
72
|
+
body: 'Runtime instances negotiate locales, apply fallback chains, resolve overrides, cache compiled messages, report diagnostics, and serialize SSR snapshots.',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
title: 'Adapter layer',
|
|
76
|
+
body: 'The i18next adapter projects ContractSpec specs or snapshots to resources and manifests for caller-owned i18next instances.',
|
|
77
|
+
},
|
|
78
|
+
];
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { CodeBlock, InstallCommand } from '@contractspec/lib.design-system';
|
|
2
|
+
import { HStack, VStack } from '@contractspec/lib.design-system/layout';
|
|
3
|
+
import { List, ListItem } from '@contractspec/lib.design-system/list';
|
|
4
|
+
import {
|
|
5
|
+
Code,
|
|
6
|
+
H1,
|
|
7
|
+
H2,
|
|
8
|
+
H3,
|
|
9
|
+
P,
|
|
10
|
+
Text,
|
|
11
|
+
} from '@contractspec/lib.design-system/typography';
|
|
12
|
+
import Link from '@contractspec/lib.ui-link';
|
|
13
|
+
import { ChevronRight } from 'lucide-react';
|
|
14
|
+
import {
|
|
15
|
+
i18nextAdapterExample,
|
|
16
|
+
ssrHydrationExample,
|
|
17
|
+
translationRuntimeChecks,
|
|
18
|
+
translationRuntimeExample,
|
|
19
|
+
translationRuntimeInstall,
|
|
20
|
+
translationRuntimeLayers,
|
|
21
|
+
translationRuntimePrompt,
|
|
22
|
+
} from './LibrariesTranslationRuntimePage.content';
|
|
23
|
+
|
|
24
|
+
export function LibrariesTranslationRuntimePage() {
|
|
25
|
+
return (
|
|
26
|
+
<VStack className="space-y-8">
|
|
27
|
+
<VStack className="space-y-4">
|
|
28
|
+
<Text className="editorial-kicker">Runtime and adapters</Text>
|
|
29
|
+
<H1 className="font-serif text-4xl tracking-[-0.04em] md:text-5xl">
|
|
30
|
+
Translation runtime and i18next adapter
|
|
31
|
+
</H1>
|
|
32
|
+
<P className="max-w-3xl text-lg text-muted-foreground leading-8">
|
|
33
|
+
Use ContractSpec as the canonical translation contract layer, then
|
|
34
|
+
resolve and format messages through a framework-independent runtime.
|
|
35
|
+
i18next is supported as an optional downstream adapter, not as the
|
|
36
|
+
source of truth.
|
|
37
|
+
</P>
|
|
38
|
+
</VStack>
|
|
39
|
+
|
|
40
|
+
<VStack className="space-y-4">
|
|
41
|
+
<H2 className="font-bold text-2xl">Install the runtime</H2>
|
|
42
|
+
<InstallCommand package={translationRuntimeInstall} />
|
|
43
|
+
<P className="text-muted-foreground">
|
|
44
|
+
<Text>Add </Text>
|
|
45
|
+
<Code>i18next</Code>
|
|
46
|
+
<Text>
|
|
47
|
+
{' '}
|
|
48
|
+
only when an app imports the adapter subpath. Core server, React,
|
|
49
|
+
React Native, CLI, and test code can use the runtime without loading
|
|
50
|
+
i18next.
|
|
51
|
+
</Text>
|
|
52
|
+
</P>
|
|
53
|
+
</VStack>
|
|
54
|
+
|
|
55
|
+
<HStack className="grid gap-4 md:grid-cols-3">
|
|
56
|
+
{translationRuntimeLayers.map((item) => (
|
|
57
|
+
<VStack className="card-subtle space-y-2 p-5" key={item.title}>
|
|
58
|
+
<H3 className="font-semibold text-lg">{item.title}</H3>
|
|
59
|
+
<P className="text-muted-foreground text-sm leading-7">
|
|
60
|
+
{item.body}
|
|
61
|
+
</P>
|
|
62
|
+
</VStack>
|
|
63
|
+
))}
|
|
64
|
+
</HStack>
|
|
65
|
+
|
|
66
|
+
<VStack className="space-y-4">
|
|
67
|
+
<H2 className="font-bold text-2xl">Use the ContractSpec runtime</H2>
|
|
68
|
+
<P className="text-muted-foreground">
|
|
69
|
+
<Text>The runtime consumes canonical </Text>
|
|
70
|
+
<Code>TranslationSpec[]</Code>
|
|
71
|
+
<Text>
|
|
72
|
+
{' '}
|
|
73
|
+
catalogs, supports BCP 47 tags such as en-US, ar-EG, and zh-Hans,
|
|
74
|
+
and delegates ICU parsing/formatting to a mature formatter engine
|
|
75
|
+
instead of a custom parser.
|
|
76
|
+
</Text>
|
|
77
|
+
</P>
|
|
78
|
+
<CodeBlock language="typescript" code={translationRuntimeExample} />
|
|
79
|
+
</VStack>
|
|
80
|
+
|
|
81
|
+
<VStack className="space-y-4">
|
|
82
|
+
<H2 className="font-bold text-2xl">Project to i18next when needed</H2>
|
|
83
|
+
<P className="text-muted-foreground">
|
|
84
|
+
<Text>Import from </Text>
|
|
85
|
+
<Code>@contractspec/lib.translation-runtime/i18next</Code>
|
|
86
|
+
<Text>
|
|
87
|
+
{' '}
|
|
88
|
+
to export resources by locale, namespace, and message key. The
|
|
89
|
+
namespace defaults to the stable bundle key, dotted message keys
|
|
90
|
+
stay flat with keySeparator false, and metadata remains in a sidecar
|
|
91
|
+
manifest.
|
|
92
|
+
</Text>
|
|
93
|
+
</P>
|
|
94
|
+
<CodeBlock language="typescript" code={i18nextAdapterExample} />
|
|
95
|
+
</VStack>
|
|
96
|
+
|
|
97
|
+
<VStack className="space-y-4">
|
|
98
|
+
<H2 className="font-bold text-2xl">SSR, streaming, and hydration</H2>
|
|
99
|
+
<P className="text-muted-foreground">
|
|
100
|
+
Negotiate locale on the server, preload catalogs needed for streamed
|
|
101
|
+
content, and hydrate the client from the same serialized state. Never
|
|
102
|
+
let client-only language detection choose a different locale after the
|
|
103
|
+
server has rendered.
|
|
104
|
+
</P>
|
|
105
|
+
<CodeBlock language="typescript" code={ssrHydrationExample} />
|
|
106
|
+
</VStack>
|
|
107
|
+
|
|
108
|
+
<VStack className="space-y-4">
|
|
109
|
+
<H2 className="font-bold text-2xl">Production checklist</H2>
|
|
110
|
+
<List className="list-disc space-y-2 pl-6 text-muted-foreground">
|
|
111
|
+
{translationRuntimeChecks.map((item) => (
|
|
112
|
+
<ListItem key={item}>{item}</ListItem>
|
|
113
|
+
))}
|
|
114
|
+
</List>
|
|
115
|
+
</VStack>
|
|
116
|
+
|
|
117
|
+
<VStack className="space-y-4 rounded-xl border border-border p-6">
|
|
118
|
+
<H2 className="font-bold text-2xl">Agent implementation prompt</H2>
|
|
119
|
+
<P className="text-muted-foreground">
|
|
120
|
+
Use this prompt when asking an agent to wire translations into a web,
|
|
121
|
+
server, or React Native surface without losing ContractSpec ownership.
|
|
122
|
+
</P>
|
|
123
|
+
<CodeBlock language="markdown" code={translationRuntimePrompt} />
|
|
124
|
+
</VStack>
|
|
125
|
+
|
|
126
|
+
<HStack className="flex flex-wrap items-center gap-4 pt-4">
|
|
127
|
+
<Link href="/docs/libraries/contracts" className="btn-ghost">
|
|
128
|
+
<Text>Translation contracts</Text>
|
|
129
|
+
</Link>
|
|
130
|
+
<Link href="/docs/libraries/design-system" className="btn-primary">
|
|
131
|
+
<Text>Design-system integration</Text>
|
|
132
|
+
<ChevronRight size={16} />
|
|
133
|
+
</Link>
|
|
134
|
+
</HStack>
|
|
135
|
+
</VStack>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
@@ -24,6 +24,7 @@ export { LibrariesSchemaPage } from './LibrariesSchemaPage';
|
|
|
24
24
|
export { LibrariesSLOPage } from './LibrariesSLOPage';
|
|
25
25
|
export { LibrariesSupportBotPage } from './LibrariesSupportBotPage';
|
|
26
26
|
export { LibrariesTestingPage } from './LibrariesTestingPage';
|
|
27
|
+
export { LibrariesTranslationRuntimePage } from './LibrariesTranslationRuntimePage';
|
|
27
28
|
export { LibrariesUIKitPage } from './LibrariesUIKitPage';
|
|
28
29
|
export { LibrariesUIKitWebPage } from './LibrariesUIKitWebPage';
|
|
29
30
|
export { LibrariesWorkflowComposerPage } from './LibrariesWorkflowComposerPage';
|