kris
(Kristiyan Bogdanov)
June 23, 2021, 8:31am
1
How can I preview a document in the correct language?
For example, I have german and english language repository I want to preview the english version (the german is default). Every time I preview the document, I automatically go to the german version.
I checked out the multi-lang repository, but I don't think they tackle this problem there
import * as prismicNext from "@prismicio/next";
import { createClient, linkResolver } from "../../prismicio";
export default async function handler(req, res) {
const client = createClient({ req });
prismicNext.setPreviewData({ req, res });
await prismicNext.redirectToPreviewURL({ req, res, client, linkResolver });
}
Phil
(Phil Snow)
June 23, 2021, 2:36pm
2
Hi Kris,
Finding the correct language is handle by the link resover, make sure it's configured as so:
// Configure your site's access point here
apiEndpoint: 'https://your-repo-name.cdn.prismic.io/api/v2',
// -- Access Token if the repository is not public
// Generate a token in your dashboard and configure it here if your repository is private
accessToken: '',
// -- Link resolution rules
// Manages links to internal Prismic documents
// Modify as your project grows to handle any new routes you've made
linkResolver: function(doc) {
if (doc.type === 'page') {
return `/${doc.lang}/${doc.uid}`;
}
if (doc.type === 'homepage') {
return `/${doc.lang}`;
}
return '/';
},
// Additional helper function for Next/Link component
Thanks.
system
(system)
closed as resolved, flag & select 'Something Else' to reopen.
July 7, 2021, 1:25pm
4
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.