{"record":{"id":"1d41d2d199756346","repo":"withastro/astro","slug":"i18nnolocalefoundinpath","errorCode":"i18nNoLocaleFoundInPath","errorMessage":"You tried to use an i18n utility on a path that doesn't contain any locale. You can use `pathHasLocale` first to determine if the path has a locale.","messagePattern":"You tried to use an i18n utility on a path that doesn't contain any locale\\. You can use `pathHasLocale` first to determine if the path has a locale\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/i18n/index.ts","lineNumber":180,"sourceCode":" * Given a locale (code), it returns its corresponding path\n * @param locale\n * @param locales\n */\nexport function getPathByLocale(locale: string, locales: Locales): string {\n\tfor (const loopLocale of locales) {\n\t\tif (typeof loopLocale === 'string') {\n\t\t\tif (loopLocale === locale) {\n\t\t\t\treturn loopLocale;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const code of loopLocale.codes) {\n\t\t\t\tif (code === locale) {\n\t\t\t\t\treturn loopLocale.path;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tthrow new AstroError(i18nNoLocaleFoundInPath);\n}\n\n/**\n * A utility function that retrieves the preferred locale that correspond to a path.\n *\n * @param path\n * @param locales\n */\nexport function getLocaleByPath(path: string, locales: Locales): string {\n\tfor (const locale of locales) {\n\t\tif (typeof locale !== 'string') {\n\t\t\tif (locale.path === path) {\n\t\t\t\t// the first code is the one that user usually wants\n\t\t\t\tconst code = locale.codes.at(0);\n\t\t\t\tif (code === undefined) throw new AstroError(i18nNoLocaleFoundInPath);\n\t\t\t\treturn code;\n\t\t\t}\n\t\t} else if (locale === path) {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/i18n/index.ts#L162-L198","documentation":"getPathByLocale() maps a locale code to its configured path: it scans `i18n.locales` for a string entry equal to the code, or an object entry whose `codes` array contains it, and returns the corresponding path. If no configured locale matches the given code, it throws i18nNoLocaleFoundInPath.","triggerScenarios":"Calling getPathByLocale('fr', locales) when no locale 'fr' is configured as a string entry or inside any codes array; a misspelled or differently-cased locale code reaching i18n routing internals; locales list loaded from a different source than the one used to validate the code.","commonSituations":"Locale codes coming from content frontmatter, headers (Accept-Language), or a CMS that are broader than i18n.locales; editing i18n.locales without updating callers that pass hardcoded codes; case mismatches between configured codes and lookup values.","solutions":["Add the code to i18n.locales (as a string entry or inside an object's codes array).","Pass a code that exactly matches a configured entry, including case.","Validate the code against getAllCodes(locales) or your own list before calling getPathByLocale."],"exampleFix":"// before\nconst path = getPathByLocale('fr', [{ path: 'english', codes: ['en'] }]); // throws\n\n// after\nconst path = getPathByLocale('en', [{ path: 'english', codes: ['en'] }]); // 'english'","handlingStrategy":"type-guard","validationCode":"import { getAllCodes } from 'astro:i18n';\n// before getPathByLocale(code, locales)\nconst known = new Set(getAllCodes(locales));\nif (!known.has(code)) {\n  // fall back to the default locale instead of throwing\n  code = defaultLocale;\n}","typeGuard":"function isConfiguredCode(code: string, locales: Locales): boolean {\n  return locales.some((l) =>\n    typeof l === 'string' ? l === code : l.codes.includes(code),\n  );\n}","tryCatchPattern":null,"preventionTips":["Derive lookups from the same i18n.locales definition used in astro.config, not a duplicate list.","Normalize case before comparing locale codes.","Treat locale codes from content frontmatter or CMS data as untrusted until checked."],"tags":["i18n","localization","routing"],"backgroundTag":"unknown-locale","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}