@parhelia/localization 0.4.13170 → 0.4.13193
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 +45 -24
- 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 +44 -27
- package/dist/services/translationService.d.ts.map +1 -1
- package/dist/services/translationService.js +38 -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 +2 -2
- package/dist/steps/ItemSelectionTree.d.ts.map +1 -1
- package/dist/steps/ItemSelectionTree.js +132 -47
- package/dist/steps/ProviderStep.d.ts.map +1 -1
- package/dist/steps/ProviderStep.js +55 -42
- package/dist/steps/ServiceLanguageSelectionStep.d.ts +1 -1
- package/dist/steps/ServiceLanguageSelectionStep.d.ts.map +1 -1
- package/dist/steps/ServiceLanguageSelectionStep.js +127 -176
- package/dist/steps/types.d.ts +3 -3
- package/dist/steps/types.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.d.ts +37 -0
- package/dist/translation-center/TranslationBatches.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.js +255 -113
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -15
|
@@ -1,291 +1,214 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState, } from "react";
|
|
3
|
+
import { AlertCircle, Languages, Pencil, Plus, Save, SlidersHorizontal, X, } from "lucide-react";
|
|
4
|
+
import { Alert, AlertDescription, Badge, Button, DeleteButton, Input, LoadingState, SettingsCard, SettingsEmptyState, SettingsList, SettingsListItem, SettingsPanelLayout, SettingsRow, SimpleIconButton, Switch, settingsText, useEditContext, } from "@parhelia/core";
|
|
5
|
+
import { translationSettingsService, } from "../services/translationSettingsService";
|
|
6
|
+
import { TranslationProviderDialog } from "./TranslationProviderDialog";
|
|
7
|
+
import { ExcludedContentTypeDialog } from "./ExcludedContentTypeDialog";
|
|
8
|
+
const errorText = (error, fallback) => error instanceof Error ? error.message : fallback;
|
|
9
|
+
const draftOf = (values) => ({
|
|
10
|
+
maxConcurrentTranslationJobs: String(values.maxConcurrentTranslationJobs),
|
|
11
|
+
maxConcurrentJobsPerBatch: String(values.maxConcurrentJobsPerBatch),
|
|
12
|
+
skipSharedFields: values.skipSharedFields,
|
|
13
|
+
displayCosts: values.displayCosts,
|
|
14
|
+
excludedContentTypes: values.excludedContentTypes,
|
|
15
|
+
});
|
|
16
|
+
/** An excluded type by its name; a key no mounted store knows any more by the key, so it can still be removed. */
|
|
17
|
+
const typeLabel = (type) => type.known ? type.name : `Unknown type ${type.key}`;
|
|
18
|
+
const keysOf = (types) => types.map((type) => type.key);
|
|
19
|
+
const sameKeys = (a, b) => keysOf(a).join("\n") === keysOf(b).join("\n");
|
|
20
|
+
/** What a save sends: only the settings the person changed. */
|
|
21
|
+
export function settingsChanges(draft, saved) {
|
|
22
|
+
const set = {};
|
|
23
|
+
const jobs = Number(draft.maxConcurrentTranslationJobs);
|
|
24
|
+
if (draft.maxConcurrentTranslationJobs.trim() !== "" &&
|
|
25
|
+
jobs !== saved.maxConcurrentTranslationJobs)
|
|
26
|
+
set.maxConcurrentTranslationJobs = jobs;
|
|
27
|
+
const perBatch = Number(draft.maxConcurrentJobsPerBatch);
|
|
28
|
+
if (draft.maxConcurrentJobsPerBatch.trim() !== "" &&
|
|
29
|
+
perBatch !== saved.maxConcurrentJobsPerBatch)
|
|
30
|
+
set.maxConcurrentJobsPerBatch = perBatch;
|
|
31
|
+
if (draft.skipSharedFields !== saved.skipSharedFields)
|
|
32
|
+
set.skipSharedFields = draft.skipSharedFields;
|
|
33
|
+
if (draft.displayCosts !== saved.displayCosts)
|
|
34
|
+
set.displayCosts = draft.displayCosts;
|
|
35
|
+
if (!sameKeys(draft.excludedContentTypes, saved.excludedContentTypes))
|
|
36
|
+
set.excludedContentTypes = keysOf(draft.excludedContentTypes);
|
|
37
|
+
return set;
|
|
38
|
+
}
|
|
19
39
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
40
|
+
* One translation setting as a settings row. Whether the customer set it comes from the server (`customized`), never
|
|
41
|
+
* from comparing values here: a customized setting shows "Customized" and a reset, which removes the customer's value so
|
|
42
|
+
* the setting follows the shipped default again (the way System Settings shows its root settings).
|
|
43
|
+
*/
|
|
44
|
+
function TranslationSettingRow({ name, page, busy, onReset, label, htmlFor, hint, toggle, control, children, }) {
|
|
45
|
+
const customized = page.customized.includes(name);
|
|
46
|
+
return (_jsx(SettingsRow, { "data-testid": `translation-setting-state-${name}`, "data-customized": customized ? "true" : "false", htmlFor: htmlFor, label: _jsxs("span", { className: "flex items-center gap-2", children: [label, customized && _jsx("span", { className: settingsText.meta, children: "Customized" })] }), description: hint || customized ? (_jsxs(_Fragment, { children: [hint, customized && (_jsx("div", { children: _jsx(Button, { variant: "link", size: "xxs", className: "h-auto px-0 text-xs", onClick: () => onReset(name), disabled: busy, "data-testid": `translation-setting-reset-${name}`, children: "Reset to default" }) }))] })) : undefined, toggle: toggle, control: control, children: children }));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Settings → Localization → Translation Services, on every host and every CMS: which translation services are set up
|
|
50
|
+
* (each with the fields its service declares), and how translation runs.
|
|
22
51
|
*/
|
|
23
52
|
export function TranslationServicesPanel() {
|
|
24
53
|
const editContext = useEditContext();
|
|
25
|
-
const [
|
|
26
|
-
const [
|
|
27
|
-
const [
|
|
28
|
-
const [
|
|
29
|
-
const [
|
|
30
|
-
const [
|
|
31
|
-
const [
|
|
32
|
-
const [
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
54
|
+
const [page, setPage] = useState(null);
|
|
55
|
+
const [loadError, setLoadError] = useState(null);
|
|
56
|
+
const [providerError, setProviderError] = useState(null);
|
|
57
|
+
const [busyProvider, setBusyProvider] = useState(null);
|
|
58
|
+
const [editing, setEditing] = useState(null);
|
|
59
|
+
const [dialogError, setDialogError] = useState(null);
|
|
60
|
+
const [draft, setDraft] = useState(null);
|
|
61
|
+
const [settingsError, setSettingsError] = useState(null);
|
|
62
|
+
const [savingSettings, setSavingSettings] = useState(false);
|
|
63
|
+
const [typeDialog, setTypeDialog] = useState(false);
|
|
64
|
+
const [typeError, setTypeError] = useState(null);
|
|
65
|
+
const [readingType, setReadingType] = useState(false);
|
|
66
|
+
const apply = useCallback((next) => {
|
|
67
|
+
setPage(next);
|
|
68
|
+
setDraft(draftOf(next.settings));
|
|
41
69
|
}, []);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
let cancelled = false;
|
|
72
|
+
translationSettingsService
|
|
73
|
+
.get()
|
|
74
|
+
.then((next) => !cancelled && apply(next))
|
|
75
|
+
.catch((error) => !cancelled &&
|
|
76
|
+
setLoadError(errorText(error, "Failed to load the translation settings")));
|
|
77
|
+
return () => {
|
|
78
|
+
cancelled = true;
|
|
79
|
+
};
|
|
80
|
+
}, [apply]);
|
|
81
|
+
const changes = useMemo(() => (page && draft ? settingsChanges(draft, page.settings) : {}), [page, draft]);
|
|
82
|
+
const dirty = Object.keys(changes).length > 0;
|
|
83
|
+
if (loadError)
|
|
84
|
+
return (_jsx(SettingsPanelLayout, { testId: "translation-services-panel", children: _jsxs(Alert, { variant: "destructive", children: [_jsx(AlertCircle, { className: "h-4 w-4", strokeWidth: 1 }), _jsx(AlertDescription, { children: loadError })] }) }));
|
|
85
|
+
if (!page || !draft)
|
|
86
|
+
return (_jsx(SettingsPanelLayout, { testId: "translation-services-panel", children: _jsx(SettingsCard, { icon: _jsx(Languages, { strokeWidth: 1 }), title: "Translation providers", description: "The translation services of this installation. People can pick a service for translation once it is set up.", children: _jsx(LoadingState, { variant: "inline", message: "Loading translation settings" }) }) }));
|
|
87
|
+
const createProvider = async (provider) => {
|
|
88
|
+
setBusyProvider(provider.serviceName);
|
|
89
|
+
setProviderError(null);
|
|
53
90
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
setStructureState(result.data.data);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new Error(result.data.error ||
|
|
62
|
-
result.details ||
|
|
63
|
-
"Failed to read translation structure");
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
throw new Error(result.details || "Failed to read translation structure");
|
|
68
|
-
}
|
|
91
|
+
const next = await translationSettingsService.saveProvider(provider.serviceName, {});
|
|
92
|
+
apply(next);
|
|
93
|
+
setDialogError(null);
|
|
94
|
+
setEditing(next.providers.find((candidate) => candidate.serviceName === provider.serviceName) ?? null);
|
|
69
95
|
}
|
|
70
|
-
catch (
|
|
71
|
-
|
|
96
|
+
catch (error) {
|
|
97
|
+
setProviderError(errorText(error, "Failed to create the settings"));
|
|
72
98
|
}
|
|
73
99
|
finally {
|
|
74
|
-
|
|
100
|
+
setBusyProvider(null);
|
|
75
101
|
}
|
|
76
|
-
}
|
|
77
|
-
const
|
|
102
|
+
};
|
|
103
|
+
const saveProvider = async (values) => {
|
|
104
|
+
if (!editing)
|
|
105
|
+
return;
|
|
106
|
+
setBusyProvider(editing.serviceName);
|
|
107
|
+
setDialogError(null);
|
|
78
108
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const result = await ensureTranslationStructure(structureSettings);
|
|
82
|
-
if (result.type === "success" && result.data) {
|
|
83
|
-
if (result.data.success && result.data.data) {
|
|
84
|
-
setStructureState(result.data.data);
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
throw new Error(result.data.error ||
|
|
88
|
-
result.details ||
|
|
89
|
-
"Failed to create translation structure");
|
|
90
|
-
}
|
|
91
|
-
throw new Error(result.details || "Failed to create translation structure");
|
|
109
|
+
apply(await translationSettingsService.saveProvider(editing.serviceName, values));
|
|
110
|
+
setEditing(null);
|
|
92
111
|
}
|
|
93
|
-
catch (
|
|
94
|
-
|
|
95
|
-
return false;
|
|
112
|
+
catch (error) {
|
|
113
|
+
setDialogError(errorText(error, "Failed to save the provider"));
|
|
96
114
|
}
|
|
97
115
|
finally {
|
|
98
|
-
|
|
116
|
+
setBusyProvider(null);
|
|
99
117
|
}
|
|
100
|
-
}
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (result.type === "success" && result.data) {
|
|
108
|
-
if (!result.data.success || !result.data.data) {
|
|
109
|
-
throw new Error(result.data.error ||
|
|
110
|
-
result.details ||
|
|
111
|
-
"Failed to load translation services. The translation API may not be available.");
|
|
112
|
-
}
|
|
113
|
-
const availableServices = result.data.data;
|
|
114
|
-
const serviceStates = availableServices.map((svc) => ({
|
|
115
|
-
...svc,
|
|
116
|
-
creating: false,
|
|
117
|
-
deleting: false,
|
|
118
|
-
}));
|
|
119
|
-
setServices(serviceStates);
|
|
120
|
-
setState(availableServices.length === 0 ? "error" : "success");
|
|
118
|
+
};
|
|
119
|
+
const deleteProvider = (provider) => {
|
|
120
|
+
const remove = async () => {
|
|
121
|
+
setBusyProvider(provider.serviceName);
|
|
122
|
+
setProviderError(null);
|
|
123
|
+
try {
|
|
124
|
+
apply(await translationSettingsService.deleteProvider(provider.serviceName));
|
|
121
125
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
setError(result.details ||
|
|
125
|
-
"Failed to load translation services. The translation API may not be available.");
|
|
126
|
+
catch (error) {
|
|
127
|
+
setProviderError(errorText(error, "Failed to delete the settings"));
|
|
126
128
|
}
|
|
129
|
+
finally {
|
|
130
|
+
setBusyProvider(null);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const message = `Delete the settings of "${provider.displayName}"? People can no longer pick it for translation until it is set up again.`;
|
|
134
|
+
if (!editContext?.confirm) {
|
|
135
|
+
if (window.confirm(message))
|
|
136
|
+
void remove();
|
|
137
|
+
return;
|
|
127
138
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const createSettings = useCallback(async (serviceName, templateId) => {
|
|
139
|
+
editContext.confirm({
|
|
140
|
+
header: "Delete translation provider settings",
|
|
141
|
+
message,
|
|
142
|
+
acceptLabel: "Delete",
|
|
143
|
+
showCancel: true,
|
|
144
|
+
accept: remove,
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
const saveSettings = async (set, reset = []) => {
|
|
148
|
+
setSavingSettings(true);
|
|
149
|
+
setSettingsError(null);
|
|
140
150
|
try {
|
|
141
|
-
|
|
142
|
-
setError(null);
|
|
143
|
-
const language = editContext?.item?.language ??
|
|
144
|
-
editContext?.currentItemDescriptor?.language ??
|
|
145
|
-
"en";
|
|
146
|
-
const result = await createProviderSettings(serviceName, templateId, language, structureSettings);
|
|
147
|
-
if (result.type === "success" && result.data) {
|
|
148
|
-
const payload = result.data.data;
|
|
149
|
-
if (result.data.success && payload) {
|
|
150
|
-
const settingsItemId = payload.itemId;
|
|
151
|
-
setServices((prev) => prev.map((s) => s.serviceName === serviceName
|
|
152
|
-
? {
|
|
153
|
-
...s,
|
|
154
|
-
isConfigured: true,
|
|
155
|
-
creating: false,
|
|
156
|
-
settingsItemId,
|
|
157
|
-
}
|
|
158
|
-
: s));
|
|
159
|
-
// Reload data to ensure consistency
|
|
160
|
-
setTimeout(() => loadData(), 500);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
throw new Error(result.data.error ||
|
|
164
|
-
result.details ||
|
|
165
|
-
"Failed to create settings");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
throw new Error(result.details || "Failed to create settings");
|
|
170
|
-
}
|
|
151
|
+
apply(await translationSettingsService.saveSettings(set, reset));
|
|
171
152
|
}
|
|
172
|
-
catch (
|
|
173
|
-
|
|
174
|
-
// Provide more helpful error messages for common issues
|
|
175
|
-
let displayMessage = errorMessage;
|
|
176
|
-
if (errorMessage.includes("Translation Providers folder not found") ||
|
|
177
|
-
errorMessage.includes("Translation folder not found")) {
|
|
178
|
-
displayMessage =
|
|
179
|
-
"The required folder structure is missing. Configure and create the parent items in the Settings section above.";
|
|
180
|
-
}
|
|
181
|
-
else if (errorMessage.includes("already exists")) {
|
|
182
|
-
displayMessage = `Settings for ${serviceName} already exist. Please refresh the list.`;
|
|
183
|
-
// Reload data to show updated status
|
|
184
|
-
setTimeout(() => loadData(), 500);
|
|
185
|
-
}
|
|
186
|
-
setError(`Failed to create settings for ${serviceName}: ${displayMessage}`);
|
|
187
|
-
setServices((prev) => prev.map((s) => s.serviceName === serviceName ? { ...s, creating: false } : s));
|
|
153
|
+
catch (error) {
|
|
154
|
+
setSettingsError(errorText(error, "Failed to save the translation settings"));
|
|
188
155
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
156
|
+
finally {
|
|
157
|
+
setSavingSettings(false);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const addContentType = async (store, itemId) => {
|
|
161
|
+
setReadingType(true);
|
|
162
|
+
setTypeError(null);
|
|
193
163
|
try {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
"en";
|
|
201
|
-
const deleted = await editContext.operations.deleteItems([
|
|
202
|
-
{
|
|
203
|
-
id: service.settingsItemId,
|
|
204
|
-
language,
|
|
205
|
-
version: 0,
|
|
206
|
-
},
|
|
207
|
-
]);
|
|
208
|
-
if (deleted) {
|
|
209
|
-
if (selectedConfigTarget?.key === `service:${service.serviceName}` ||
|
|
210
|
-
selectedConfigTarget?.itemId === service.settingsItemId) {
|
|
211
|
-
setSelectedConfigTarget(null);
|
|
164
|
+
const type = await translationSettingsService.contentTypeOf(store, itemId);
|
|
165
|
+
setDraft((current) => current &&
|
|
166
|
+
!current.excludedContentTypes.some((existing) => existing.key === type.key)
|
|
167
|
+
? {
|
|
168
|
+
...current,
|
|
169
|
+
excludedContentTypes: [...current.excludedContentTypes, type],
|
|
212
170
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
...s,
|
|
216
|
-
isConfigured: false,
|
|
217
|
-
settingsItemId: undefined,
|
|
218
|
-
deleting: false,
|
|
219
|
-
}
|
|
220
|
-
: s));
|
|
221
|
-
await loadData();
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
setServices((prev) => prev.map((s) => s.serviceName === service.serviceName
|
|
225
|
-
? { ...s, deleting: false }
|
|
226
|
-
: s));
|
|
227
|
-
}
|
|
171
|
+
: current);
|
|
172
|
+
setTypeDialog(false);
|
|
228
173
|
}
|
|
229
|
-
catch (
|
|
230
|
-
|
|
231
|
-
`Failed to delete settings for ${service.displayName || service.serviceName}`);
|
|
232
|
-
setServices((prev) => prev.map((s) => s.serviceName === service.serviceName
|
|
233
|
-
? { ...s, deleting: false }
|
|
234
|
-
: s));
|
|
174
|
+
catch (error) {
|
|
175
|
+
setTypeError(errorText(error, "Failed to read the content type"));
|
|
235
176
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
const
|
|
241
|
-
const
|
|
242
|
-
const
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
name: "service-config",
|
|
275
|
-
defaultSize: 400,
|
|
276
|
-
content: (_jsx(ItemConfigPanel, { itemId: selectedConfigTarget.itemId, title: selectedConfigTarget.title, onClose: handleCloseConfig }, selectedConfigTarget.itemId)),
|
|
277
|
-
className: "overflow-hidden",
|
|
278
|
-
},
|
|
279
|
-
]
|
|
280
|
-
: [
|
|
281
|
-
{
|
|
282
|
-
name: "services-list",
|
|
283
|
-
defaultSize: "auto",
|
|
284
|
-
content: servicesListContent,
|
|
285
|
-
className: "overflow-hidden",
|
|
286
|
-
},
|
|
287
|
-
];
|
|
288
|
-
const SplitterComponent = Splitter;
|
|
289
|
-
return (_jsx(SplitterComponent, { panels: panels, localStorageKey: "translation-services-panel-splitter", direction: editContext?.isMobile ? "vertical" : "horizontal", className: "h-full w-full" }));
|
|
177
|
+
finally {
|
|
178
|
+
setReadingType(false);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const services = page.providers;
|
|
182
|
+
const configuredCount = services.filter((service) => service.configured).length;
|
|
183
|
+
const languageName = (code) => page.languages.find((language) => language.code === code)?.name ?? code;
|
|
184
|
+
const settingRow = {
|
|
185
|
+
page,
|
|
186
|
+
busy: savingSettings,
|
|
187
|
+
onReset: (reset) => void saveSettings({}, [reset]),
|
|
188
|
+
};
|
|
189
|
+
const removeType = (key) => setDraft({
|
|
190
|
+
...draft,
|
|
191
|
+
excludedContentTypes: draft.excludedContentTypes.filter((existing) => existing.key !== key),
|
|
192
|
+
});
|
|
193
|
+
return (_jsxs(SettingsPanelLayout, { testId: "translation-services-panel", children: [_jsx(SettingsCard, { icon: _jsx(Languages, { strokeWidth: 1 }), title: `Translation providers (${configuredCount} of ${services.length} set up)`, description: "The translation services of this installation. People can pick a service for translation once it is set up.", children: _jsxs("div", { className: "flex flex-col gap-4", "data-testid": "translation-services-providers", children: [providerError && (_jsxs(Alert, { variant: "destructive", "data-testid": "translation-services-error", children: [_jsx(AlertCircle, { className: "h-4 w-4", strokeWidth: 1 }), _jsx(AlertDescription, { children: providerError })] })), services.length === 0 ? (_jsx(SettingsEmptyState, { icon: Languages, title: "This installation has no translation services." })) : (_jsx(SettingsList, { children: services.map((service) => {
|
|
194
|
+
const languages = service.fields.find((field) => field.type === "languages")?.value;
|
|
195
|
+
return (_jsx(SettingsListItem, { "data-testid": "translation-provider", "data-service-name": service.serviceName, icon: _jsx(Languages, { strokeWidth: 1 }), title: service.displayName, badges: service.displayName !== service.serviceName && (_jsx("span", { className: settingsText.meta, children: service.serviceName })), meta: _jsx("div", { className: "truncate", "data-testid": "translation-provider-summary", children: !service.configured
|
|
196
|
+
? "Not set up"
|
|
197
|
+
: languages
|
|
198
|
+
? `Languages: ${languages.split("|").map(languageName).join(", ")}`
|
|
199
|
+
: "Set up" }), actions: service.configured ? (_jsxs(_Fragment, { children: [_jsx(SimpleIconButton, { label: `Edit the settings of ${service.displayName}`, icon: _jsx(Pencil, { className: "size-4", strokeWidth: 1 }), className: "size-7 p-0", onClick: () => {
|
|
200
|
+
setDialogError(null);
|
|
201
|
+
setEditing(service);
|
|
202
|
+
}, disabled: busyProvider !== null, "data-testid": "translation-provider-edit" }), _jsx(DeleteButton, { label: `Delete the settings of ${service.displayName}`, onClick: () => deleteProvider(service), disabled: busyProvider !== null, "data-testid": "translation-provider-delete" })] })) : (_jsxs(Button, { size: "sm", variant: "outline", onClick: () => void createProvider(service), disabled: busyProvider !== null, "data-testid": "translation-provider-create", children: [_jsx(Plus, { className: "h-4 w-4", strokeWidth: 1 }), "Set up"] })) }, service.serviceName));
|
|
203
|
+
}) }))] }) }), _jsx(SettingsCard, { icon: _jsx(SlidersHorizontal, { strokeWidth: 1 }), title: "Translation settings", description: "How translation runs, for every translation service.", children: _jsxs("div", { "data-testid": "translation-settings-section", children: [_jsxs("div", { children: [_jsx(TranslationSettingRow, { ...settingRow, name: "maxConcurrentTranslationJobs", label: "Jobs at once", htmlFor: "translation-setting-maxConcurrentTranslationJobs", hint: `How many translation jobs run at the same time. Default: ${page.defaults.maxConcurrentTranslationJobs}.`, control: _jsx(Input, { id: "translation-setting-maxConcurrentTranslationJobs", type: "number", min: 1, className: "w-28", value: draft.maxConcurrentTranslationJobs, onChange: (event) => setDraft({
|
|
204
|
+
...draft,
|
|
205
|
+
maxConcurrentTranslationJobs: event.target.value,
|
|
206
|
+
}), "data-testid": "translation-setting-maxConcurrentTranslationJobs" }) }), _jsx(TranslationSettingRow, { ...settingRow, name: "maxConcurrentJobsPerBatch", label: "Jobs at once per batch", htmlFor: "translation-setting-maxConcurrentJobsPerBatch", hint: `How many jobs of one batch run at the same time; 0 sets no limit. Default: ${page.defaults.maxConcurrentJobsPerBatch}.`, control: _jsx(Input, { id: "translation-setting-maxConcurrentJobsPerBatch", type: "number", min: 0, className: "w-28", value: draft.maxConcurrentJobsPerBatch, onChange: (event) => setDraft({
|
|
207
|
+
...draft,
|
|
208
|
+
maxConcurrentJobsPerBatch: event.target.value,
|
|
209
|
+
}), "data-testid": "translation-setting-maxConcurrentJobsPerBatch" }) }), _jsx(TranslationSettingRow, { ...settingRow, name: "skipSharedFields", label: "Skip fields that are the same in all languages", htmlFor: "translation-setting-skipSharedFields", toggle: _jsx(Switch, { id: "translation-setting-skipSharedFields", checked: draft.skipSharedFields, onCheckedChange: (checked) => setDraft({ ...draft, skipSharedFields: checked }), "data-testid": "translation-setting-skipSharedFields" }) }), _jsx(TranslationSettingRow, { ...settingRow, name: "displayCosts", label: "Show translation costs", htmlFor: "translation-setting-displayCosts", toggle: _jsx(Switch, { id: "translation-setting-displayCosts", checked: draft.displayCosts, onCheckedChange: (checked) => setDraft({ ...draft, displayCosts: checked }), "data-testid": "translation-setting-displayCosts" }) }), _jsxs(TranslationSettingRow, { ...settingRow, name: "excludedContentTypes", label: "Content types that are not translated", hint: "Items of these types, and of types based on them, are left out of translation.", control: _jsxs(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
210
|
+
setTypeError(null);
|
|
211
|
+
setTypeDialog(true);
|
|
212
|
+
}, "data-testid": "translation-excluded-type-open", children: [_jsx(Plus, { className: "h-4 w-4", strokeWidth: 1 }), "Add content type"] }), children: [draft.excludedContentTypes.length === 0 && (_jsx("p", { className: settingsText.meta, children: "None: every content type is translated." })), _jsx("ul", { className: "flex flex-wrap gap-1.5 empty:hidden", "data-testid": "translation-setting-excludedContentTypes", children: draft.excludedContentTypes.map((type) => (_jsx("li", { className: "contents", children: _jsxs(Badge, { variant: type.known ? "secondary" : "warning", className: "pr-1", "data-testid": "translation-excluded-type", "data-type-key": type.key, "data-known": type.known, children: [typeLabel(type), _jsx("button", { type: "button", "aria-label": `Translate ${typeLabel(type)} again`, className: "flex cursor-pointer items-center rounded-sm opacity-70 hover:opacity-100", onClick: () => removeType(type.key), children: _jsx(X, { className: "size-3", strokeWidth: 1 }) })] }) }, type.key))) })] })] }), settingsError && (_jsx("p", { className: `mt-4 ${settingsText.error}`, role: "alert", "data-testid": "translation-settings-error", children: settingsError })), _jsxs("div", { className: "border-border-default mt-4 flex justify-end gap-2 border-t pt-4", children: [dirty && (_jsx(Button, { size: "sm", variant: "outline", onClick: () => setDraft(draftOf(page.settings)), disabled: savingSettings, children: "Discard changes" })), _jsxs(Button, { size: "sm", onClick: () => void saveSettings(changes), disabled: !dirty || savingSettings, "data-testid": "translation-settings-save", children: [_jsx(Save, { className: "h-4 w-4", strokeWidth: 1 }), "Save"] })] })] }) }), _jsx(TranslationProviderDialog, { provider: editing, saving: busyProvider !== null, error: dialogError, onOpenChange: (open) => !open && setEditing(null), onSave: (values) => void saveProvider(values) }, editing?.serviceName ?? "closed"), _jsx(ExcludedContentTypeDialog, { open: typeDialog, saving: readingType, error: typeError, onOpenChange: setTypeDialog, onPick: (store, itemId) => void addContentType(store, itemId) })] }));
|
|
290
213
|
}
|
|
291
214
|
export default TranslationServicesPanel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationSetupStep.d.ts","sourceRoot":"","sources":["../../src/setup/LocalizationSetupStep.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAgCzE,wBAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"LocalizationSetupStep.d.ts","sourceRoot":"","sources":["../../src/setup/LocalizationSetupStep.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAgCzE,wBAAgB,qBAAqB,sBAmPpC;eAEc,qBAAqB"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React, { useCallback, useState } from "react";
|
|
3
|
-
import { Card, Button
|
|
3
|
+
import { Card, Button } from "@parhelia/core";
|
|
4
4
|
import { CheckCircle as LucideCheckCircle, AlertCircle as LucideAlertCircle, Languages as LucideLanguages, RefreshCw as LucideRefreshCw, Plus as LucidePlus, } from "lucide-react";
|
|
5
|
-
import { getAvailableTranslationServices,
|
|
5
|
+
import { getAvailableTranslationServices, } from "../services/translationService";
|
|
6
|
+
import { translationSettingsService } from "../services/translationSettingsService";
|
|
6
7
|
const CheckCircleIcon = LucideCheckCircle;
|
|
7
8
|
const AlertCircleIcon = LucideAlertCircle;
|
|
8
9
|
const LanguagesIcon = LucideLanguages;
|
|
9
10
|
const RefreshCwIcon = LucideRefreshCw;
|
|
10
11
|
const PlusIcon = LucidePlus;
|
|
11
12
|
export function LocalizationSetupStep() {
|
|
12
|
-
const editContext = useEditContext();
|
|
13
13
|
const [state, setState] = useState("checking");
|
|
14
14
|
const [error, setError] = useState(null);
|
|
15
15
|
const [services, setServices] = useState([]);
|
|
@@ -49,7 +49,7 @@ export function LocalizationSetupStep() {
|
|
|
49
49
|
const totalCount = serviceStates.length;
|
|
50
50
|
if (configuredCount === 0) {
|
|
51
51
|
setState("error");
|
|
52
|
-
setError(`Found ${totalCount} translation service${totalCount !== 1 ? "s" : ""} in DI, but none have
|
|
52
|
+
setError(`Found ${totalCount} translation service${totalCount !== 1 ? "s" : ""} in DI, but none have settings items configured.`);
|
|
53
53
|
}
|
|
54
54
|
else if (configuredCount < totalCount) {
|
|
55
55
|
setState("partial");
|
|
@@ -71,47 +71,28 @@ export function LocalizationSetupStep() {
|
|
|
71
71
|
setError(e?.message || "Failed to check localization setup");
|
|
72
72
|
}
|
|
73
73
|
}, []);
|
|
74
|
-
const createSettings = useCallback(async (serviceName
|
|
74
|
+
const createSettings = useCallback(async (serviceName) => {
|
|
75
75
|
try {
|
|
76
76
|
setServices((prev) => prev.map((s) => s.serviceName === serviceName ? { ...s, creating: true } : s));
|
|
77
77
|
setError(null);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
setServices((prev) => prev.map((s) => s.serviceName === serviceName
|
|
85
|
-
? {
|
|
86
|
-
...s,
|
|
87
|
-
isConfigured: true,
|
|
88
|
-
creating: false,
|
|
89
|
-
settingsItemId: result.data?.data?.itemId,
|
|
90
|
-
}
|
|
91
|
-
: s));
|
|
92
|
-
setTimeout(() => checkLocalization(), 500);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw new Error(result.data.error ||
|
|
96
|
-
result.details ||
|
|
97
|
-
"Failed to create settings");
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
throw new Error(result.details || "Failed to create settings");
|
|
102
|
-
}
|
|
78
|
+
// The Settings page's write path (every host and CMS): an empty save creates the provider's settings.
|
|
79
|
+
await translationSettingsService.saveProvider(serviceName, {});
|
|
80
|
+
setServices((prev) => prev.map((s) => s.serviceName === serviceName
|
|
81
|
+
? { ...s, isConfigured: true, creating: false }
|
|
82
|
+
: s));
|
|
83
|
+
setTimeout(() => checkLocalization(), 500);
|
|
103
84
|
}
|
|
104
85
|
catch (e) {
|
|
105
86
|
setError(`Failed to create settings for ${serviceName}: ${e?.message || "Unknown error"}`);
|
|
106
87
|
setServices((prev) => prev.map((s) => s.serviceName === serviceName ? { ...s, creating: false } : s));
|
|
107
88
|
}
|
|
108
|
-
}, [
|
|
89
|
+
}, [checkLocalization]);
|
|
109
90
|
React.useEffect(() => {
|
|
110
91
|
checkLocalization();
|
|
111
92
|
}, [checkLocalization]);
|
|
112
93
|
const configuredCount = services.filter((s) => s.isConfigured).length;
|
|
113
94
|
const totalCount = services.length;
|
|
114
|
-
return (_jsx(Card, { icon: _jsx(LanguagesIcon, { strokeWidth: 1, className: "h-5 w-5" }), title: "Localization setup", description: "Verifies that translation services registered in DI have corresponding
|
|
95
|
+
return (_jsx(Card, { icon: _jsx(LanguagesIcon, { strokeWidth: 1, className: "h-5 w-5" }), title: "Localization setup", description: "Verifies that translation services registered in DI have corresponding settings items.", children: _jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-2", children: [statusIcon(state), _jsx("span", { className: "text-sm text-neutral-grey-100", children: state === "success"
|
|
115
96
|
? `All ${totalCount} translation service${totalCount !== 1 ? "s" : ""} configured`
|
|
116
97
|
: state === "partial"
|
|
117
98
|
? `${configuredCount} of ${totalCount} services configured`
|
|
@@ -122,6 +103,6 @@ export function LocalizationSetupStep() {
|
|
|
122
103
|
: "Checking..." })] }), _jsxs(Button, { size: "sm", variant: "outline", onClick: checkLocalization, children: [_jsx(RefreshCwIcon, { strokeWidth: 1, className: "h-4 w-4" }), "Recheck"] })] }), services.length > 0 && (_jsxs("div", { className: "space-y-2 rounded-lg border border-border-default bg-neutral-grey-5 p-3", children: [_jsx("div", { className: "text-xs font-medium text-neutral-grey-50 tracking-wide", children: "Translation Services" }), services.map((service) => (_jsxs("div", { className: "flex items-center justify-between rounded-md bg-background p-3 shadow-sm border border-border-default", children: [_jsxs("div", { className: "flex items-center gap-2", children: [service.isConfigured ? (_jsx(CheckCircleIcon, { className: "h-3.5 w-3.5 text-[var(--color-feedback-green)]", strokeWidth: 1 })) : (_jsx(AlertCircleIcon, { className: "h-3.5 w-3.5 text-[var(--color-feedback-orange)]", strokeWidth: 1 })), _jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium text-neutral-grey-100", children: service.displayName || service.serviceName }), service.displayName &&
|
|
123
104
|
service.displayName !== service.serviceName && (_jsxs("div", { className: "text-xs text-neutral-grey-50", children: ["Service: ", service.serviceName] })), service.isConfigured &&
|
|
124
105
|
service.supportedLanguages &&
|
|
125
|
-
service.supportedLanguages.length > 0 && (_jsxs("div", { className: "text-xs text-neutral-grey-50", children: ["Languages: ", service.supportedLanguages.join(", ")] }))] })] }), !service.isConfigured && (_jsxs(Button, { size: "xs", onClick: () => createSettings(service.serviceName
|
|
106
|
+
service.supportedLanguages.length > 0 && (_jsxs("div", { className: "text-xs text-neutral-grey-50", children: ["Languages: ", service.supportedLanguages.join(", ")] }))] })] }), !service.isConfigured && (_jsxs(Button, { size: "xs", onClick: () => createSettings(service.serviceName), disabled: service.creating, title: `Create the settings of ${service.serviceName}`, children: [service.creating ? (_jsx(RefreshCwIcon, { strokeWidth: 1, className: "h-3 w-3 animate-spin" })) : (_jsx(PlusIcon, { strokeWidth: 1, className: "h-3 w-3" })), "Create Settings"] }))] }, service.serviceName)))] })), error && (_jsx("div", { className: "rounded-md border border-feedback-orange/30 bg-feedback-orange-light p-3 text-xs whitespace-pre-wrap text-feedback-orange", children: error }))] }) }));
|
|
126
107
|
}
|
|
127
108
|
export default LocalizationSetupStep;
|