With an Astro locale object, content created at runtime is stamped with the `path` while `Astro.currentLocale` is the code, so a lookup by the current locale misses it
Versions: emdash 0.42.0 and 1.0.1, @emdash-cms/cloudflare same, astro 7.3.2, astro dev on workerd.
Config
i18n: {
defaultLocale: "es-MX",
locales: ["es-MX", { path: "en", codes: ["en-US"] }],
fallback: { en: "es-MX" },
routing: { prefixDefaultLocale: false, fallbackType: "rewrite" },
}Steps
- Seed a
pagesentryterminos-y-condicionesines-MX. - Create its translation through the REST API with the locale the admin offers for that entry,
en(the locale list EmDash exposes is the normalized one,["es-MX", "en"]):POST /_emdash/api/content/pageswith{ slug: "terminos-y-condiciones", locale: "en", translationOf: <id>, data: { title: "Terms EN" } }, then publish. - On a page served under
/en/, readAstro.currentLocaleand query the entry with it.
Observed
Astro.currentLocaleunder/en/is"en-US"(Astro returns the locale's first code).getEmDashEntry("pages", "terminos-y-condiciones", { locale: "en-US" })returns thees-MXrow (via the fallback chain);{ locale: "en" }returns "Terms EN".- The sitemap is consistent:
sitemap-pages.xmllists/en/terminos-y-condicionesfor theenrow, and anen-USrow is listed under/en/too —resolveLocaleSegmentmatchesentry.path === locale || entry.codes.includes(locale)since 0.42.0.
Expected
One locale identity per configured locale object across writes and reads: either rows are stamped with a code (so Astro.currentLocale finds them), or queries normalize a code to its object's path before matching. Today normalizeAstroI18n maps each object to its path (src/i18n/normalize.ts), which is what rows get, while Astro hands templates a code.
Workaround
Use string locales only, so the URL segment, Astro.currentLocale and the stored row locale are the same string.
(At 0.38.0 the sitemap side was broken as well — rows stamped with the path were dropped from it; that half is fixed in 0.42.0.)
Source: emdash-cms/emdash