Replies: 1 comment
-
|
Here is my current workaround, which is to load every collection that I have. import { collections } from "../content/config.ts"
type MyCollectionKeys = keyof typeof collections;
type AnyCollectionEntry = CollectionEntry<MyCollectionKeys>;
async function loadCollection(language: string) {
if (!language) {
language = "en";
}
let posts: AnyCollectionEntry[] = [];
for (const collection of Object.keys(collections) as MyCollectionKeys[]) {
let collectionEntries = await getCollection(collection, ({ data }) => {
if (import.meta.env.PROD && data.language === language && data.draft !== true) {
return true;
}
return false;
});
posts = posts.concat(collectionEntries);
}
return posts;
}It works on |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I am working on an internationalized Astro project where I aim to serve content in multiple languages. The content is organized by slugs that correspond to journal entries. I want to maintain the same slug across different languages but change the path based on the language (e.g.,
/en/2023-05-13-Journaland/th/2023-05-13-Journal). This approach ensures a consistent URL structure that only varies by the language prefix, facilitating better user navigation and SEO for language-specific content.However, following the internationalization guide on the Astro documentation, I encountered the
[DuplicateContentEntrySlugError]when trying to implement this. The error message is as follows:This limitation restricts the ability to use the same slug across different languages, which is a common requirement for multilingual websites.
Expected Behavior
I expect to be able to create markdown files (or other content files) for different languages that share the same slug but differ in their language-specific frontmatter and path. This setup would allow the website to switch languages without changing the content's slug, maintaining a consistent URL structure for SEO and user experience.
Proposed Solution or Feature
Ideally, Astro should support a way to differentiate content by language within the routing or content fetching logic, even if the slugs are identical. This could involve:
Additional Context
This feature is crucial for developers building multilingual sites who wish to maintain clean and consistent URL structures across languages. It enhances SEO and user experience by enabling easy toggling between languages without changing the content context.
Thank you for considering this enhancement to better support internationalization in Astro.
Beta Was this translation helpful? Give feedback.
All reactions