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

  1. Pass a non-empty key string to t(); audit the call site for undefined variables.
  2. Type keys as a union of known keys (or derive from the translations object) so missing keys fail at compile time.
  3. For dynamic keys, default them: t(`app.${section ?? 'default'}`).
  4. 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

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


AI-assisted analysis of eythaann/Seelen-UI@dee4aaa940 (2026-09-03). Data as JSON: /api/errors/437239c4e106b95e. Report an issue: GitHub.