{"record":{"id":"df1e7af23c441cae","repo":"facebook/docusaurus","slug":"can-t-write-translation-for-locale-locale-tha","errorCode":null,"errorMessage":"Can't write-translation for locale \"${locale}\" that is not in the locale configuration file.\\nAvailable locales are: ${context.i18n.locales.join(',')}.","messagePattern":"Can't write-translation for locale \"(.+?)\" that is not in the locale configuration file\\.\\\\nAvailable locales are: (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/docusaurus/src/commands/writeTranslations.ts","lineNumber":97,"sourceCode":"\nexport async function writeTranslations(\n  siteDirParam: string = '.',\n  options: Partial<WriteTranslationsCLIOptions> = {},\n): Promise<void> {\n  const siteDir = await fs.realpath(siteDirParam);\n\n  const context = await loadContext({\n    siteDir,\n    config: options.config,\n    locale: options.locale,\n  });\n  const {localizationDir} = context;\n  const plugins = await initPlugins(context);\n\n  const locale = options.locale ?? context.i18n.defaultLocale;\n\n  if (!context.i18n.locales.includes(locale)) {\n    throw new Error(\n      `Can't write-translation for locale \"${locale}\" that is not in the locale configuration file.\nAvailable locales are: ${context.i18n.locales.join(',')}.`,\n    );\n  }\n\n  const extractedCodeTranslations = await extractSiteSourceCodeTranslations({\n    siteDir,\n    plugins,\n    extraSourceCodeFilePaths: await getExtraSourceCodeFilePaths(),\n  });\n\n  const defaultCodeMessages =\n    await loadPluginsDefaultCodeTranslationMessages(plugins);\n\n  const codeTranslations = applyDefaultCodeTranslations({\n    extractedCodeTranslations,\n    defaultCodeMessages,\n  });","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus/src/commands/writeTranslations.ts#L79-L115","documentation":"Thrown by `writeTranslations` when the requested `--locale` is not present in `context.i18n.locales` (the locales declared in the site's i18n config). Docusaurus will not extract/write translation files for a locale the site does not officially support.","triggerScenarios":"Running `docusaurus write-translations --locale=<x>` where `<x>` is neither in `i18n.locales` nor the default locale. Also fires if `options.locale` is omitted but `context.i18n.defaultLocale` itself is not in `locales` (misconfigured i18n).","commonSituations":"Typo in locale code (e.g. `en-US` vs `en`); forgot to add the locale to `i18n.locales` before translating; copying a command from a project that supports a different locale set; locale casing mismatch.","solutions":["Add the locale to `i18n.locales` in `docusaurus.config.js` before running write-translations.","Check the locale code spelling/casing against the configured list (the error prints the available locales).","Run without `--locale` to use the default locale, if that is what you intended.","Re-run `docusaurus write-translations --locale=<x>` after fixing config — the available-locales list in the message confirms the fix."],"exampleFix":"// before\nexport default { i18n: { defaultLocale: 'en', locales: ['en'] } };\n// docusaurus write-translations --locale=fr  -> throws\n// after\nexport default { i18n: { defaultLocale: 'en', locales: ['en', 'fr'] } };","handlingStrategy":"validation","validationCode":"const locale = options.locale ?? context.i18n.defaultLocale;\nif (!context.i18n.locales.includes(locale)) {\n  throw new Error(`Locale ${locale} not in i18n.locales: ${context.i18n.locales.join(',')}`);\n}","typeGuard":"function isConfiguredLocale(locale: string, configured: string[]): locale is string {\n  return configured.includes(locale);\n}","tryCatchPattern":null,"preventionTips":["Add new locales to `i18n.locales` before running write-translations.","Share a constant for supported locale codes between config and scripts.","Validate `--locale` against config before invoking the CLI."],"tags":["i18n","write-translations","config","validation"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}