eythaann/Seelen-UI · error · Error
no key provided to $t()
Error message
no key provided to $t()
What it means
The internal translate() function backing the $t() helper validates its inputs: a falsy (empty/undefined/null) key cannot be looked up in the messages table, so it throws immediately with 'no key provided to $t()'. This is a programming-mistake guard rather than a data problem — the key string itself is missing.
Source
Thrown at libs/ui/svelte/utils/i18n.svelte.ts:9
import yaml from "js-yaml";
let _locale = $state("en");
let _messages = $state.raw<Record<string, any>>({});
function translate(locale: string, key: string, vars: Record<string, string> = {}) {
// Let's throw some errors if we're trying to use keys/locales that don't exist.
// We could improve this by using Typescript and/or fallback values.
if (!key) throw new Error("no key provided to $t()");
if (!locale) throw new Error(`no translation for key "${key}"`);
// Grab the translation from the translations object.
// Support nested keys like "profile.log_out"
const keys = key.split(".");
let text = _messages[locale];
for (const k of keys) {
text = text?.[k];
}
if (!text) {
console.error(`no translation found for ${locale}.${key}`);
// Try fallback to English
let fallback = _messages["en"];
for (const k of keys) {
fallback = fallback?.[k];
}View on GitHub (pinned to dee4aaa940)
Solutions
- Pass a non-empty key string to t(); audit the call site for undefined variables.
- Type keys as a union of known keys (or derive from the translations object) so missing keys fail at compile time.
- For dynamic keys, default them: t(`app.${section ?? 'default'}`).
- Add a dev-time assertion/log before t() when keys are computed.
Example fix
// before: const key = config.translationKey; /* undefined */ t(key); // after: if (config.translationKey) t(config.translationKey);
Defensive patterns
Strategy: validation
Validate before calling
function safeT(key?: string, vars?: Record<string, string>) { if (!key) return key ?? ''; return t(key, vars); } Type guard
function isTranslationKey(key: unknown): key is string { return typeof key === 'string' && key.length > 0; } Try / catch
try { label = $t(key); } catch (e) { if (e instanceof Error && e.message.includes('no key provided')) { label = key ?? ''; } else { throw e; } } Prevention
- Type keys as a union derived from the translations object so missing keys fail at compile time.
- Never build keys from possibly-undefined data without a default.
- Avoid optional-chained values as keys.
- Lint/grep for t() calls with empty or dynamic-unchecked arguments.
When it happens
Trigger: Calling t('') or t(undefined); passing a variable that is undefined because the constant/import is missing; building keys dynamically (t(`app.${section}`)) where section is undefined; passing arguments in the wrong order so the key slot receives the wrong value.
Common situations: Renaming a key constant and leaving a call site undefined; optional chaining producing undefined keys (t(obj?.key)); template-literal keys built from not-yet-loaded data; copy-pasted t() calls with arguments dropped.
Related errors
- The inner array cannot be null or undefined.
- The inner array must be an array.
- no translation for key "${key}"
- no key provided to $t()
- no translation for key "${key}"
AI-assisted analysis of eythaann/Seelen-UI@dee4aaa940 (2026-09-03).
Data as JSON: /api/errors/437239c4e106b95e.
Report an issue: GitHub.