@parhelia/localization 0.4.12884 → 0.4.13030
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/LICENSE +1 -1
- package/dist/LocalizeItemCommand.d.ts.map +1 -1
- package/dist/LocalizeItemCommand.js +1 -0
- package/dist/LocalizeItemDialog.d.ts.map +1 -1
- package/dist/LocalizeItemDialog.js +9 -3
- package/dist/LocalizeItemUtils.d.ts +1 -0
- package/dist/LocalizeItemUtils.d.ts.map +1 -1
- package/dist/LocalizeItemUtils.js +44 -18
- package/dist/api/discovery.d.ts +17 -3
- package/dist/api/discovery.d.ts.map +1 -1
- package/dist/api/discovery.js +35 -14
- package/dist/hooks/useTranslationWizard.d.ts.map +1 -1
- package/dist/hooks/useTranslationWizard.js +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/services/translationService.d.ts +43 -27
- package/dist/services/translationService.d.ts.map +1 -1
- package/dist/services/translationService.js +36 -32
- package/dist/services/translationSettingsService.d.ts +79 -0
- package/dist/services/translationSettingsService.d.ts.map +1 -0
- package/dist/services/translationSettingsService.js +68 -0
- package/dist/settings/ExcludedContentTypeDialog.d.ts +12 -0
- package/dist/settings/ExcludedContentTypeDialog.d.ts.map +1 -0
- package/dist/settings/ExcludedContentTypeDialog.js +29 -0
- package/dist/settings/TranslationProviderDialog.d.ts +18 -0
- package/dist/settings/TranslationProviderDialog.d.ts.map +1 -0
- package/dist/settings/TranslationProviderDialog.js +105 -0
- package/dist/settings/TranslationServicesPanel.d.ts +14 -4
- package/dist/settings/TranslationServicesPanel.d.ts.map +1 -1
- package/dist/settings/TranslationServicesPanel.js +186 -263
- package/dist/setup/LocalizationSetupStep.d.ts.map +1 -1
- package/dist/setup/LocalizationSetupStep.js +14 -33
- package/dist/sidebar/TranslationSidebar.d.ts.map +1 -1
- package/dist/sidebar/TranslationSidebar.js +35 -14
- package/dist/steps/ItemSelectionTree.d.ts.map +1 -1
- package/dist/steps/ItemSelectionTree.js +130 -43
- package/dist/steps/ProviderStep.d.ts.map +1 -1
- package/dist/steps/ProviderStep.js +54 -42
- package/dist/steps/ServiceLanguageSelectionStep.d.ts.map +1 -1
- package/dist/steps/ServiceLanguageSelectionStep.js +32 -9
- package/dist/steps/types.d.ts +7 -1
- package/dist/steps/types.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.d.ts +36 -0
- package/dist/translation-center/TranslationBatches.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.js +200 -77
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translationService.d.ts","sourceRoot":"","sources":["../../src/services/translationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"translationService.d.ts","sourceRoot":"","sources":["../../src/services/translationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC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Key(descriptor) {
|
|
3
|
+
return translationItemKey({
|
|
4
|
+
store: descriptor.database,
|
|
5
|
+
itemId: descriptor.id,
|
|
6
|
+
});
|
|
4
7
|
}
|
|
5
|
-
export
|
|
6
|
-
return
|
|
8
|
+
export function translationItemKey(item) {
|
|
9
|
+
return JSON.stringify([item.store ?? null, item.itemId]);
|
|
7
10
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
11
|
+
export function translationItem(descriptor) {
|
|
12
|
+
if (!descriptor.database)
|
|
13
|
+
throw new Error("Translation requires an explicit content store.");
|
|
14
|
+
return { store: descriptor.database, itemId: descriptor.id };
|
|
10
15
|
}
|
|
11
|
-
export async function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
language,
|
|
16
|
-
translationFolderPath: structureSettings?.translationFolderPath,
|
|
17
|
-
translationFolderTemplateId: structureSettings?.translationFolderTemplateId,
|
|
18
|
-
translationProvidersPath: structureSettings?.translationProvidersPath,
|
|
19
|
-
translationProvidersTemplateId: structureSettings?.translationProvidersTemplateId,
|
|
16
|
+
export async function getTranslationStatus(item) {
|
|
17
|
+
const coordinate = translationItem(item);
|
|
18
|
+
const params = new URLSearchParams({
|
|
19
|
+
...coordinate,
|
|
20
|
+
language: item.language,
|
|
20
21
|
});
|
|
22
|
+
return await get(`/parhelia/translation/getTranslations?${params}`);
|
|
21
23
|
}
|
|
22
|
-
export async function
|
|
23
|
-
return await
|
|
24
|
-
translationFolderPath: settings.translationFolderPath,
|
|
25
|
-
translationFolderTemplateId: settings.translationFolderTemplateId,
|
|
26
|
-
translationProvidersPath: settings.translationProvidersPath,
|
|
27
|
-
translationProvidersTemplateId: settings.translationProvidersTemplateId,
|
|
28
|
-
});
|
|
24
|
+
export async function getTranslationProviders() {
|
|
25
|
+
return await get(`/parhelia/translation/providers`);
|
|
29
26
|
}
|
|
30
|
-
export async function
|
|
31
|
-
return await
|
|
32
|
-
translationFolderPath: settings.translationFolderPath,
|
|
33
|
-
translationFolderTemplateId: settings.translationFolderTemplateId,
|
|
34
|
-
translationProvidersPath: settings.translationProvidersPath,
|
|
35
|
-
translationProvidersTemplateId: settings.translationProvidersTemplateId,
|
|
36
|
-
});
|
|
27
|
+
export async function getAvailableTranslationServices() {
|
|
28
|
+
return await get(`/parhelia/translation/availableServices`);
|
|
37
29
|
}
|
|
38
30
|
export async function listBatchTranslationJobs(batchId) {
|
|
39
31
|
return await get(`/parhelia/translation/batchJobs?batchId=${encodeURIComponent(batchId)}`);
|
|
@@ -75,8 +67,13 @@ export async function listBatches(take = 100, skip = 0, filters = {}) {
|
|
|
75
67
|
params.set("provider", filters.provider);
|
|
76
68
|
if (filters.targetLanguage)
|
|
77
69
|
params.set("targetLanguage", filters.targetLanguage);
|
|
78
|
-
if (filters.itemIdOrPath)
|
|
70
|
+
if (filters.itemIdOrPath) {
|
|
71
|
+
if (!filters.store || !filters.language)
|
|
72
|
+
throw new Error("Item filters require a store and language.");
|
|
79
73
|
params.set("itemIdOrPath", filters.itemIdOrPath);
|
|
74
|
+
params.set("store", filters.store);
|
|
75
|
+
params.set("language", filters.language);
|
|
76
|
+
}
|
|
80
77
|
if (filters.itemIncludeSubitems)
|
|
81
78
|
params.set("itemIncludeSubitems", "true");
|
|
82
79
|
return await get(`/parhelia/translation/batches?${params.toString()}`);
|
|
@@ -87,19 +84,26 @@ export async function abortJob(id) {
|
|
|
87
84
|
export async function abortBatch(id) {
|
|
88
85
|
return await post("/parhelia/translation/abortBatch", { id });
|
|
89
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Deletes a batch that has stopped, with its jobs. A running batch is refused
|
|
89
|
+
* (409): abort it first. Translations already written to content stay.
|
|
90
|
+
*/
|
|
91
|
+
export async function deleteBatch(id) {
|
|
92
|
+
return await post("/parhelia/translation/deleteBatch", { id });
|
|
93
|
+
}
|
|
90
94
|
export async function subscribeToBatch(batchId, sessionId) {
|
|
91
95
|
return await post("/parhelia/translation/subscribeToBatch", { batchId, sessionId });
|
|
92
96
|
}
|
|
93
97
|
export async function unsubscribeFromBatch(batchId, sessionId) {
|
|
94
98
|
return await post("/parhelia/translation/unsubscribeFromBatch", { batchId, sessionId });
|
|
95
99
|
}
|
|
96
|
-
export async function requestBatchTranslation({ sessionId, provider, batchMetadata, languageMappings,
|
|
100
|
+
export async function requestBatchTranslation({ sessionId, provider, batchMetadata, languageMappings, items, }) {
|
|
97
101
|
return await post("/parhelia/translation/requestBatchTranslation", {
|
|
98
102
|
sessionId,
|
|
99
103
|
provider,
|
|
100
104
|
batchMetadata: batchMetadata || "",
|
|
101
105
|
languageMappings,
|
|
102
|
-
|
|
106
|
+
items,
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
109
|
export async function retryBatchTranslation({ sessionId, sourceBatchId, provider, jobs, }) {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Settings "Translation Services" page (`/parhelia/translation-settings/*`, administrators only, every host and
|
|
3
|
+
* every CMS): the translation providers with the fields their services declare, and the translation settings.
|
|
4
|
+
*/
|
|
5
|
+
export type TranslationProviderFieldType = "text" | "multiline" | "number" | "checkbox" | "choice" | "modelReference" | "languages" | "secret";
|
|
6
|
+
export interface TranslationFieldOption {
|
|
7
|
+
value: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TranslationProviderField {
|
|
11
|
+
name: string;
|
|
12
|
+
label: string;
|
|
13
|
+
type: TranslationProviderFieldType;
|
|
14
|
+
required: boolean;
|
|
15
|
+
help?: string | null;
|
|
16
|
+
defaultValue?: string | null;
|
|
17
|
+
/** A choice field's options, the chat models, or the mounted languages. */
|
|
18
|
+
options: TranslationFieldOption[];
|
|
19
|
+
/** The stored value; null when none is stored, and always null for a secret. */
|
|
20
|
+
value: string | null;
|
|
21
|
+
/** For a secret: whether one is stored. */
|
|
22
|
+
isSet?: boolean | null;
|
|
23
|
+
}
|
|
24
|
+
export interface TranslationProvider {
|
|
25
|
+
serviceName: string;
|
|
26
|
+
displayName: string;
|
|
27
|
+
configured: boolean;
|
|
28
|
+
fields: TranslationProviderField[];
|
|
29
|
+
}
|
|
30
|
+
export interface TranslationContentType {
|
|
31
|
+
key: string;
|
|
32
|
+
name: string;
|
|
33
|
+
/** Whether a mounted store describes the key (an unknown one stays listed so it can be removed). */
|
|
34
|
+
known: boolean;
|
|
35
|
+
store?: string | null;
|
|
36
|
+
}
|
|
37
|
+
export interface TranslationSettingsValues {
|
|
38
|
+
maxConcurrentTranslationJobs: number;
|
|
39
|
+
/** 0 sets no limit per batch. */
|
|
40
|
+
maxConcurrentJobsPerBatch: number;
|
|
41
|
+
skipSharedFields: boolean;
|
|
42
|
+
displayCosts: boolean;
|
|
43
|
+
excludedContentTypes: TranslationContentType[];
|
|
44
|
+
}
|
|
45
|
+
export type TranslationSettingName = Exclude<keyof TranslationSettingsValues, never>;
|
|
46
|
+
export interface TranslationSettingsPage {
|
|
47
|
+
providers: TranslationProvider[];
|
|
48
|
+
settings: TranslationSettingsValues;
|
|
49
|
+
defaults: TranslationSettingsValues;
|
|
50
|
+
/** The settings the customer set; the others follow the shipped defaults. */
|
|
51
|
+
customized: TranslationSettingName[];
|
|
52
|
+
languages: {
|
|
53
|
+
code: string;
|
|
54
|
+
name: string;
|
|
55
|
+
}[];
|
|
56
|
+
}
|
|
57
|
+
/** What a settings save sets (a member left out is not touched). */
|
|
58
|
+
export interface TranslationSettingsSet {
|
|
59
|
+
maxConcurrentTranslationJobs?: number;
|
|
60
|
+
maxConcurrentJobsPerBatch?: number;
|
|
61
|
+
skipSharedFields?: boolean;
|
|
62
|
+
displayCosts?: boolean;
|
|
63
|
+
excludedContentTypes?: string[];
|
|
64
|
+
}
|
|
65
|
+
/** The answer with every list present (the server leaves out nulls). */
|
|
66
|
+
export declare function normalizeTranslationSettings(value: Partial<TranslationSettingsPage> | null | undefined): TranslationSettingsPage;
|
|
67
|
+
export declare const translationSettingsService: {
|
|
68
|
+
get(): Promise<TranslationSettingsPage>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates the service's settings when it has none and writes the values: a field left out keeps its value, `null`
|
|
71
|
+
* clears it. An empty `values` only creates the settings.
|
|
72
|
+
*/
|
|
73
|
+
saveProvider: (serviceName: string, values: Record<string, string | null>) => Promise<TranslationSettingsPage>;
|
|
74
|
+
deleteProvider: (serviceName: string) => Promise<TranslationSettingsPage>;
|
|
75
|
+
/** Sets values and resets settings to their shipped defaults (the customer's value is removed). */
|
|
76
|
+
saveSettings: (set: TranslationSettingsSet, reset?: TranslationSettingName[]) => Promise<TranslationSettingsPage>;
|
|
77
|
+
contentTypeOf(store: string, itemId: string): Promise<TranslationContentType>;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=translationSettingsService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translationSettingsService.d.ts","sourceRoot":"","sources":["../../src/services/translationSettingsService.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,MAAM,MAAM,4BAA4B,GACpC,MAAM,GACN,WAAW,GACX,QAAQ,GACR,UAAU,GACV,QAAQ,GACR,gBAAgB,GAChB,WAAW,GACX,QAAQ,CAAC;AAEb,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,4BAA4B,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,2EAA2E;IAC3E,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAClC,gFAAgF;IAChF,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,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,CAAC,GAAG,IAAI,GAAG,SAAS,GACzD,uBAAuB,CAkBzB;AAiBD,eAAO,MAAM,0BAA0B;IAC/B,GAAG,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAO7C;;;OAGG;IACH,YAAY,gBAAgB,MAAM,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAOzE,cAAc,gBAAgB,MAAM;IAOpC,mGAAmG;IACnG,YAAY,QAAQ,sBAAsB,UAAS,sBAAsB,EAAE;IAOrE,aAAa,QAAQ,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;CASpF,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { get, post } from "@parhelia/core";
|
|
2
|
+
const emptyValues = () => ({
|
|
3
|
+
maxConcurrentTranslationJobs: 0,
|
|
4
|
+
maxConcurrentJobsPerBatch: 0,
|
|
5
|
+
skipSharedFields: false,
|
|
6
|
+
displayCosts: false,
|
|
7
|
+
excludedContentTypes: [],
|
|
8
|
+
});
|
|
9
|
+
/** The values with every list present; a type key counts as known only when the server says so. */
|
|
10
|
+
const values = (value) => ({
|
|
11
|
+
...emptyValues(),
|
|
12
|
+
...(value ?? {}),
|
|
13
|
+
excludedContentTypes: (value?.excludedContentTypes ?? []).map((type) => ({ ...type, known: type.known === true })),
|
|
14
|
+
});
|
|
15
|
+
/** The answer with every list present (the server leaves out nulls). */
|
|
16
|
+
export function normalizeTranslationSettings(value) {
|
|
17
|
+
return {
|
|
18
|
+
providers: (value?.providers ?? []).map((provider) => ({
|
|
19
|
+
serviceName: provider.serviceName ?? "",
|
|
20
|
+
displayName: provider.displayName || provider.serviceName || "",
|
|
21
|
+
configured: provider.configured === true,
|
|
22
|
+
fields: (provider.fields ?? []).map((field) => ({
|
|
23
|
+
...field,
|
|
24
|
+
required: field.required === true,
|
|
25
|
+
options: field.options ?? [],
|
|
26
|
+
value: field.value ?? null,
|
|
27
|
+
})),
|
|
28
|
+
})),
|
|
29
|
+
settings: values(value?.settings),
|
|
30
|
+
defaults: values(value?.defaults),
|
|
31
|
+
customized: value?.customized ?? [],
|
|
32
|
+
languages: value?.languages ?? [],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The server's own words for a refused save (a named refusal answers `{ summary, reason }`). */
|
|
36
|
+
function fail(result, fallback) {
|
|
37
|
+
throw new Error(result.summary && result.summary !== "Error"
|
|
38
|
+
? result.summary
|
|
39
|
+
: result.details || fallback);
|
|
40
|
+
}
|
|
41
|
+
async function save(url, body, fallback) {
|
|
42
|
+
const result = await post(url, body);
|
|
43
|
+
if (result.type !== "success" || !result.data)
|
|
44
|
+
fail(result, fallback);
|
|
45
|
+
return normalizeTranslationSettings(result.data.settings);
|
|
46
|
+
}
|
|
47
|
+
export const translationSettingsService = {
|
|
48
|
+
async get() {
|
|
49
|
+
const result = await get("/parhelia/translation-settings/index");
|
|
50
|
+
if (result.type !== "success" || !result.data)
|
|
51
|
+
fail(result, "Failed to load the translation settings");
|
|
52
|
+
return normalizeTranslationSettings(result.data);
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Creates the service's settings when it has none and writes the values: a field left out keeps its value, `null`
|
|
56
|
+
* clears it. An empty `values` only creates the settings.
|
|
57
|
+
*/
|
|
58
|
+
saveProvider: (serviceName, values) => save("/parhelia/translation-settings/saveProvider", { serviceName, values }, "Failed to save the provider"),
|
|
59
|
+
deleteProvider: (serviceName) => save("/parhelia/translation-settings/deleteProvider", { serviceName }, "Failed to delete the provider"),
|
|
60
|
+
/** Sets values and resets settings to their shipped defaults (the customer's value is removed). */
|
|
61
|
+
saveSettings: (set, reset = []) => save("/parhelia/translation-settings/saveSettings", { set, reset }, "Failed to save the translation settings"),
|
|
62
|
+
async contentTypeOf(store, itemId) {
|
|
63
|
+
const result = await post("/parhelia/translation-settings/contentTypeOf", { store, itemId });
|
|
64
|
+
if (result.type !== "success" || !result.data)
|
|
65
|
+
fail(result, "Failed to read the content type");
|
|
66
|
+
return { ...result.data, known: true };
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds a content type to the types translation skips: the person picks the content store, then an item of that type in
|
|
3
|
+
* the store's content tree (every CMS has items; not every CMS lists its types).
|
|
4
|
+
*/
|
|
5
|
+
export declare function ExcludedContentTypeDialog({ open, saving, error, onOpenChange, onPick, }: {
|
|
6
|
+
open: boolean;
|
|
7
|
+
saving: boolean;
|
|
8
|
+
error: string | null;
|
|
9
|
+
onOpenChange: (open: boolean) => void;
|
|
10
|
+
onPick: (store: string, itemId: string) => void;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
//# sourceMappingURL=ExcludedContentTypeDialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExcludedContentTypeDialog.d.ts","sourceRoot":"","sources":["../../src/settings/ExcludedContentTypeDialog.tsx"],"names":[],"mappings":"AAeA;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,IAAI,EACJ,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,GACP,EAAE;IACD,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD,+BAuGA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { FolderTree, Loader2 } from "lucide-react";
|
|
4
|
+
import { Button, ContentStoreSelect, ContentTree, Dialog, DialogContent, DialogFooter, FormField, StyledDialogTitle, settingsText, useContentModel, } from "@parhelia/core";
|
|
5
|
+
/**
|
|
6
|
+
* Adds a content type to the types translation skips: the person picks the content store, then an item of that type in
|
|
7
|
+
* the store's content tree (every CMS has items; not every CMS lists its types).
|
|
8
|
+
*/
|
|
9
|
+
export function ExcludedContentTypeDialog({ open, saving, error, onOpenChange, onPick, }) {
|
|
10
|
+
const model = useContentModel();
|
|
11
|
+
const stores = model?.stores ?? [];
|
|
12
|
+
const [store, setStore] = useState("");
|
|
13
|
+
const [itemId, setItemId] = useState("");
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!open)
|
|
16
|
+
return;
|
|
17
|
+
setItemId("");
|
|
18
|
+
setStore((current) => current || (stores.length === 1 ? stores[0].id : ""));
|
|
19
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
20
|
+
}, [open]);
|
|
21
|
+
const roots = model?.roots
|
|
22
|
+
.filter((root) => root.storeId === store && root.kind === "content")
|
|
23
|
+
.map((root) => root.id) ?? [];
|
|
24
|
+
const language = stores.find((candidate) => candidate.id === store)?.defaultLocale ?? "en";
|
|
25
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { className: "max-w-xl gap-0 p-0", "data-testid": "translation-excluded-type-dialog", children: [_jsx(StyledDialogTitle, { icon: _jsx(FolderTree, { strokeWidth: 1 }), title: "Exclude a content type", subtitle: "Pick an item: its content type, and every type based on it, is not translated." }), _jsxs("div", { className: "flex flex-col gap-4 px-8 py-6", children: [_jsx(FormField, { label: "Content store", children: _jsx(ContentStoreSelect, { value: store, onValueChange: (value) => {
|
|
26
|
+
setStore(value);
|
|
27
|
+
setItemId("");
|
|
28
|
+
}, stores: stores, placeholder: "Select a content store", maxWidth: "100%", "data-testid": "translation-excluded-type-store" }) }), store && roots.length === 0 && (_jsx("p", { className: settingsText.help, children: "This store shows no content tree to pick from." })), store && roots.length > 0 && (_jsx("div", { className: "border-border-default h-72 overflow-auto rounded-md border", "data-testid": "translation-excluded-type-tree", children: _jsx(ContentTree, { database: store, language: language, rootItemIds: roots, hideRootNodes: false, selectionMode: "single", selectedItemIds: itemId ? [itemId] : [], onSelectionChange: (items) => setItemId(items[0]?.id ?? "") }, JSON.stringify([store, language])) })), error && (_jsx("p", { className: settingsText.error, role: "alert", "data-testid": "translation-excluded-type-error", children: error }))] }), _jsxs(DialogFooter, { className: "border-border-default gap-2 border-t pt-5 sm:gap-3", children: [_jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), disabled: saving, children: "Cancel" }), _jsxs(Button, { onClick: () => onPick(store, itemId), disabled: saving || !store || !itemId, "data-testid": "translation-excluded-type-add", children: [saving && (_jsx(Loader2, { className: "h-4 w-4 animate-spin", strokeWidth: 1 })), "Add its content type"] })] })] }) }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TranslationProvider } from "../services/translationSettingsService";
|
|
2
|
+
/** What the form holds per field: the text to save; a secret starts empty and is only sent when typed or removed. */
|
|
3
|
+
type Draft = Record<string, string>;
|
|
4
|
+
/**
|
|
5
|
+
* The values a save sends: only fields that changed. A secret is sent when something was typed, or as `null` when the
|
|
6
|
+
* person removed it; it is never read back, so an untouched secret is not sent.
|
|
7
|
+
*/
|
|
8
|
+
export declare function providerChanges(provider: TranslationProvider, draft: Draft, removedSecrets: ReadonlySet<string>): Record<string, string | null>;
|
|
9
|
+
/** Edits one translation provider's settings with the fields its service declares (on every host and CMS). */
|
|
10
|
+
export declare function TranslationProviderDialog({ provider, saving, error, onOpenChange, onSave, }: {
|
|
11
|
+
provider: TranslationProvider | null;
|
|
12
|
+
saving: boolean;
|
|
13
|
+
error: string | null;
|
|
14
|
+
onOpenChange: (open: boolean) => void;
|
|
15
|
+
onSave: (values: Record<string, string | null>) => void;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=TranslationProviderDialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranslationProviderDialog.d.ts","sourceRoot":"","sources":["../../src/settings/TranslationProviderDialog.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,mBAAmB,EAEpB,MAAM,wCAAwC,CAAC;AAKhD,qHAAqH;AACrH,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAepC;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAc/B;AAkKD,8GAA8G;AAC9G,wBAAgB,yBAAyB,CAAC,EACxC,QAAQ,EACR,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACrC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;CACzD,+BA6GA"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { Languages, Loader2 } from "lucide-react";
|
|
4
|
+
import { Button, Checkbox, Dialog, DialogContent, DialogFooter, FormField, Input, Select, StyledDialogTitle, Textarea, cn, settingsText, } from "@parhelia/core";
|
|
5
|
+
/** The select value of "no model chosen" (the provider then uses the default agent profile's model). */
|
|
6
|
+
const NO_MODEL = "translation-provider-default-model";
|
|
7
|
+
const splitList = (value) => (value ?? "")
|
|
8
|
+
.split(/[|\r\n]+/)
|
|
9
|
+
.map((entry) => entry.trim())
|
|
10
|
+
.filter(Boolean);
|
|
11
|
+
function initialDraft(provider) {
|
|
12
|
+
const draft = {};
|
|
13
|
+
for (const field of provider.fields)
|
|
14
|
+
draft[field.name] = field.type === "secret" ? "" : (field.value ?? "");
|
|
15
|
+
return draft;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The values a save sends: only fields that changed. A secret is sent when something was typed, or as `null` when the
|
|
19
|
+
* person removed it; it is never read back, so an untouched secret is not sent.
|
|
20
|
+
*/
|
|
21
|
+
export function providerChanges(provider, draft, removedSecrets) {
|
|
22
|
+
const changes = {};
|
|
23
|
+
for (const field of provider.fields) {
|
|
24
|
+
const text = draft[field.name] ?? "";
|
|
25
|
+
if (field.type === "secret") {
|
|
26
|
+
if (text.length > 0)
|
|
27
|
+
changes[field.name] = text;
|
|
28
|
+
else if (removedSecrets.has(field.name))
|
|
29
|
+
changes[field.name] = null;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const stored = field.value ?? "";
|
|
33
|
+
if (text.replace(/\r\n/g, "\n") === stored.replace(/\r\n/g, "\n"))
|
|
34
|
+
continue;
|
|
35
|
+
changes[field.name] = text.trim().length === 0 ? null : text;
|
|
36
|
+
}
|
|
37
|
+
return changes;
|
|
38
|
+
}
|
|
39
|
+
function FieldInput({ field, value, secretState, onChange, onRemoveSecret, }) {
|
|
40
|
+
const testId = `translation-provider-field-${field.name.replace(/\s+/g, "-").toLowerCase()}`;
|
|
41
|
+
switch (field.type) {
|
|
42
|
+
case "multiline":
|
|
43
|
+
return (_jsx(Textarea, { value: value, onChange: (event) => onChange(event.target.value), rows: 5, placeholder: field.defaultValue ?? undefined, "data-testid": testId }));
|
|
44
|
+
case "number":
|
|
45
|
+
return (_jsx(Input, { type: "number", value: value, onChange: (event) => onChange(event.target.value), placeholder: field.defaultValue ?? undefined, "data-testid": testId }));
|
|
46
|
+
case "checkbox":
|
|
47
|
+
return (_jsx(Checkbox, { checked: value === "1", onCheckedChange: (checked) => onChange(checked === true ? "1" : ""), "data-testid": testId }));
|
|
48
|
+
case "choice":
|
|
49
|
+
return (_jsx(Select, { value: value, onValueChange: onChange, options: field.options.map((option) => ({
|
|
50
|
+
value: option.value,
|
|
51
|
+
label: option.label,
|
|
52
|
+
})), placeholder: field.defaultValue ?? "Not set", maxWidth: "100%", "data-testid": testId }));
|
|
53
|
+
case "modelReference":
|
|
54
|
+
return (_jsx(Select, { value: value || NO_MODEL, onValueChange: (next) => onChange(next === NO_MODEL ? "" : next), options: [
|
|
55
|
+
{
|
|
56
|
+
value: NO_MODEL,
|
|
57
|
+
label: "Default (the model of the default agent profile)",
|
|
58
|
+
},
|
|
59
|
+
...field.options.map((option) => ({
|
|
60
|
+
value: option.value,
|
|
61
|
+
label: option.label,
|
|
62
|
+
})),
|
|
63
|
+
], searchable: true, maxWidth: "100%", "data-testid": testId }));
|
|
64
|
+
case "languages": {
|
|
65
|
+
const selected = new Set(splitList(value).map((code) => code.toLowerCase()));
|
|
66
|
+
const toggle = (code, on) => {
|
|
67
|
+
const codes = field.options
|
|
68
|
+
.map((option) => option.value)
|
|
69
|
+
.filter((option) => option === code ? on : selected.has(option.toLowerCase()));
|
|
70
|
+
onChange(codes.join("|"));
|
|
71
|
+
};
|
|
72
|
+
if (field.options.length === 0)
|
|
73
|
+
return (_jsx("p", { className: settingsText.meta, children: "The mounted content has no languages." }));
|
|
74
|
+
return (_jsx("div", { className: "grid gap-1.5 sm:grid-cols-2", "data-testid": testId, children: field.options.map((option) => (_jsxs("span", { className: cn("flex items-center gap-2", settingsText.body), children: [_jsx(Checkbox, { checked: selected.has(option.value.toLowerCase()), onCheckedChange: (checked) => toggle(option.value, checked === true), "aria-label": option.label, "data-testid": `${testId}-${option.value}` }), _jsx("span", { children: option.label }), option.label !== option.value && (_jsx("span", { className: cn("text-neutral-grey-50", settingsText.mono), children: option.value }))] }, option.value))) }));
|
|
75
|
+
}
|
|
76
|
+
case "secret":
|
|
77
|
+
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Input, { type: "password", autoComplete: "new-password", value: value, onChange: (event) => onChange(event.target.value), placeholder: secretState === "set"
|
|
78
|
+
? "Set. Type a new value to replace it."
|
|
79
|
+
: "Not set", "data-testid": testId }), secretState === "set" && value.length === 0 && (_jsx(Button, { variant: "outline", size: "sm", onClick: onRemoveSecret, "data-testid": `${testId}-remove`, children: "Remove" }))] }));
|
|
80
|
+
default:
|
|
81
|
+
return (_jsx(Input, { value: value, onChange: (event) => onChange(event.target.value), placeholder: field.defaultValue ?? undefined, "data-testid": testId }));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Edits one translation provider's settings with the fields its service declares (on every host and CMS). */
|
|
85
|
+
export function TranslationProviderDialog({ provider, saving, error, onOpenChange, onSave, }) {
|
|
86
|
+
// The panel keys this dialog by provider, so a fresh form starts from the provider it opens for.
|
|
87
|
+
const [draft, setDraft] = useState(() => provider ? initialDraft(provider) : {});
|
|
88
|
+
const [removedSecrets, setRemovedSecrets] = useState(() => new Set());
|
|
89
|
+
const changes = useMemo(() => (provider ? providerChanges(provider, draft, removedSecrets) : {}), [provider, draft, removedSecrets]);
|
|
90
|
+
const dirty = Object.keys(changes).length > 0;
|
|
91
|
+
return (_jsx(Dialog, { open: provider !== null, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { className: "max-w-2xl gap-0 p-0", "data-testid": "translation-provider-dialog", children: [_jsx(StyledDialogTitle, { icon: _jsx(Languages, { strokeWidth: 1 }), title: provider ? `Settings: ${provider.displayName}` : "Settings", subtitle: provider
|
|
92
|
+
? `Translation service "${provider.serviceName}".`
|
|
93
|
+
: undefined }), _jsxs("div", { className: "flex max-h-[60vh] flex-col gap-4 overflow-auto px-8 py-6", children: [provider?.fields.map((field) => {
|
|
94
|
+
const label = field.required ? `${field.label} *` : field.label;
|
|
95
|
+
const input = (_jsx(FieldInput, { field: field, value: draft[field.name] ?? "", secretState: field.type !== "secret"
|
|
96
|
+
? "unset"
|
|
97
|
+
: removedSecrets.has(field.name)
|
|
98
|
+
? "removed"
|
|
99
|
+
: field.isSet
|
|
100
|
+
? "set"
|
|
101
|
+
: "unset", onChange: (value) => setDraft((current) => ({ ...current, [field.name]: value })), onRemoveSecret: () => setRemovedSecrets((current) => new Set(current).add(field.name)) }));
|
|
102
|
+
// A group of checkboxes is several controls: a <label> around it would send every click to the first one.
|
|
103
|
+
return field.type === "languages" ? (_jsxs("fieldset", { className: "flex flex-col gap-1.5", children: [_jsx("legend", { className: cn("mb-1.5", settingsText.label), children: label }), input, field.help && (_jsx("p", { className: settingsText.help, children: field.help }))] }, field.name)) : (_jsx(FormField, { label: label, hint: field.help ?? undefined, children: input }, field.name));
|
|
104
|
+
}), error && (_jsx("p", { className: settingsText.error, role: "alert", "data-testid": "translation-provider-error", children: error }))] }), _jsxs(DialogFooter, { className: "border-border-default gap-2 border-t pt-5 sm:gap-3", children: [_jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), disabled: saving, children: "Cancel" }), _jsxs(Button, { onClick: () => onSave(changes), disabled: saving || !dirty, "data-testid": "translation-provider-save", children: [saving && (_jsx(Loader2, { className: "h-4 w-4 animate-spin", strokeWidth: 1 })), "Save"] })] })] }) }));
|
|
105
|
+
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type TranslationContentType, type TranslationSettingsSet, type TranslationSettingsValues } from "../services/translationSettingsService";
|
|
2
|
+
/** What the settings form edits (numbers as typed text). */
|
|
3
|
+
type SettingsDraft = {
|
|
4
|
+
maxConcurrentTranslationJobs: string;
|
|
5
|
+
maxConcurrentJobsPerBatch: string;
|
|
6
|
+
skipSharedFields: boolean;
|
|
7
|
+
displayCosts: boolean;
|
|
8
|
+
excludedContentTypes: TranslationContentType[];
|
|
9
|
+
};
|
|
10
|
+
/** What a save sends: only the settings the person changed. */
|
|
11
|
+
export declare function settingsChanges(draft: SettingsDraft, saved: TranslationSettingsValues): TranslationSettingsSet;
|
|
2
12
|
/**
|
|
3
|
-
* Settings
|
|
4
|
-
*
|
|
13
|
+
* Settings → Localization → Translation Services, on every host and every CMS: which translation services are set up
|
|
14
|
+
* (each with the fields its service declares), and how translation runs.
|
|
5
15
|
*/
|
|
6
|
-
export declare function TranslationServicesPanel():
|
|
16
|
+
export declare function TranslationServicesPanel(): import("react").JSX.Element;
|
|
7
17
|
export default TranslationServicesPanel;
|
|
8
18
|
//# sourceMappingURL=TranslationServicesPanel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslationServicesPanel.d.ts","sourceRoot":"","sources":["../../src/settings/TranslationServicesPanel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TranslationServicesPanel.d.ts","sourceRoot":"","sources":["../../src/settings/TranslationServicesPanel.tsx"],"names":[],"mappings":"AAmCA,OAAO,EAEL,KAAK,sBAAsB,EAI3B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC/B,MAAM,wCAAwC,CAAC;AAOhD,4DAA4D;AAC5D,KAAK,aAAa,GAAG;IACnB,4BAA4B,EAAE,MAAM,CAAC;IACrC,yBAAyB,EAAE,MAAM,CAAC;IAClC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;IACtB,oBAAoB,EAAE,sBAAsB,EAAE,CAAC;CAChD,CAAC;AAqBF,+DAA+D;AAC/D,wBAAgB,eAAe,CAC7B,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,yBAAyB,GAC/B,sBAAsB,CAqBxB;AAuED;;;GAGG;AACH,wBAAgB,wBAAwB,gCAuevC;eAEc,wBAAwB"}
|