State.source.post empty when /cy endpoint added to url

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.

Any help will be appreciated.

Hi @leogardner12

Could you provide a link to a repo so that we can clone your project and take a look at what’s going on. Thanks.

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?

Hi @leogardner12

I haven’t done anything myself with Polylang or developed any multilingual sites. Maybe someone else in the community who has could help you?

Meanwhile take a look at these threads and see if they give you any ideas.

https://community.frontity.org/t/multilanguage-with-acf/2750/9

1 Like