i18 cleanup

This commit is contained in:
2026-02-25 18:31:50 +03:00
parent 99f19ac305
commit 5d42a6b930
48 changed files with 1431 additions and 808 deletions

View File

@@ -12,9 +12,10 @@
-->
<script>
// [SECTION: IMPORTS]
import { onMount } from 'svelte';
import { getSettings, updateGlobalSettings, getEnvironments, addEnvironment, updateEnvironment, deleteEnvironment, testEnvironmentConnection, updateEnvironmentSchedule } from '../lib/api';
import { addToast } from '../lib/toasts';
import { onMount } from 'svelte';
import { getSettings, updateGlobalSettings, getEnvironments, addEnvironment, updateEnvironment, deleteEnvironment, testEnvironmentConnection, updateEnvironmentSchedule } from '../lib/api';
import { addToast } from '../lib/toasts';
import { t } from '../lib/i18n';
// [/SECTION]
let settings = {
@@ -60,7 +61,7 @@
console.log("[Settings.loadSettings][Coherence:OK] Settings loaded.");
} catch (error) {
console.error("[Settings.loadSettings][Coherence:Failed] Failed to load settings:", error);
addToast('Failed to load settings', 'error');
addToast($t.settings?.load_failed, 'error');
}
}
// [/DEF:loadSettings:Function]
@@ -75,11 +76,11 @@
try {
console.log("[Settings.handleSaveGlobal][Action] Saving global settings.");
await updateGlobalSettings(settings.settings);
addToast('Global settings saved', 'success');
addToast($t.settings?.save_success, 'success');
console.log("[Settings.handleSaveGlobal][Coherence:OK] Global settings saved.");
} catch (error) {
console.error("[Settings.handleSaveGlobal][Coherence:Failed] Failed to save global settings:", error);
addToast('Failed to save global settings', 'error');
addToast($t.settings?.save_failed, 'error');
}
}
// [/DEF:handleSaveGlobal:Function]
@@ -95,17 +96,17 @@
console.log(`[Settings.handleAddOrUpdateEnv][Action] ${editingEnvId ? 'Updating' : 'Adding'} environment.`);
if (editingEnvId) {
await updateEnvironment(editingEnvId, newEnv);
addToast('Environment updated', 'success');
} else {
await addEnvironment(newEnv);
addToast('Environment added', 'success');
}
addToast($t.settings?.env_updated, 'success');
} else {
await addEnvironment(newEnv);
addToast($t.settings?.env_added, 'success');
}
resetEnvForm();
await loadSettings();
console.log("[Settings.handleAddOrUpdateEnv][Coherence:OK] Environment saved.");
} catch (error) {
console.error("[Settings.handleAddOrUpdateEnv][Coherence:Failed] Failed to save environment:", error);
addToast('Failed to save environment', 'error');
addToast($t.settings?.env_save_failed, 'error');
}
}
// [/DEF:handleAddOrUpdateEnv:Function]
@@ -118,16 +119,16 @@
* @param {string} id - The ID of the environment to delete.
*/
async function handleDeleteEnv(id) {
if (confirm('Are you sure you want to delete this environment?')) {
if (confirm($t.settings?.env_delete_confirm)) {
try {
console.log(`[Settings.handleDeleteEnv][Action] Deleting environment: ${id}`);
await deleteEnvironment(id);
addToast('Environment deleted', 'success');
addToast($t.settings?.env_deleted, 'success');
await loadSettings();
console.log("[Settings.handleDeleteEnv][Coherence:OK] Environment deleted.");
} catch (error) {
console.error("[Settings.handleDeleteEnv][Coherence:Failed] Failed to delete environment:", error);
addToast('Failed to delete environment', 'error');
addToast($t.settings?.env_delete_failed, 'error');
}
}
}
@@ -145,15 +146,15 @@
console.log(`[Settings.handleTestEnv][Action] Testing environment: ${id}`);
const result = await testEnvironmentConnection(id);
if (result.status === 'success') {
addToast('Connection successful', 'success');
addToast($t.settings?.connection_success, 'success');
console.log("[Settings.handleTestEnv][Coherence:OK] Connection successful.");
} else {
addToast(`Connection failed: ${result.message}`, 'error');
addToast($t.settings?.connection_failed?.replace('{error}', result.message || ''), 'error');
console.log("[Settings.handleTestEnv][Coherence:Failed] Connection failed.");
}
} catch (error) {
console.error("[Settings.handleTestEnv][Coherence:Failed] Error testing connection:", error);
addToast('Failed to test connection', 'error');
addToast($t.settings?.connection_test_failed, 'error');
}
}
// [/DEF:handleTestEnv:Function]
@@ -199,15 +200,15 @@
<!-- [SECTION: TEMPLATE] -->
<div class="container mx-auto p-4">
<h1 class="text-2xl font-bold mb-6">Settings</h1>
<h1 class="text-2xl font-bold mb-6">{$t.settings?.title}</h1>
<section class="mb-8 bg-white p-6 rounded shadow">
<h2 class="text-xl font-semibold mb-4">Global Settings</h2>
<h2 class="text-xl font-semibold mb-4">{$t.settings?.global_title}</h2>
<h3 class="text-lg font-medium mb-4 mt-6">Logging Configuration</h3>
<h3 class="text-lg font-medium mb-4 mt-6">{$t.settings?.logging}</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="log_level" class="block text-sm font-medium text-gray-700">Log Level</label>
<label for="log_level" class="block text-sm font-medium text-gray-700">{$t.settings?.log_level}</label>
<select id="log_level" bind:value={settings.settings.logging.level} class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2">
<option value="DEBUG">DEBUG</option>
<option value="INFO">INFO</option>
@@ -217,37 +218,37 @@
</select>
</div>
<div>
<label for="log_file_path" class="block text-sm font-medium text-gray-700">Log File Path</label>
<input type="text" id="log_file_path" bind:value={settings.settings.logging.file_path} placeholder="logs/app.log" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
<label for="log_file_path" class="block text-sm font-medium text-gray-700">{$t.settings?.log_file_path}</label>
<input type="text" id="log_file_path" bind:value={settings.settings.logging.file_path} placeholder={$t.settings?.log_file_path_placeholder} class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
</div>
<div>
<label for="log_max_bytes" class="block text-sm font-medium text-gray-700">Max File Size (MB)</label>
<label for="log_max_bytes" class="block text-sm font-medium text-gray-700">{$t.settings?.max_file_size_mb}</label>
<input type="number" id="log_max_bytes" bind:value={settings.settings.logging.max_bytes} min="1" step="1" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
</div>
<div>
<label for="log_backup_count" class="block text-sm font-medium text-gray-700">Backup Count</label>
<label for="log_backup_count" class="block text-sm font-medium text-gray-700">{$t.settings?.backup_count}</label>
<input type="number" id="log_backup_count" bind:value={settings.settings.logging.backup_count} min="1" step="1" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
</div>
<div class="md:col-span-2">
<label class="flex items-center">
<input type="checkbox" id="enable_belief_state" bind:checked={settings.settings.logging.enable_belief_state} class="h-4 w-4 text-blue-600 border-gray-300 rounded" />
<span class="ml-2 block text-sm text-gray-900">Enable Belief State Logging</span>
<span class="ml-2 block text-sm text-gray-900">{$t.settings?.enable_belief_state}</span>
</label>
</div>
</div>
<button on:click={handleSaveGlobal} class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 w-max mt-4">
Save Global Settings
{$t.settings?.save_global_settings}
</button>
</section>
<section class="mb-8 bg-white p-6 rounded shadow">
<h2 class="text-xl font-semibold mb-4">Superset Environments</h2>
<h2 class="text-xl font-semibold mb-4">{$t.settings?.env_title}</h2>
{#if settings.environments.length === 0}
<div class="mb-4 p-4 bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700">
<p class="font-bold">Warning</p>
<p>No Superset environments configured. You must add at least one environment to perform backups or migrations.</p>
<p class="font-bold">{$t.settings?.warning}</p>
<p>{$t.settings?.env_warning}</p>
</div>
{/if}
@@ -255,11 +256,11 @@
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">URL</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Username</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Default</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{$t.settings?.name}</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{$t.settings?.env_url}</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{$t.settings?.username}</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{$t.settings?.default}</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{$t.settings?.env_actions}</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@@ -268,11 +269,11 @@
<td class="px-6 py-4 whitespace-nowrap">{env.name}</td>
<td class="px-6 py-4 whitespace-nowrap">{env.url}</td>
<td class="px-6 py-4 whitespace-nowrap">{env.username}</td>
<td class="px-6 py-4 whitespace-nowrap">{env.is_default ? 'Yes' : 'No'}</td>
<td class="px-6 py-4 whitespace-nowrap">{env.is_default ? $t.common?.yes : $t.common?.no}</td>
<td class="px-6 py-4 whitespace-nowrap">
<button on:click={() => handleTestEnv(env.id)} class="text-green-600 hover:text-green-900 mr-4">Test</button>
<button on:click={() => editEnv(env)} class="text-indigo-600 hover:text-indigo-900 mr-4">Edit</button>
<button on:click={() => handleDeleteEnv(env.id)} class="text-red-600 hover:text-red-900">Delete</button>
<button on:click={() => handleTestEnv(env.id)} class="text-green-600 hover:text-green-900 mr-4">{$t.settings?.env_test}</button>
<button on:click={() => editEnv(env)} class="text-indigo-600 hover:text-indigo-900 mr-4">{$t.common?.edit}</button>
<button on:click={() => handleDeleteEnv(env.id)} class="text-red-600 hover:text-red-900">{$t.common?.delete}</button>
</td>
</tr>
{/each}
@@ -281,54 +282,54 @@
</div>
<div class="bg-gray-50 p-4 rounded">
<h3 class="text-lg font-medium mb-4">{editingEnvId ? 'Edit' : 'Add'} Environment</h3>
<h3 class="text-lg font-medium mb-4">{editingEnvId ? $t.settings?.env_edit : $t.settings?.env_add}</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="env_id" class="block text-sm font-medium text-gray-700">ID</label>
<label for="env_id" class="block text-sm font-medium text-gray-700">{$t.common?.id}</label>
<input type="text" id="env_id" bind:value={newEnv.id} disabled={!!editingEnvId} class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
</div>
<div>
<label for="env_name" class="block text-sm font-medium text-gray-700">Name</label>
<label for="env_name" class="block text-sm font-medium text-gray-700">{$t.settings?.name}</label>
<input type="text" id="env_name" bind:value={newEnv.name} class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
</div>
<div>
<label for="env_url" class="block text-sm font-medium text-gray-700">URL</label>
<label for="env_url" class="block text-sm font-medium text-gray-700">{$t.settings?.env_url}</label>
<input type="text" id="env_url" bind:value={newEnv.url} class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
</div>
<div>
<label for="env_user" class="block text-sm font-medium text-gray-700">Username</label>
<label for="env_user" class="block text-sm font-medium text-gray-700">{$t.settings?.username}</label>
<input type="text" id="env_user" bind:value={newEnv.username} class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
</div>
<div>
<label for="env_pass" class="block text-sm font-medium text-gray-700">Password</label>
<label for="env_pass" class="block text-sm font-medium text-gray-700">{$t.settings?.password}</label>
<input type="password" id="env_pass" bind:value={newEnv.password} class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
</div>
<div class="flex items-center">
<input type="checkbox" id="env_default" bind:checked={newEnv.is_default} class="h-4 w-4 text-blue-600 border-gray-300 rounded" />
<label for="env_default" class="ml-2 block text-sm text-gray-900">Default Environment</label>
<label for="env_default" class="ml-2 block text-sm text-gray-900">{$t.settings?.env_default}</label>
</div>
</div>
<h3 class="text-lg font-medium mb-4 mt-6">Backup Schedule</h3>
<h3 class="text-lg font-medium mb-4 mt-6">{$t.settings?.backup_schedule}</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="flex items-center">
<input type="checkbox" id="backup_enabled" bind:checked={newEnv.backup_schedule.enabled} class="h-4 w-4 text-blue-600 border-gray-300 rounded" />
<label for="backup_enabled" class="ml-2 block text-sm text-gray-900">Enable Automatic Backups</label>
<label for="backup_enabled" class="ml-2 block text-sm text-gray-900">{$t.settings?.enable_auto_backups}</label>
</div>
<div>
<label for="cron_expression" class="block text-sm font-medium text-gray-700">Cron Expression</label>
<input type="text" id="cron_expression" bind:value={newEnv.backup_schedule.cron_expression} placeholder="0 0 * * *" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
<p class="text-xs text-gray-500 mt-1">Example: 0 0 * * * (daily at midnight), */5 * * * * (every 5 minutes)</p>
<label for="cron_expression" class="block text-sm font-medium text-gray-700">{$t.settings?.cron_expression}</label>
<input type="text" id="cron_expression" bind:value={newEnv.backup_schedule.cron_expression} placeholder={$t.settings?.cron_placeholder} class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2" />
<p class="text-xs text-gray-500 mt-1">{$t.settings?.cron_example}</p>
</div>
</div>
<div class="mt-6 flex gap-2">
<button on:click={handleAddOrUpdateEnv} class="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600">
{editingEnvId ? 'Update' : 'Add'} Environment
{editingEnvId ? $t.settings?.env_update : $t.settings?.env_add}
</button>
{#if editingEnvId}
<button on:click={resetEnvForm} class="bg-gray-500 text-white px-4 py-2 rounded hover:bg-gray-600">
Cancel
{$t.common?.cancel}
</button>
{/if}
</div>