Support for localization (e.g. for Contentful)
See original GitHub issueWhile I guess that it is currently possible to localize MDX based on frontmatter tags, doing this would mean that the filenames would need to be different, resulting in different slugs which would certainly not be ideal. I guess there are other ways to achieve it, but none of them seem ideal, thatβs why it would be great to support l10n (and also just because Contentlayers goal is to be the abstraction layer between data and code).
I assume that there could be several ways for structuring the MDX files, but what comes to my mind first is either via file name eg. /pages/about.mdx
/pages/about.de.mdx
or via subfolders eg. /pages/en/about.mdx
/pages/de/about.mdx
.
Edit: the following structure seems pretty nice, but would depend on #11
βββ data
β βββ pages
β β βββ about
β β β βββ index.mdx
β β β βββ index.de.mdx
β β β βββ picture.jpeg
β β βββ privacy
β β β βββ index.mdx
β β β βββ index.de.mdx
β β β βββ cover.jpeg
For Contentful one just needs to add &locale=
https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/localization
Issue Analytics
- State:
- Created 2 years ago
- Comments:10
Top GitHub Comments
@rsipakov, hereβs a psuedocode assuming βenβ as the default:
This would generate a new
locale
field for each post which you can use in your pages/routing.Thanks a lot for the update @henniaufmrenni. Iβll keep this issue open since some CMS (e.g. Contentful) have a first-class localization feature thatβs currently not yet supported by Contentlayer but should be.
I also agree that we should better document how to implement localization/internationalization scenarios when using the source-files plugin. (cc @seancdavis)