{"record":{"id":"00297046fd7fc8ea","repo":"eythaann/Seelen-UI","slug":"no-translation-for-key-key","errorCode":null,"errorMessage":"no translation for key \"${key}\"","messagePattern":"no translation for key \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libs/ui/svelte/utils/i18n.svelte.ts","lineNumber":10,"sourceCode":"import yaml from \"js-yaml\";\n\nlet _locale = $state(\"en\");\nlet _messages = $state.raw<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 = _messages[locale];\n\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 = _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.svelte.ts#L1-L28","documentation":"translate() throws this error when the locale value is falsy after being resolved for a given key. Despite the message wording, the check is `if (!locale)` — the active locale string is empty/undefined when looking up the key, meaning no translation can be resolved under the current (missing) locale.","triggerScenarios":"Calling t(key) before the i18n module loaded its locale/messages (so _locale is empty); setLocale('') or an unset locale at startup; the translation file for the locale failed to load; calling t() during module init before i18n bootstrap completed.","commonSituations":"Rendering a Svelte component before the app's i18n bootstrap ran; a locale code typo or unsupported locale yielding no messages entry; async locale loading racing first render; test environments where the i18n store was never initialized.","solutions":["Initialize the i18n module (load locale/messages) before rendering components that call t().","Provide a default locale fallback so _locale is never empty (e.g. default to 'en').","Verify the messages file for the active locale exists and loads without error.","Gate rendering on i18n readiness (await locale setup, or show a loading state)."],"exampleFix":"// before: setLocale(userLocale); /* userLocale may be '' */ t('app.title'); // throws\n// after: setLocale(userLocale || 'en'); t('app.title'); // resolves with the default locale","handlingStrategy":"fallback","validationCode":"if (!locale) { setLocale('en'); } // default before any t() call","typeGuard":"function hasLocale(state: { locale?: string }): state is { locale: string } { return typeof state.locale === 'string' && state.locale.length > 0; }","tryCatchPattern":"try { text = $t('app.title'); } catch (e) { if (e instanceof Error && e.message.startsWith('no translation for key')) { text = 'app.title'; } else { throw e; } }","preventionTips":["Initialize the i18n store with a default locale at app startup, before rendering.","Always provide a fallback locale ('en') when the user's locale is unavailable or files fail to load.","Await locale/message loading before first render that calls t().","Verify every shipped locale has a translations entry in i18n/translations/."],"tags":["i18n","localization","initialization"],"backgroundTag":"missing-i18n-key","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"}