fix: remove $t() calls from $derived() blocks to fix PostCSS errors
vite-plugin-svelte CSS extraction fails when $t() is used inside $derived(). This causes "[postcss] Unknown word <script" errors that appear to be cache issues but are actually a known Svelte 5 / vite-plugin-svelte incompatibility. Files fixed: - DownloadButton.svelte: use titleKey pattern with function resolver - DACSetupWizard.svelte: use labelKey pattern resolved in WizardStepper - RemoteControlSetupGuide.svelte: use labelKey pattern - WizardStepper.svelte: support optional labelKey with $t() in template Also added download.* translation keys to en.json and es.json. cc
This commit is contained in:
1 parent
4cfde680aa
commit
c9b26eb4db
6 files changed
+45
-15
No files matched your search
@@ -194,9 +194,11 @@
|
|||||||
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
const steps = $derived<Step[]>(STEPS.map((step, index) => ({
|
// Store labelKey instead of calling $t() in $derived - resolve in template
|
||||||
|
const steps = $derived<(Step & { labelKey: string })[]>(STEPS.map((step, index) => ({
|
||||||
id: step,
|
id: step,
|
||||||
label: $t(`dacWizard.steps.${toCamelCase(step)}`) || step,
|
label: step, // fallback
|
||||||
|
labelKey: `dacWizard.steps.${toCamelCase(step)}`,
|
||||||
status: index === currentIndex ? 'active' : completedSteps.has(step) ? 'complete' : 'upcoming'
|
status: index === currentIndex ? 'active' : completedSteps.has(step) ? 'complete' : 'upcoming'
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
|||||||
@@ -50,21 +50,31 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = $derived.by(() => {
|
// Return translation key for title - call $t() in template
|
||||||
|
const titleKey = $derived.by(() => {
|
||||||
// Show offline message when trying to download while offline
|
// Show offline message when trying to download while offline
|
||||||
if (isOffline && (status === 'none' || status === 'failed')) {
|
if (isOffline && (status === 'none' || status === 'failed')) {
|
||||||
return $t('offline.featureDisabled');
|
return 'offline.featureDisabled';
|
||||||
}
|
}
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 'none': return 'Make available offline';
|
case 'none': return 'download.makeAvailable';
|
||||||
case 'queued': return 'Queued for offline';
|
case 'queued': return 'download.queued';
|
||||||
case 'downloading': return `Preparing for offline ${progress}%`;
|
case 'downloading': return 'download.preparing';
|
||||||
case 'ready': return 'Available offline (click to remove)';
|
case 'ready': return 'download.ready';
|
||||||
case 'failed': return 'Failed to cache for offline (click to retry)';
|
case 'failed': return 'download.failed';
|
||||||
default: return '';
|
default: return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Resolve title - must be a function called from template (not $derived)
|
||||||
|
function getTitle(): string {
|
||||||
|
if (!titleKey) return '';
|
||||||
|
if (status === 'downloading') {
|
||||||
|
return `${$t(titleKey)} ${progress}%`;
|
||||||
|
}
|
||||||
|
return $t(titleKey);
|
||||||
|
}
|
||||||
|
|
||||||
// Disable button when offline and not already downloaded
|
// Disable button when offline and not already downloaded
|
||||||
const isDisabled = $derived(
|
const isDisabled = $derived(
|
||||||
status === 'queued' || (isOffline && status !== 'ready')
|
status === 'queued' || (isOffline && status !== 'ready')
|
||||||
@@ -78,8 +88,8 @@
|
|||||||
class:failed={status === 'failed'}
|
class:failed={status === 'failed'}
|
||||||
class:offline={isOffline && status !== 'ready'}
|
class:offline={isOffline && status !== 'ready'}
|
||||||
onclick={handleClick}
|
onclick={handleClick}
|
||||||
title={title}
|
title={getTitle()}
|
||||||
aria-label={title}
|
aria-label={getTitle()}
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
>
|
>
|
||||||
{#if status === 'ready'}
|
{#if status === 'ready'}
|
||||||
|
|||||||
@@ -31,9 +31,11 @@
|
|||||||
// Derived values
|
// Derived values
|
||||||
const currentIndex = $derived(STEPS.indexOf(currentStep));
|
const currentIndex = $derived(STEPS.indexOf(currentStep));
|
||||||
|
|
||||||
const steps = $derived<Step[]>(STEPS.map((step, index) => ({
|
// Store labelKey instead of calling $t() in $derived - resolve in WizardStepper template
|
||||||
|
const steps = $derived<(Step & { labelKey: string })[]>(STEPS.map((step, index) => ({
|
||||||
id: step,
|
id: step,
|
||||||
label: $t(`remoteControlWizard.steps.${step}`) || step,
|
label: step, // fallback
|
||||||
|
labelKey: `remoteControlWizard.steps.${step}`,
|
||||||
status: index === currentIndex ? 'active' : completedSteps.has(step) ? 'complete' : 'upcoming'
|
status: index === currentIndex ? 'active' : completedSteps.has(step) ? 'complete' : 'upcoming'
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Check } from 'lucide-svelte';
|
import { Check } from 'lucide-svelte';
|
||||||
|
import { t } from '$lib/i18n';
|
||||||
|
|
||||||
export interface Step {
|
export interface Step {
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
labelKey?: string; // Optional translation key - resolved in template
|
||||||
status: 'complete' | 'active' | 'upcoming';
|
status: 'complete' | 'active' | 'upcoming';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +43,7 @@
|
|||||||
<span class="step-number">{index + 1}</span>
|
<span class="step-number">{index + 1}</span>
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
<span class="step-label">{step.label}</span>
|
<span class="step-label">{step.labelKey ? $t(step.labelKey) || step.label : step.label}</span>
|
||||||
</button>
|
</button>
|
||||||
{#if index < steps.length - 1}
|
{#if index < steps.length - 1}
|
||||||
<div class="step-connector" class:complete={step.status === 'complete'}></div>
|
<div class="step-connector" class:complete={step.status === 'complete'}></div>
|
||||||
|
|||||||
@@ -987,6 +987,13 @@
|
|||||||
"showNetworkFolders": "Show Network Folder Content",
|
"showNetworkFolders": "Show Network Folder Content",
|
||||||
"showNetworkFoldersDesc": "Display content from network-mounted folders (NAS, Samba, etc.) while in manual offline mode"
|
"showNetworkFoldersDesc": "Display content from network-mounted folders (NAS, Samba, etc.) while in manual offline mode"
|
||||||
},
|
},
|
||||||
|
"download": {
|
||||||
|
"makeAvailable": "Make available offline",
|
||||||
|
"queued": "Queued for offline",
|
||||||
|
"preparing": "Preparing for offline",
|
||||||
|
"ready": "Available offline (click to remove)",
|
||||||
|
"failed": "Failed to cache for offline (click to retry)"
|
||||||
|
},
|
||||||
"filter": {
|
"filter": {
|
||||||
"all": "All"
|
"all": "All"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -987,6 +987,13 @@
|
|||||||
"showNetworkFolders": "Mostrar Contenido de Carpetas de Red",
|
"showNetworkFolders": "Mostrar Contenido de Carpetas de Red",
|
||||||
"showNetworkFoldersDesc": "Mostrar contenido de carpetas montadas en red (NAS, Samba, etc.) mientras estas en modo offline manual"
|
"showNetworkFoldersDesc": "Mostrar contenido de carpetas montadas en red (NAS, Samba, etc.) mientras estas en modo offline manual"
|
||||||
},
|
},
|
||||||
|
"download": {
|
||||||
|
"makeAvailable": "Hacer disponible offline",
|
||||||
|
"queued": "En cola para offline",
|
||||||
|
"preparing": "Preparando para offline",
|
||||||
|
"ready": "Disponible offline (clic para eliminar)",
|
||||||
|
"failed": "Error al cachear para offline (clic para reintentar)"
|
||||||
|
},
|
||||||
"filter": {
|
"filter": {
|
||||||
"all": "Todos"
|
"all": "Todos"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user