eythaann/Seelen-UI · error · Error
no key provided to $t()
Error message
no key provided to $t()
What it means
The i18n helper `translate` (exposed as the `$t` store) requires a translation key string. It throws `no key provided to $t()` when the key argument is falsy (undefined, null, empty string). This is a programmer-error guard: calling `$t()` without specifying which string to look up can never succeed.
Source
Thrown at libs/ui/svelte/utils/i18n.ts:10
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
- Pass a non-empty string key to `$t()`, e.g. `$t("profile.log_out")`.
- If the key is dynamic, guard before calling: `key && $t(key)` or provide a default like `$t(key ?? "common.unknown")`.
- Check the surrounding component for undefined props/config feeding the key expression and add a fallback.
Example fix
// before
<span>{$t(item.key)}</span>
// after
<span>{item.key ? $t(item.key) : ""}</span> Defensive patterns
Strategy: validation
Validate before calling
function safeT(t: (key: string, vars?: Record<string, string>) => string, key?: string | null) {
return typeof key === "string" && key.length > 0 ? t(key) : "";
} Type guard
function hasKey(key: unknown): key is string {
return typeof key === "string" && key.trim().length > 0;
} Try / catch
try {
label = $t(key);
} catch (e) {
if (e instanceof Error && e.message === "no key provided to $t()") label = "";
else throw e;
} Prevention
- Never build i18n keys from possibly-undefined values without a fallback.
- Type key parameters as `string` (not `string | undefined`) in components.
- Lint for bare `$t()` calls during review.
When it happens
Trigger: Calling the `t` store function as `$t()` or `$t("")` — e.g. a dynamic key expression that evaluates to empty/undefined because a variable was not set, a loop property name is missing, or a template literal interpolated an undefined value.
Common situations: Refactoring component labels to use i18n keys but forgetting to pass the key; keys read from config/props that are optional and undefined at first render; mistyping the call as `t(vars)` with the vars object as first arg while key is missing.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- no translation for key "${key}"
- LazyRune was not initialized
- no key provided to $t()
- no translation for key "${key}"
- Current monitor not found
AI-assisted analysis of eythaann/Seelen-UI@dee4aaa940 (2026-09-03).
Data as JSON: /api/errors/59bacb309ad5985f.
Report an issue: GitHub.