{"record":{"id":"59bacb309ad5985f","repo":"eythaann/Seelen-UI","slug":"no-key-provided-to-t-59bacb","errorCode":null,"errorMessage":"no key provided to $t()","messagePattern":"no key provided to \\$t\\(\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libs/ui/svelte/utils/i18n.ts","lineNumber":10,"sourceCode":"import { derived, get, writable } from \"svelte/store\";\nimport yaml from \"js-yaml\";\n\nconst _locale = writable(\"en\");\nconst _messages = writable<Record<string, any>>({});\n\nfunction translate(locale: string, key: string, vars: Record<string, string> = {}) {\n  // Let's throw some errors if we're trying to use keys/locales that don't exist.\n  // We could improve this by using Typescript and/or fallback values.\n  if (!key) throw new Error(\"no key provided to $t()\");\n  if (!locale) throw new Error(`no translation for key \"${key}\"`);\n\n  // Grab the translation from the translations object.\n  // Support nested keys like \"profile.log_out\"\n  const keys = key.split(\".\");\n  let text = get(_messages)[locale];\n  for (const k of keys) {\n    text = text?.[k];\n  }\n\n  if (!text) {\n    console.error(`no translation found for ${locale}.${key}`);\n    // Try fallback to English\n    let fallback = get(_messages)[\"en\"];\n    for (const k of keys) {\n      fallback = fallback?.[k];\n    }\n    text = fallback || key;","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/libs/ui/svelte/utils/i18n.ts#L1-L28","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n<span>{$t(item.key)}</span>\n// after\n<span>{item.key ? $t(item.key) : \"\"}</span>","handlingStrategy":"validation","validationCode":"function safeT(t: (key: string, vars?: Record<string, string>) => string, key?: string | null) {\n  return typeof key === \"string\" && key.length > 0 ? t(key) : \"\";\n}","typeGuard":"function hasKey(key: unknown): key is string {\n  return typeof key === \"string\" && key.trim().length > 0;\n}","tryCatchPattern":"try {\n  label = $t(key);\n} catch (e) {\n  if (e instanceof Error && e.message === \"no key provided to $t()\") label = \"\";\n  else throw e;\n}","preventionTips":["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."],"tags":["i18n","argument-validation","svelte"],"backgroundTag":"missing-required-argument","analyzedSha":"dee4aaa94066c5d0888ab25554864862fc47be15","analyzedAt":"2026-09-03T10:20:37.842Z","contentChangedAt":"2026-09-03T10:20:37.842Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}