@svadmin/ui 0.130.0 → 0.131.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.css +318 -0
- package/dist/app.theme.css +318 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AccessRevocationMatrix.svelte +425 -0
- package/dist/components/AccessRevocationMatrix.svelte.d.ts +27 -0
- package/dist/components/AudioVisualInspector.svelte +458 -0
- package/dist/components/AudioVisualInspector.svelte.d.ts +53 -0
- package/dist/components/AuditSnapshotCapture.svelte +328 -0
- package/dist/components/AuditSnapshotCapture.svelte.d.ts +28 -0
- package/dist/components/CannedResponsePicker.svelte +257 -0
- package/dist/components/CannedResponsePicker.svelte.d.ts +22 -0
- package/dist/components/ContentModerationCenter.svelte +166 -0
- package/dist/components/ContentModerationCenter.svelte.d.ts +11 -0
- package/dist/components/ContractClauseDiffViewer.svelte +566 -0
- package/dist/components/ContractClauseDiffViewer.svelte.d.ts +53 -0
- package/dist/components/DataImportPipeline.svelte +577 -0
- package/dist/components/DataImportPipeline.svelte.d.ts +35 -0
- package/dist/components/DataRetentionPolicyEditor.svelte +455 -0
- package/dist/components/DataRetentionPolicyEditor.svelte.d.ts +10 -0
- package/dist/components/ElectronicSealInspector.svelte +450 -0
- package/dist/components/ElectronicSealInspector.svelte.d.ts +72 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte +405 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte.d.ts +39 -0
- package/dist/components/FieldMappingBuilder.svelte +393 -0
- package/dist/components/FieldMappingBuilder.svelte.d.ts +39 -0
- package/dist/components/FilterBuilder.svelte +50 -34
- package/dist/components/FilterBuilder.svelte.d.ts +2 -0
- package/dist/components/GatewayRouteEditor.svelte +493 -0
- package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
- package/dist/components/I18nStudio.svelte +635 -0
- package/dist/components/I18nStudio.svelte.d.ts +23 -0
- package/dist/components/IpAccessRuleEditor.svelte +290 -0
- package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
- package/dist/components/IpWhitelistDrawer.svelte +94 -0
- package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
- package/dist/components/PrintDocument.svelte +95 -0
- package/dist/components/PrintDocument.svelte.d.ts +10 -0
- package/dist/components/PrintPreviewModal.svelte +52 -0
- package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
- package/dist/components/PrintTemplateDesigner.svelte +280 -0
- package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
- package/dist/components/RateLimitPolicyPanel.svelte +369 -0
- package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
- package/dist/components/SensitiveWordAuditor.svelte +368 -0
- package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
- package/dist/components/ServiceDeskTicketCard.svelte +297 -0
- package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
- package/dist/components/ShiftScheduler.svelte +490 -0
- package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
- package/dist/components/SslCertificateMonitorCard.svelte +309 -0
- package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
- package/dist/components/SsoConnectionStudio.svelte +784 -0
- package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
- package/dist/components/StepUpAuthModal.svelte +448 -0
- package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
- package/dist/components/TrafficTopologyInspector.svelte +361 -0
- package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
- package/dist/components/enterprise/filter-tree.js +1 -1
- package/dist/components/filter-i18n.d.ts +61 -0
- package/dist/components/filter-i18n.js +114 -0
- package/dist/components/ip-access-rules.d.ts +24 -0
- package/dist/components/ip-access-rules.js +110 -0
- package/dist/components/moderation-utils.d.ts +45 -0
- package/dist/components/moderation-utils.js +74 -0
- package/dist/components/print-document.d.ts +3 -0
- package/dist/components/print-document.js +65 -0
- package/dist/components/print-utils.d.ts +44 -0
- package/dist/components/print-utils.js +68 -0
- package/dist/components/retention-utils.d.ts +31 -0
- package/dist/components/retention-utils.js +38 -0
- package/dist/components/sso-connection-presets.d.ts +2 -0
- package/dist/components/sso-connection-presets.js +59 -0
- package/dist/components/ui/sheet/sheet.svelte +3 -1
- package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +44 -0
- package/package.json +5 -4
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { addTranslations } from '@svadmin/core';
|
|
3
|
+
|
|
4
|
+
export interface I18nStudioProps {
|
|
5
|
+
/** Map of locale to translation dictionary records */
|
|
6
|
+
dictionaries?: Record<string, Record<string, string>>;
|
|
7
|
+
/** Active source locale for reference (default: 'zh-CN') */
|
|
8
|
+
sourceLocale?: string;
|
|
9
|
+
/** Active target locale being translated (default: 'en-US') */
|
|
10
|
+
targetLocale?: string;
|
|
11
|
+
/** Supported locales list */
|
|
12
|
+
locales?: string[];
|
|
13
|
+
/** Whether to allow hot-reloading translations directly into current runtime memory */
|
|
14
|
+
allowLiveApply?: boolean;
|
|
15
|
+
/** Callback when user saves all translation modifications */
|
|
16
|
+
onSave?: (dictionaries: Record<string, Record<string, string>>) => void | Promise<void>;
|
|
17
|
+
/** Callback when user live-applies translations */
|
|
18
|
+
onApplyLive?: (locale: string, dict: Record<string, string>) => void;
|
|
19
|
+
/** Callback when user exports dictionary */
|
|
20
|
+
onExport?: (locale: string, dict: Record<string, string>) => void;
|
|
21
|
+
/** Callback when user imports dictionary */
|
|
22
|
+
onImport?: (locale: string, dict: Record<string, string>) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
dictionaries = {},
|
|
27
|
+
sourceLocale = 'zh-CN',
|
|
28
|
+
targetLocale = 'en-US',
|
|
29
|
+
locales = ['zh-CN', 'en-US', 'ja-JP', 'fr-FR'],
|
|
30
|
+
allowLiveApply = true,
|
|
31
|
+
onSave,
|
|
32
|
+
onApplyLive,
|
|
33
|
+
onExport,
|
|
34
|
+
onImport,
|
|
35
|
+
}: I18nStudioProps = $props();
|
|
36
|
+
|
|
37
|
+
// Internal reactive copy of dictionaries
|
|
38
|
+
let localDictionaries = $state<Record<string, Record<string, string>>>({});
|
|
39
|
+
let activeSource = $derived(sourceLocale);
|
|
40
|
+
let activeTarget = $derived(targetLocale);
|
|
41
|
+
let searchQuery = $state('');
|
|
42
|
+
let selectedNamespace = $state('all');
|
|
43
|
+
let statusFilter = $state<'all' | 'missing' | 'modified'>('all');
|
|
44
|
+
let newKeyName = $state('');
|
|
45
|
+
let newSourceVal = $state('');
|
|
46
|
+
let isAddingKey = $state(false);
|
|
47
|
+
let importJsonText = $state('');
|
|
48
|
+
let showImportModal = $state(false);
|
|
49
|
+
let liveSuccessMessage = $state<string | null>(null);
|
|
50
|
+
let savedDictionaries = $state<Record<string, Record<string, string>>>({});
|
|
51
|
+
const initialTargetSnapshot = $derived(savedDictionaries[activeTarget] ?? {});
|
|
52
|
+
let isSaving = $state(false);
|
|
53
|
+
let errorMessage = $state<string | null>(null);
|
|
54
|
+
let previousInput: Record<string, Record<string, string>> | undefined;
|
|
55
|
+
let previousInputSnapshot = '';
|
|
56
|
+
let inputGeneration = 0;
|
|
57
|
+
|
|
58
|
+
function copyDictionaries(value: Record<string, Record<string, string>>): Record<string, Record<string, string>> {
|
|
59
|
+
return Object.fromEntries(Object.entries(value).map(([locale, dict]): [string, Record<string, string>] => [locale, { ...dict }]));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function translation(dict: Record<string, string>, key: string): string {
|
|
63
|
+
return Object.hasOwn(dict, key) ? (dict[key] ?? '') : '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
$effect(() => {
|
|
67
|
+
const incoming = copyDictionaries(dictionaries);
|
|
68
|
+
const snapshot = JSON.stringify(incoming);
|
|
69
|
+
// 其他属性更新触发 effect 时,不覆盖同一份输入对应的本地草稿。
|
|
70
|
+
if (dictionaries === previousInput && snapshot === previousInputSnapshot) return;
|
|
71
|
+
previousInput = dictionaries;
|
|
72
|
+
previousInputSnapshot = snapshot;
|
|
73
|
+
inputGeneration++;
|
|
74
|
+
localDictionaries = incoming;
|
|
75
|
+
savedDictionaries = copyDictionaries(incoming);
|
|
76
|
+
isSaving = false;
|
|
77
|
+
errorMessage = null;
|
|
78
|
+
liveSuccessMessage = null;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Ensure dictionaries have objects for selected locales
|
|
82
|
+
function ensureLocale(loc: string): Record<string, string> {
|
|
83
|
+
const existing = localDictionaries[loc];
|
|
84
|
+
if (Object.hasOwn(localDictionaries, loc) && existing) return existing;
|
|
85
|
+
localDictionaries[loc] = {};
|
|
86
|
+
return localDictionaries[loc];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// All combined keys across all locales
|
|
90
|
+
const allKeys = $derived.by(() => {
|
|
91
|
+
const keySet = new Set<string>();
|
|
92
|
+
for (const dict of Object.values(localDictionaries)) {
|
|
93
|
+
for (const k of Object.keys(dict)) {
|
|
94
|
+
keySet.add(k);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return Array.from(keySet).sort();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Extract unique namespaces (e.g., 'dashboard' from 'dashboard.title')
|
|
101
|
+
const namespaces = $derived.by(() => {
|
|
102
|
+
const nsSet = new Set<string>();
|
|
103
|
+
for (const k of allKeys) {
|
|
104
|
+
const parts = k.split('.');
|
|
105
|
+
if (parts.length > 1) {
|
|
106
|
+
nsSet.add(parts[0] ?? 'common');
|
|
107
|
+
} else {
|
|
108
|
+
nsSet.add('common');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return Array.from(nsSet).sort();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Filtered keys
|
|
115
|
+
const filteredKeys = $derived.by(() => {
|
|
116
|
+
const keys = allKeys;
|
|
117
|
+
const sourceDict = localDictionaries[activeSource] || {};
|
|
118
|
+
const targetDict = localDictionaries[activeTarget] || {};
|
|
119
|
+
|
|
120
|
+
return keys.filter((key) => {
|
|
121
|
+
// Namespace filter
|
|
122
|
+
if (selectedNamespace !== 'all') {
|
|
123
|
+
const ns = key.includes('.') ? key.split('.')[0] : 'common';
|
|
124
|
+
if (ns !== selectedNamespace) return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const sVal = translation(sourceDict, key);
|
|
128
|
+
const tVal = translation(targetDict, key);
|
|
129
|
+
|
|
130
|
+
// Search query filter
|
|
131
|
+
if (searchQuery.trim()) {
|
|
132
|
+
const q = searchQuery.toLowerCase();
|
|
133
|
+
const matchKey = key.toLowerCase().includes(q);
|
|
134
|
+
const matchSource = sVal.toLowerCase().includes(q);
|
|
135
|
+
const matchTarget = tVal.toLowerCase().includes(q);
|
|
136
|
+
if (!matchKey && !matchSource && !matchTarget) return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Status filter
|
|
140
|
+
const isMissing = !tVal || tVal.trim() === '';
|
|
141
|
+
const isModified = translation(initialTargetSnapshot, key) !== tVal;
|
|
142
|
+
|
|
143
|
+
if (statusFilter === 'missing' && !isMissing) return false;
|
|
144
|
+
if (statusFilter === 'modified' && !isModified) return false;
|
|
145
|
+
|
|
146
|
+
return true;
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Completion stats
|
|
151
|
+
const completionStats = $derived.by(() => {
|
|
152
|
+
const keys = allKeys;
|
|
153
|
+
if (keys.length === 0) return { total: 0, translated: 0, percent: 100 };
|
|
154
|
+
const targetDict = localDictionaries[activeTarget] || {};
|
|
155
|
+
let translatedCount = 0;
|
|
156
|
+
for (const k of keys) {
|
|
157
|
+
const value = translation(targetDict, k);
|
|
158
|
+
if (value.trim() !== '') {
|
|
159
|
+
translatedCount++;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const percent = Math.round((translatedCount / keys.length) * 100);
|
|
163
|
+
return {
|
|
164
|
+
total: keys.length,
|
|
165
|
+
translated: translatedCount,
|
|
166
|
+
percent,
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
function updateTargetTranslation(key: string, value: string) {
|
|
171
|
+
const dict = ensureLocale(activeTarget);
|
|
172
|
+
dict[key] = value;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function handleSaveAll() {
|
|
176
|
+
if (!onSave || isSaving) return;
|
|
177
|
+
isSaving = true;
|
|
178
|
+
errorMessage = null;
|
|
179
|
+
liveSuccessMessage = null;
|
|
180
|
+
const snapshot = copyDictionaries(localDictionaries);
|
|
181
|
+
const count = allKeys.length;
|
|
182
|
+
const generation = inputGeneration;
|
|
183
|
+
try {
|
|
184
|
+
await onSave(copyDictionaries(snapshot));
|
|
185
|
+
if (generation !== inputGeneration) return;
|
|
186
|
+
savedDictionaries = snapshot;
|
|
187
|
+
liveSuccessMessage = `Translations saved successfully (${count} keys)`;
|
|
188
|
+
} catch {
|
|
189
|
+
if (generation === inputGeneration) errorMessage = 'Translation save failed. Please retry.';
|
|
190
|
+
} finally {
|
|
191
|
+
if (generation === inputGeneration) isSaving = false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function handleLiveApply() {
|
|
196
|
+
const targetDict = { ...localDictionaries[activeTarget] };
|
|
197
|
+
// Directly inject into core runtime dictionary
|
|
198
|
+
addTranslations(activeTarget, targetDict);
|
|
199
|
+
onApplyLive?.(activeTarget, targetDict);
|
|
200
|
+
liveSuccessMessage = `Applied hot reload for [${activeTarget}] directly to runtime`;
|
|
201
|
+
setTimeout(() => {
|
|
202
|
+
liveSuccessMessage = null;
|
|
203
|
+
}, 3000);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function handleExport() {
|
|
207
|
+
const targetDict = { ...localDictionaries[activeTarget] };
|
|
208
|
+
onExport?.(activeTarget, targetDict);
|
|
209
|
+
const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(targetDict, null, 2));
|
|
210
|
+
const downloadAnchor = document.createElement('a');
|
|
211
|
+
downloadAnchor.setAttribute('href', dataStr);
|
|
212
|
+
downloadAnchor.setAttribute('download', `${activeTarget}-translations.json`);
|
|
213
|
+
document.body.appendChild(downloadAnchor);
|
|
214
|
+
downloadAnchor.click();
|
|
215
|
+
downloadAnchor.remove();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function handleImportSubmit() {
|
|
219
|
+
errorMessage = null;
|
|
220
|
+
liveSuccessMessage = null;
|
|
221
|
+
try {
|
|
222
|
+
const parsed: unknown = JSON.parse(importJsonText);
|
|
223
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
224
|
+
throw new Error('Expected a flat dictionary of strings');
|
|
225
|
+
}
|
|
226
|
+
const entries: [string, unknown][] = Object.entries(parsed);
|
|
227
|
+
const importedEntries: [string, string][] = [];
|
|
228
|
+
for (const [k, v] of entries) {
|
|
229
|
+
if (typeof v !== 'string') throw new Error('Dictionary values must be strings');
|
|
230
|
+
importedEntries.push([k, v]);
|
|
231
|
+
}
|
|
232
|
+
const imported = Object.fromEntries(importedEntries);
|
|
233
|
+
const dict = { ...localDictionaries[activeTarget], ...imported };
|
|
234
|
+
onImport?.(activeTarget, { ...dict });
|
|
235
|
+
localDictionaries = { ...localDictionaries, [activeTarget]: dict };
|
|
236
|
+
showImportModal = false;
|
|
237
|
+
importJsonText = '';
|
|
238
|
+
liveSuccessMessage = `Imported translations into [${activeTarget}]`;
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
liveSuccessMessage = null;
|
|
241
|
+
}, 3000);
|
|
242
|
+
} catch (e) {
|
|
243
|
+
errorMessage = `JSON import failed: ${e instanceof Error ? e.message : 'Invalid dictionary'}`;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function handleAddNewKey() {
|
|
248
|
+
if (!newKeyName.trim()) return;
|
|
249
|
+
const key = newKeyName.trim();
|
|
250
|
+
const sDict = ensureLocale(activeSource);
|
|
251
|
+
sDict[key] = newSourceVal;
|
|
252
|
+
const tDict = ensureLocale(activeTarget);
|
|
253
|
+
if (!tDict[key]) {
|
|
254
|
+
tDict[key] = '';
|
|
255
|
+
}
|
|
256
|
+
newKeyName = '';
|
|
257
|
+
newSourceVal = '';
|
|
258
|
+
isAddingKey = false;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function handleDeleteKey(key: string) {
|
|
262
|
+
const next: Record<string, Record<string, string>> = {};
|
|
263
|
+
for (const [locale, dict] of Object.entries(localDictionaries)) {
|
|
264
|
+
const { [key]: _removed, ...rest } = dict;
|
|
265
|
+
next[locale] = rest;
|
|
266
|
+
}
|
|
267
|
+
localDictionaries = next;
|
|
268
|
+
}
|
|
269
|
+
</script>
|
|
270
|
+
|
|
271
|
+
<div
|
|
272
|
+
class="flex flex-col gap-4 rounded-xl border border-border bg-card p-5 text-foreground shadow-sm"
|
|
273
|
+
data-svadmin-component="I18nStudio"
|
|
274
|
+
>
|
|
275
|
+
<!-- Studio Header -->
|
|
276
|
+
<div class="flex flex-wrap items-center justify-between gap-3 border-b border-border pb-4">
|
|
277
|
+
<div>
|
|
278
|
+
<div class="flex items-center gap-2">
|
|
279
|
+
<h2 class="text-lg font-semibold tracking-tight text-foreground">I18n Studio</h2>
|
|
280
|
+
<span class="rounded bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary">
|
|
281
|
+
{activeTarget}
|
|
282
|
+
</span>
|
|
283
|
+
</div>
|
|
284
|
+
<p class="text-xs text-muted-foreground">
|
|
285
|
+
Manage bilingual/multilingual dictionaries, verify translation completeness, and apply hot reloads.
|
|
286
|
+
</p>
|
|
287
|
+
</div>
|
|
288
|
+
|
|
289
|
+
<!-- Actions -->
|
|
290
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
291
|
+
<button
|
|
292
|
+
type="button"
|
|
293
|
+
class="inline-flex items-center rounded-lg border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted"
|
|
294
|
+
onclick={() => (isAddingKey = !isAddingKey)}
|
|
295
|
+
>
|
|
296
|
+
+ Add Key
|
|
297
|
+
</button>
|
|
298
|
+
|
|
299
|
+
<button
|
|
300
|
+
type="button"
|
|
301
|
+
class="inline-flex items-center rounded-lg border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted"
|
|
302
|
+
onclick={() => (showImportModal = true)}
|
|
303
|
+
>
|
|
304
|
+
Import JSON
|
|
305
|
+
</button>
|
|
306
|
+
|
|
307
|
+
<button
|
|
308
|
+
type="button"
|
|
309
|
+
class="inline-flex items-center rounded-lg border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted"
|
|
310
|
+
onclick={handleExport}
|
|
311
|
+
>
|
|
312
|
+
Export
|
|
313
|
+
</button>
|
|
314
|
+
|
|
315
|
+
{#if allowLiveApply}
|
|
316
|
+
<button
|
|
317
|
+
type="button"
|
|
318
|
+
class="inline-flex items-center rounded-lg bg-secondary px-3 py-1.5 text-xs font-medium text-secondary-foreground hover:bg-secondary/90"
|
|
319
|
+
onclick={handleLiveApply}
|
|
320
|
+
>
|
|
321
|
+
⚡ Hot Reload
|
|
322
|
+
</button>
|
|
323
|
+
{/if}
|
|
324
|
+
|
|
325
|
+
<button
|
|
326
|
+
type="button"
|
|
327
|
+
class="inline-flex items-center rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90"
|
|
328
|
+
onclick={handleSaveAll}
|
|
329
|
+
disabled={isSaving || !onSave}
|
|
330
|
+
>
|
|
331
|
+
Save Changes
|
|
332
|
+
</button>
|
|
333
|
+
</div>
|
|
334
|
+
</div>
|
|
335
|
+
|
|
336
|
+
<!-- Notification Banner -->
|
|
337
|
+
{#if errorMessage}
|
|
338
|
+
<p role="alert" class="text-xs text-destructive">{errorMessage}</p>
|
|
339
|
+
{/if}
|
|
340
|
+
|
|
341
|
+
{#if liveSuccessMessage}
|
|
342
|
+
<div
|
|
343
|
+
role="status"
|
|
344
|
+
class="flex items-center justify-between rounded-lg border border-success/30 bg-success/10 px-3 py-2 text-xs font-medium text-success"
|
|
345
|
+
>
|
|
346
|
+
<span>✓ {liveSuccessMessage}</span>
|
|
347
|
+
<button
|
|
348
|
+
type="button"
|
|
349
|
+
class="text-success hover:underline"
|
|
350
|
+
onclick={() => (liveSuccessMessage = null)}
|
|
351
|
+
>
|
|
352
|
+
Dismiss
|
|
353
|
+
</button>
|
|
354
|
+
</div>
|
|
355
|
+
{/if}
|
|
356
|
+
|
|
357
|
+
<!-- Add New Key Form -->
|
|
358
|
+
{#if isAddingKey}
|
|
359
|
+
<div class="flex flex-wrap items-end gap-3 rounded-lg border border-primary/20 bg-muted/40 p-3">
|
|
360
|
+
<div class="flex flex-1 flex-col gap-1 min-w-[200px]">
|
|
361
|
+
<label for="new-key-input" class="text-xs font-medium text-foreground">Translation Key (dot notation)</label>
|
|
362
|
+
<input
|
|
363
|
+
id="new-key-input"
|
|
364
|
+
type="text"
|
|
365
|
+
placeholder="e.g. auth.mfa.verifyButton"
|
|
366
|
+
bind:value={newKeyName}
|
|
367
|
+
class="rounded-md border border-border bg-background px-3 py-1.5 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
|
368
|
+
/>
|
|
369
|
+
</div>
|
|
370
|
+
<div class="flex flex-1 flex-col gap-1 min-w-[200px]">
|
|
371
|
+
<label for="new-source-input" class="text-xs font-medium text-foreground">Source Reference Value ({activeSource})</label>
|
|
372
|
+
<input
|
|
373
|
+
id="new-source-input"
|
|
374
|
+
type="text"
|
|
375
|
+
placeholder="e.g. 验证并登录"
|
|
376
|
+
bind:value={newSourceVal}
|
|
377
|
+
class="rounded-md border border-border bg-background px-3 py-1.5 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
|
378
|
+
/>
|
|
379
|
+
</div>
|
|
380
|
+
<div class="flex gap-2">
|
|
381
|
+
<button
|
|
382
|
+
type="button"
|
|
383
|
+
class="rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90"
|
|
384
|
+
onclick={handleAddNewKey}
|
|
385
|
+
>
|
|
386
|
+
Confirm Add
|
|
387
|
+
</button>
|
|
388
|
+
<button
|
|
389
|
+
type="button"
|
|
390
|
+
class="rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted"
|
|
391
|
+
onclick={() => (isAddingKey = false)}
|
|
392
|
+
>
|
|
393
|
+
Cancel
|
|
394
|
+
</button>
|
|
395
|
+
</div>
|
|
396
|
+
</div>
|
|
397
|
+
{/if}
|
|
398
|
+
|
|
399
|
+
<!-- Import Modal -->
|
|
400
|
+
{#if showImportModal}
|
|
401
|
+
<div class="flex flex-col gap-2 rounded-lg border border-border bg-muted/30 p-3">
|
|
402
|
+
<div class="flex items-center justify-between">
|
|
403
|
+
<span class="text-xs font-semibold text-foreground">Paste JSON dictionary to merge into [{activeTarget}]</span>
|
|
404
|
+
<button
|
|
405
|
+
type="button"
|
|
406
|
+
class="text-xs text-muted-foreground hover:text-foreground"
|
|
407
|
+
onclick={() => (showImportModal = false)}
|
|
408
|
+
>
|
|
409
|
+
✕
|
|
410
|
+
</button>
|
|
411
|
+
</div>
|
|
412
|
+
<textarea
|
|
413
|
+
rows="4"
|
|
414
|
+
placeholder={`{\n "common.ok": "OK",\n "common.cancel": "Cancel"\n}`}
|
|
415
|
+
bind:value={importJsonText}
|
|
416
|
+
class="font-mono text-xs w-full rounded-md border border-border bg-background p-2 text-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
|
417
|
+
></textarea>
|
|
418
|
+
<div class="flex justify-end gap-2">
|
|
419
|
+
<button
|
|
420
|
+
type="button"
|
|
421
|
+
class="rounded-md bg-primary px-3 py-1 text-xs text-primary-foreground hover:bg-primary/90"
|
|
422
|
+
onclick={handleImportSubmit}
|
|
423
|
+
>
|
|
424
|
+
Merge Import
|
|
425
|
+
</button>
|
|
426
|
+
</div>
|
|
427
|
+
</div>
|
|
428
|
+
{/if}
|
|
429
|
+
|
|
430
|
+
<!-- Locales, Filters & Progress Stats -->
|
|
431
|
+
<div class="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border/60 bg-muted/20 p-3">
|
|
432
|
+
<!-- Language Pairs -->
|
|
433
|
+
<div class="flex items-center gap-2">
|
|
434
|
+
<span class="text-xs text-muted-foreground">Source:</span>
|
|
435
|
+
<select
|
|
436
|
+
value={activeSource}
|
|
437
|
+
onchange={(event) => { activeSource = (event.currentTarget as HTMLSelectElement).value; }}
|
|
438
|
+
class="svadmin-select svadmin-select--inline"
|
|
439
|
+
data-size="compact"
|
|
440
|
+
>
|
|
441
|
+
{#each locales as loc (loc)}
|
|
442
|
+
<option value={loc}>{loc}</option>
|
|
443
|
+
{/each}
|
|
444
|
+
</select>
|
|
445
|
+
|
|
446
|
+
<span class="text-xs text-muted-foreground">➔ Target:</span>
|
|
447
|
+
<select
|
|
448
|
+
value={activeTarget}
|
|
449
|
+
onchange={(event) => { activeTarget = (event.currentTarget as HTMLSelectElement).value; }}
|
|
450
|
+
class="svadmin-select svadmin-select--inline"
|
|
451
|
+
data-size="compact"
|
|
452
|
+
>
|
|
453
|
+
{#each locales as loc (loc)}
|
|
454
|
+
<option value={loc}>{loc}</option>
|
|
455
|
+
{/each}
|
|
456
|
+
</select>
|
|
457
|
+
</div>
|
|
458
|
+
|
|
459
|
+
<!-- Progress Indicator -->
|
|
460
|
+
<div class="flex items-center gap-3">
|
|
461
|
+
<div class="flex flex-col items-end">
|
|
462
|
+
<span class="text-xs font-semibold text-foreground">
|
|
463
|
+
{completionStats.percent}% Translated
|
|
464
|
+
</span>
|
|
465
|
+
<span class="text-[10px] text-muted-foreground">
|
|
466
|
+
{completionStats.translated} / {completionStats.total} keys completed
|
|
467
|
+
</span>
|
|
468
|
+
</div>
|
|
469
|
+
<div class="h-2 w-24 overflow-hidden rounded-full bg-muted">
|
|
470
|
+
<div
|
|
471
|
+
class="h-full bg-primary transition-all duration-300"
|
|
472
|
+
style={`width: ${completionStats.percent}%`}
|
|
473
|
+
></div>
|
|
474
|
+
</div>
|
|
475
|
+
</div>
|
|
476
|
+
</div>
|
|
477
|
+
|
|
478
|
+
<!-- Filter Bar -->
|
|
479
|
+
<div class="flex flex-wrap items-center justify-between gap-3">
|
|
480
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
481
|
+
<!-- Search Input -->
|
|
482
|
+
<div class="relative">
|
|
483
|
+
<input
|
|
484
|
+
type="search"
|
|
485
|
+
placeholder="Filter by key, source, or target..."
|
|
486
|
+
bind:value={searchQuery}
|
|
487
|
+
class="w-64 rounded-md border border-border bg-background px-3 py-1.5 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
|
488
|
+
/>
|
|
489
|
+
</div>
|
|
490
|
+
|
|
491
|
+
<!-- Namespace dropdown -->
|
|
492
|
+
<select
|
|
493
|
+
bind:value={selectedNamespace}
|
|
494
|
+
class="svadmin-select svadmin-select--inline"
|
|
495
|
+
data-size="compact"
|
|
496
|
+
>
|
|
497
|
+
<option value="all">All Namespaces</option>
|
|
498
|
+
{#each namespaces as ns (ns)}
|
|
499
|
+
<option value={ns}>{ns}</option>
|
|
500
|
+
{/each}
|
|
501
|
+
</select>
|
|
502
|
+
|
|
503
|
+
<!-- Status segment filters -->
|
|
504
|
+
<div class="flex rounded-md border border-border bg-muted/40 p-0.5">
|
|
505
|
+
<button
|
|
506
|
+
type="button"
|
|
507
|
+
class={`rounded px-2.5 py-1 text-xs font-medium transition ${
|
|
508
|
+
statusFilter === 'all'
|
|
509
|
+
? 'bg-background text-foreground shadow-sm'
|
|
510
|
+
: 'text-muted-foreground hover:text-foreground'
|
|
511
|
+
}`}
|
|
512
|
+
onclick={() => (statusFilter = 'all')}
|
|
513
|
+
>
|
|
514
|
+
All
|
|
515
|
+
</button>
|
|
516
|
+
<button
|
|
517
|
+
type="button"
|
|
518
|
+
class={`rounded px-2.5 py-1 text-xs font-medium transition ${
|
|
519
|
+
statusFilter === 'missing'
|
|
520
|
+
? 'bg-background text-foreground shadow-sm'
|
|
521
|
+
: 'text-muted-foreground hover:text-foreground'
|
|
522
|
+
}`}
|
|
523
|
+
onclick={() => (statusFilter = 'missing')}
|
|
524
|
+
>
|
|
525
|
+
Missing
|
|
526
|
+
</button>
|
|
527
|
+
<button
|
|
528
|
+
type="button"
|
|
529
|
+
class={`rounded px-2.5 py-1 text-xs font-medium transition ${
|
|
530
|
+
statusFilter === 'modified'
|
|
531
|
+
? 'bg-background text-foreground shadow-sm'
|
|
532
|
+
: 'text-muted-foreground hover:text-foreground'
|
|
533
|
+
}`}
|
|
534
|
+
onclick={() => (statusFilter = 'modified')}
|
|
535
|
+
>
|
|
536
|
+
Modified
|
|
537
|
+
</button>
|
|
538
|
+
</div>
|
|
539
|
+
</div>
|
|
540
|
+
|
|
541
|
+
<span class="text-xs text-muted-foreground">
|
|
542
|
+
Showing {filteredKeys.length} of {allKeys.length} entries
|
|
543
|
+
</span>
|
|
544
|
+
</div>
|
|
545
|
+
|
|
546
|
+
<!-- Dictionary List / Grid -->
|
|
547
|
+
<div class="overflow-x-auto rounded-lg border border-border">
|
|
548
|
+
<table class="w-full text-left text-xs text-foreground">
|
|
549
|
+
<thead class="border-b border-border bg-muted/50 text-[11px] font-medium uppercase text-muted-foreground">
|
|
550
|
+
<tr>
|
|
551
|
+
<th scope="col" class="py-2.5 pl-4 pr-3 w-1/4">Key & Namespace</th>
|
|
552
|
+
<th scope="col" class="px-3 py-2.5 w-1/3">Source: {activeSource}</th>
|
|
553
|
+
<th scope="col" class="px-3 py-2.5 w-1/3">Target: {activeTarget}</th>
|
|
554
|
+
<th scope="col" class="py-2.5 pl-3 pr-4 text-right">Actions</th>
|
|
555
|
+
</tr>
|
|
556
|
+
</thead>
|
|
557
|
+
<tbody class="divide-y divide-border bg-background">
|
|
558
|
+
{#if filteredKeys.length === 0}
|
|
559
|
+
<tr>
|
|
560
|
+
<td colspan="4" class="py-8 text-center text-xs text-muted-foreground">
|
|
561
|
+
No translation keys match the selected filters.
|
|
562
|
+
</td>
|
|
563
|
+
</tr>
|
|
564
|
+
{:else}
|
|
565
|
+
{#each filteredKeys as key (key)}
|
|
566
|
+
{@const sourceVal = translation(localDictionaries[activeSource] ?? {}, key)}
|
|
567
|
+
{@const targetVal = translation(localDictionaries[activeTarget] ?? {}, key)}
|
|
568
|
+
{@const isMissing = !targetVal || targetVal.trim() === ''}
|
|
569
|
+
{@const isModified = translation(initialTargetSnapshot, key) !== targetVal}
|
|
570
|
+
<tr class="hover:bg-muted/30 transition">
|
|
571
|
+
<!-- Key -->
|
|
572
|
+
<td class="py-3 pl-4 pr-3 align-top font-mono text-[11px]">
|
|
573
|
+
<div class="flex flex-col gap-1">
|
|
574
|
+
<span class="font-semibold text-foreground break-all">{key}</span>
|
|
575
|
+
<div class="flex items-center gap-1.5">
|
|
576
|
+
<span class="rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground">
|
|
577
|
+
{key.includes('.') ? key.split('.')[0] : 'common'}
|
|
578
|
+
</span>
|
|
579
|
+
{#if isMissing}
|
|
580
|
+
<span class="rounded bg-destructive/10 px-1.5 py-0.5 text-[10px] font-semibold text-destructive">
|
|
581
|
+
Missing
|
|
582
|
+
</span>
|
|
583
|
+
{:else if isModified}
|
|
584
|
+
<span class="rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning">
|
|
585
|
+
Draft
|
|
586
|
+
</span>
|
|
587
|
+
{/if}
|
|
588
|
+
</div>
|
|
589
|
+
</div>
|
|
590
|
+
</td>
|
|
591
|
+
|
|
592
|
+
<!-- Source Text -->
|
|
593
|
+
<td class="px-3 py-3 align-top text-muted-foreground">
|
|
594
|
+
<div class="max-h-24 overflow-y-auto whitespace-pre-wrap break-words">
|
|
595
|
+
{sourceVal || '—'}
|
|
596
|
+
</div>
|
|
597
|
+
</td>
|
|
598
|
+
|
|
599
|
+
<!-- Target Text Editable -->
|
|
600
|
+
<td class="px-3 py-3 align-top">
|
|
601
|
+
<textarea
|
|
602
|
+
rows="2"
|
|
603
|
+
value={targetVal}
|
|
604
|
+
oninput={(e) => updateTargetTranslation(key, e.currentTarget.value)}
|
|
605
|
+
placeholder={`Translate to ${activeTarget}...`}
|
|
606
|
+
class={`w-full rounded border px-2.5 py-1.5 text-xs text-foreground placeholder:text-muted-foreground/60 focus:outline-none focus:ring-1 focus:ring-primary ${
|
|
607
|
+
isMissing
|
|
608
|
+
? 'border-destructive/40 bg-destructive/5'
|
|
609
|
+
: isModified
|
|
610
|
+
? 'border-warning/50 bg-background'
|
|
611
|
+
: 'border-border bg-background'
|
|
612
|
+
}`}
|
|
613
|
+
></textarea>
|
|
614
|
+
</td>
|
|
615
|
+
|
|
616
|
+
<!-- Action Controls -->
|
|
617
|
+
<td class="py-3 pl-3 pr-4 text-right align-top">
|
|
618
|
+
<button
|
|
619
|
+
type="button"
|
|
620
|
+
class="rounded p-1 text-muted-foreground hover:bg-destructive/10 hover:text-destructive"
|
|
621
|
+
title="Delete key"
|
|
622
|
+
onclick={() => handleDeleteKey(key)}
|
|
623
|
+
>
|
|
624
|
+
<svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
625
|
+
<path d="M3 6h18M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2M10 11v6M14 11v6" />
|
|
626
|
+
</svg>
|
|
627
|
+
</button>
|
|
628
|
+
</td>
|
|
629
|
+
</tr>
|
|
630
|
+
{/each}
|
|
631
|
+
{/if}
|
|
632
|
+
</tbody>
|
|
633
|
+
</table>
|
|
634
|
+
</div>
|
|
635
|
+
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface I18nStudioProps {
|
|
2
|
+
/** Map of locale to translation dictionary records */
|
|
3
|
+
dictionaries?: Record<string, Record<string, string>>;
|
|
4
|
+
/** Active source locale for reference (default: 'zh-CN') */
|
|
5
|
+
sourceLocale?: string;
|
|
6
|
+
/** Active target locale being translated (default: 'en-US') */
|
|
7
|
+
targetLocale?: string;
|
|
8
|
+
/** Supported locales list */
|
|
9
|
+
locales?: string[];
|
|
10
|
+
/** Whether to allow hot-reloading translations directly into current runtime memory */
|
|
11
|
+
allowLiveApply?: boolean;
|
|
12
|
+
/** Callback when user saves all translation modifications */
|
|
13
|
+
onSave?: (dictionaries: Record<string, Record<string, string>>) => void | Promise<void>;
|
|
14
|
+
/** Callback when user live-applies translations */
|
|
15
|
+
onApplyLive?: (locale: string, dict: Record<string, string>) => void;
|
|
16
|
+
/** Callback when user exports dictionary */
|
|
17
|
+
onExport?: (locale: string, dict: Record<string, string>) => void;
|
|
18
|
+
/** Callback when user imports dictionary */
|
|
19
|
+
onImport?: (locale: string, dict: Record<string, string>) => void;
|
|
20
|
+
}
|
|
21
|
+
declare const I18nStudio: import("svelte").Component<I18nStudioProps, {}, "">;
|
|
22
|
+
type I18nStudio = ReturnType<typeof I18nStudio>;
|
|
23
|
+
export default I18nStudio;
|