{"record":{"id":"94db1c20573454cd","repo":"eythaann/Seelen-UI","slug":"no-translation-for-key-key-94db1c","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.ts","lineNumber":11,"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;\n  }","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/libs/ui/svelte/utils/i18n.ts#L1-L29","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the exported `t` derived store instead of calling `translate` directly, so the locale is always supplied.","Ensure `locale.value` is never set to an empty string; validate the configured locale before `locale.set(...)`.","Default the locale when reading it from settings: `setLocale(savedLocale || \"en\")`."],"exampleFix":"// before\nsetLocale(settings.language); // may be \"\"\n// after\nsetLocale(settings.language || \"en\");","handlingStrategy":"validation","validationCode":"if (!locale || typeof locale !== \"string\") {\n  locale = \"en\"; // default before calling translate/t\n}","typeGuard":"function isValidLocale(locale: unknown): locale is string {\n  return typeof locale === \"string\" && /^[a-z]{2}(-[A-Z]{2})?$/.test(locale);\n}","tryCatchPattern":"try {\n  text = translate(locale, key);\n} catch (e) {\n  if (String((e as Error).message).startsWith(\"no translation for key\")) text = key;\n  else throw e;\n}","preventionTips":["Always use the exported `t` store; never call the internal `translate` with a hand-rolled locale.","Validate the locale from settings/config before `locale.set(...)`.","Keep \"en\" as the fallback default in persistence layers."],"tags":["i18n","argument-validation","locale"],"backgroundTag":"missing-locale","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"}