Skip to content

Commit cd1b47b

Browse files
Copilothotlong
andcommitted
refactor: remove runtime implementation from spec protocol package
Move generateTranslationSkeleton() and validateTranslationCompleteness() out of packages/spec per spec's "no business logic" principle. Spec retains only protocol definitions: - StrictObjectTranslation type utility (translation-typegen.ts) - TRANSLATE_PLACEHOLDER constant (translation-skeleton.ts) - All existing Zod schemas (translation.zod.ts) Runtime implementations should be re-implemented in appropriate packages (CLI, service-i18n, metadata) in future work. Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent fb22853 commit cd1b47b

5 files changed

Lines changed: 12 additions & 466 deletions

File tree

packages/spec/src/system/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export * from './notification.zod';
4343
export * from './translation.zod';
4444
export * from './translation-typegen';
4545
export * from './translation-skeleton';
46-
export * from './translation-validator';
4746
export * from './collaboration.zod';
4847
export * from './metadata-persistence.zod';
4948
export * from './core-services.zod';

packages/spec/src/system/translation-skeleton.test.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 12 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,22 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

3-
import type { ServiceObject } from '../data/object.zod';
4-
53
/**
6-
* Translation Skeleton Generator
4+
* Translation Skeleton Protocol Constants
75
*
8-
* Generates an AI-friendly JSON "fill-in-the-blank" template from an object
9-
* definition. The output contains `__TRANSLATE__` placeholders for every
10-
* translatable string, ensuring AI/human translators cannot accidentally
11-
* add or omit fields.
6+
* Defines the placeholder convention used in AI-friendly translation
7+
* skeleton templates. Runtime implementations (skeleton generation,
8+
* validation) belong in implementation packages (CLI, service-i18n, etc.).
129
*
1310
* @example
14-
* ```typescript
15-
* import { generateTranslationSkeleton } from '@objectstack/spec/system';
16-
* import { Task } from './objects/task.object';
17-
*
18-
* const skeleton = generateTranslationSkeleton(Task);
19-
* // → JSON string with __TRANSLATE__ placeholders for all 18 fields
11+
* ```json
12+
* {
13+
* "label": "__TRANSLATE__: \"Task\"",
14+
* "fields": {
15+
* "subject": { "label": "__TRANSLATE__: \"Subject\"" }
16+
* }
17+
* }
2018
* ```
2119
*/
2220

23-
/** Placeholder prefix used in skeleton output */
21+
/** Placeholder prefix used in translation skeleton output */
2422
export const TRANSLATE_PLACEHOLDER = '__TRANSLATE__';
25-
26-
/**
27-
* Generates a translation skeleton JSON string from an object definition.
28-
*
29-
* The skeleton includes:
30-
* - Object-level `label` and `pluralLabel`
31-
* - Every field with a `label` placeholder
32-
* - `help` placeholder for fields that have a `description`
33-
* - `options` map for select/multiselect fields with all option values
34-
*
35-
* @param objectDef - A parsed ServiceObject definition
36-
* @returns A formatted JSON string with `__TRANSLATE__` placeholders
37-
*/
38-
export function generateTranslationSkeleton(objectDef: ServiceObject): string {
39-
const skeleton: Record<string, unknown> = {
40-
label: `${TRANSLATE_PLACEHOLDER}: "${objectDef.label}"`,
41-
};
42-
43-
if (objectDef.pluralLabel) {
44-
skeleton.pluralLabel = `${TRANSLATE_PLACEHOLDER}: "${objectDef.pluralLabel}"`;
45-
}
46-
47-
const fieldsObj: Record<string, Record<string, unknown>> = {};
48-
49-
for (const [fieldName, fieldDef] of Object.entries(objectDef.fields)) {
50-
const fieldEntry: Record<string, unknown> = {
51-
label: `${TRANSLATE_PLACEHOLDER}: "${fieldDef.label ?? fieldName}"`,
52-
};
53-
54-
// Add help placeholder for fields with a description
55-
if (fieldDef.description) {
56-
fieldEntry.help = `${TRANSLATE_PLACEHOLDER}: "${fieldDef.description}"`;
57-
}
58-
59-
// Add options map for select/multiselect fields
60-
if (fieldDef.options && fieldDef.options.length > 0) {
61-
const optionsMap: Record<string, string> = {};
62-
for (const opt of fieldDef.options) {
63-
optionsMap[opt.value] = `${TRANSLATE_PLACEHOLDER}: "${opt.label}"`;
64-
}
65-
fieldEntry.options = optionsMap;
66-
}
67-
68-
fieldsObj[fieldName] = fieldEntry;
69-
}
70-
71-
skeleton.fields = fieldsObj;
72-
73-
return JSON.stringify(skeleton, null, 2);
74-
}

packages/spec/src/system/translation-validator.test.ts

Lines changed: 0 additions & 187 deletions
This file was deleted.

0 commit comments

Comments
 (0)