{"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/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/i18n/index.ts#L162-L198","documentation":"In the internal locale-matching loop (used to find a configured locale whose path matches a given input), if the loop completes without any locale string or locale object code matching the requested `locale`, Astro throws `i18nNoLocaleFoundInPath`. The message advises checking the path with `pathHasLocale` first.","triggerScenarios":"Calling an i18n utility that resolves a locale against `locales` with a `locale`/path argument that matches none of the configured locales' codes or paths.","commonSituations":"Passing a URL path that has no locale segment to a utility that assumes one; a locale code casing or formatting mismatch (e.g. 'EN' vs 'en'); a path produced by an external source (CMS, redirect) that doesn't include the expected locale prefix.","solutions":["Call `pathHasLocale(path, locales)` (or equivalent membership check) before invoking the locale utility, and branch when it returns false.","Ensure the path includes a locale segment that exactly matches a configured locale code or path.","Normalize casing/spacing of the locale segment before lookup.","Add or correct the locale in `i18n.locales` if it should be supported."],"exampleFix":"// before\nconst locale = extractLocale(path, locales) // throws if path has no locale\n\n// after\nif (pathHasLocale(path, locales)) {\n  const locale = extractLocale(path, locales)\n} else {\n  // handle locale-less path (e.g. default locale)\n}","handlingStrategy":"type-guard","validationCode":"import { pathHasLocale } from 'astro:i18n';\nif (!pathHasLocale(path, locales)) {\n  // skip locale utility, handle locale-less path\n}","typeGuard":"function pathHasLocaleFast(path, locales) {\n  return locales.some(l => {\n    const seg = typeof l === 'string' ? l : l.path;\n    return path === seg || path.startsWith('/' + seg);\n  });\n}","tryCatchPattern":"null","preventionTips":["Always call pathHasLocale before locale-extracting utilities.","Normalize path casing before lookup.","Ensure incoming URLs include a configured locale prefix."],"tags":["i18n","routing","localization"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}