I’m trying to translate my latest-posts page by first checking if “cy” ( the language shortcode for Welsh) is in the current URL and then checking the lang property of each post.
const posts = state.source.post;
for (var i in posts) {
if(state.router.link.includes("/cy/")) {
if(posts[i]["lang"] == "cy") {
correctLangPosts.push(posts[i]);
}
} else if(posts[i]["lang"] == "en") {
correctLangPosts.push(posts[i]);
}
}
However, when I check state.source.post whilst /cy is in the URL no posts are there. I have a feeling this isn’t the best way to implement translations but I have no other ideas.
I’m using Polylang for translations on my Wordpress site.
I can’t give you the link to the repo for security reasons.
Do you by any chance have any example multilingual sites which have been developed using the Polylang plugin which I could look at?