{"record":{"id":"5dd2536d349d8474","repo":"facebook/docusaurus","slug":"can-t-find-locale-config-for-locale-logger-code","errorCode":null,"errorMessage":"Can't find locale config for locale ${logger.code(localeToLookFor)}","messagePattern":"Can't find locale config for locale (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/docusaurus-utils/src/i18nUtils.ts","lineNumber":76,"sourceCode":"  subPaths?: string[];\n}): string {\n  return path.join(\n    localizationDir,\n    // Make it convenient to use for single-instance\n    // ie: return \"docs\", not \"docs-default\" nor \"docs/default\"\n    `${pluginName}${pluginId === DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`,\n    ...subPaths,\n  );\n}\n\n// TODO we may extract this to a separate package\n//  we want to use it on the frontend too\n//  but \"docusaurus-utils-common\" (agnostic utils) is not an ideal place since\nexport function getLocaleConfig(i18n: I18n, locale?: string): I18nLocaleConfig {\n  const localeToLookFor = locale ?? i18n.currentLocale;\n  const localeConfig = i18n.localeConfigs[localeToLookFor];\n  if (!localeConfig) {\n    throw new Error(\n      `Can't find locale config for locale ${logger.code(localeToLookFor)}`,\n    );\n  }\n  return localeConfig;\n}\n","sourceCodeStart":58,"sourceCodeEnd":82,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-utils/src/i18nUtils.ts#L58-L82","documentation":"Thrown by getLocaleConfig() when looking up a locale in i18n.localeConfigs fails. The locale is either the one passed explicitly or, falling back, i18n.currentLocale. localeConfigs is populated from the i18n config in docusaurus.config.js, so a missing entry means the locale was referenced but never declared there.","triggerScenarios":"Calling getLocaleConfig with a locale code that is not a key in i18n.localeConfigs. This happens when the URL or a plugin path forces a locale (e.g. /fr/) but the site's i18n.config only declares en. It also happens when i18n.currentLocale itself is set to a value not present in localeConfigs.","commonSituations":"Enabling localized routing before adding the locale to i18n.locales and i18n.localeConfigs. Typos in locale codes (e.g. 'en-US' vs 'en'). A plugin receiving a locale from a user-facing switcher that has not been configured. Upgrading Docusaurus and forgetting to migrate the i18n config shape.","solutions":["Open docusaurus.config.js and confirm the failing locale code is present in both i18n.locales and i18n.localeConfigs (with at least label/direction/htmlLang entries).","Match the exact casing and hyphenation of the locale code between the caller and the config (locale lookups are exact-string).","If the locale should not be supported, fix the caller (URL switcher, plugin option) so it never requests that locale.","Rebuild after saving the config change — localeConfigs is computed at config load time."],"exampleFix":"// before (docusaurus.config.js)\ni18n: {\n  defaultLocale: 'en',\n  locales: ['en'],\n  localeConfigs: { en: { label: 'English' } }\n}\n// a request for /fr/ triggers the error\n\n// after\ni18n: {\n  defaultLocale: 'en',\n  locales: ['en', 'fr'],\n  localeConfigs: {\n    en: { label: 'English' },\n    fr: { label: 'Français', direction: 'ltr', htmlLang: 'fr' }\n  }\n}","handlingStrategy":"validation","validationCode":"function isLocaleConfigured(i18n: { localeConfigs: Record<string, unknown> }, locale?: string): boolean {\n  const target = locale ?? (i18n as any).currentLocale;\n  return Boolean(target && i18n.localeConfigs[target]);\n}\n\nif (!isLocaleConfigured(i18n, requestedLocale)) {\n  throw new Error(`Locale '${requestedLocale}' is not declared in i18n.localeConfigs.`);\n}","typeGuard":"function hasLocaleConfig(i18n: { localeConfigs: Record<string, unknown> }, locale: string): boolean {\n  return locale in i18n.localeConfigs;\n}","tryCatchPattern":"try {\n  getLocaleConfig(i18n, locale);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"Can't find locale config\")) {\n    // locale was requested but not configured; fall back to default or surface a helpful message\n  }\n  throw err;\n}","preventionTips":["Keep i18n.locales and i18n.localeConfigs keys in sync — every supported locale needs both entries.","Validate locale codes at the boundary where users can pick them (URL switcher, plugin option).","Match casing/hyphenation exactly (e.g. en-US vs en-us will not match)."],"tags":["i18n","locale","config"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}