eythaann/Seelen-UI · error · Error

no translation for key "${key}"

Error message

no translation for key "${key}"

What it means

`translate` requires a locale string as its first argument; it throws `no translation for key "<key>"` when the locale is falsy. The public `t` store derives from `_locale` (initialized to "en"), so a normal `$t(key)` call always has a locale — the throw happens when the locale store was somehow reset or when `translate` is invoked directly with an empty locale.

Source

Thrown at libs/ui/svelte/utils/i18n.ts:11

import { derived, get, writable } from "svelte/store";
import yaml from "js-yaml";

const _locale = writable("en");
const _messages = writable<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 = get(_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 = get(_messages)["en"];
    for (const k of keys) {
      fallback = fallback?.[k];
    }
    text = fallback || key;
  }

View on GitHub (pinned to dee4aaa940)

Solutions

  1. Use the exported `t` derived store instead of calling `translate` directly, so the locale is always supplied.
  2. Ensure `locale.value` is never set to an empty string; validate the configured locale before `locale.set(...)`.
  3. Default the locale when reading it from settings: `setLocale(savedLocale || "en")`.

Example fix

// before
setLocale(settings.language); // may be ""
// after
setLocale(settings.language || "en");
Defensive patterns

Strategy: validation

Validate before calling

if (!locale || typeof locale !== "string") {
  locale = "en"; // default before calling translate/t
}

Type guard

function isValidLocale(locale: unknown): locale is string {
  return typeof locale === "string" && /^[a-z]{2}(-[A-Z]{2})?$/.test(locale);
}

Try / catch

try {
  text = translate(locale, key);
} catch (e) {
  if (String((e as Error).message).startsWith("no translation for key")) text = key;
  else throw e;
}

Prevention

When it happens

Trigger: Calling `translate(locale, key)` (or a derived `$t`) where `locale` is `""`, undefined, or null — e.g. `_locale` was set to an empty value, or custom code invokes the internal function with a locale read from config before initialization.

Common situations: Custom code calling `translate` directly instead of the exported `t` store; a settings file providing an empty `language`/`locale` value that is assigned to the locale store; race where locale state is cleared during app re-init.

Related errors


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