I am trying to create multi-language site using contentful as the headless CMS. I have setup the contentful content model as follows:
The Navigation content type has a title and a links field, which references many Links.
The Link content type has a title field (localized) and a page field, which references one Page.
The Page content type has a title field (localized) and a text field (localized).
When rendering page, I want to render the main navigation depending on the locale of each page, so that the links in the main navigation point to localized pages - if available - instead of pages written in the default locale.
Gatsby version: ^1.9.158
Node.js version: v9.4.0
Operating System: macOS 10.13.3
The file contents shouldn't matter, I can add them later if requested.
To retrieve the main navigation, I use the following query in the page.js template:
query PageQuery($id:String!){
main:contentfulNavigation(contentful_id:{eq:$id}) {
links {
title
node_locale
page {
slug
}
}
}
}
I tested this query in GraphiQL and this is what I received:
{
"data": {
"main": {
"links": [
{
"title": "脺ber uns",
"node_locale": "de-DE",
"page": {
"slug": "/about-us"
}
},
{
"title": "Kontakt",
"node_locale": "de-DE",
"page": {
"slug": "/contact"
}
}
]
}
}
}
The response does not contain the localized nodes, only the nodes with the default locale (de-DE). I expect nodes for the secondary locale (en) to be included:
{
"data": {
"main": {
"links": [
{
"title": "脺ber uns",
"node_locale": "de-DE",
"page": {
"slug": "/about-us"
}
},
{
"title": "Kontakt",
"node_locale": "de-DE",
"page": {
"slug": "/contact"
}
},
"title": "About us",
"node_locale": "en",
"page": {
"slug": "/about-us"
}
},
"title": "Contact",
"node_locale": "en",
"page": {
"slug": "/contact"
}
},
]
}
}
}
1. Create a contentful content type A, which itself has no localized fields and references another content type B, which has localized fields.
2. Try to retrieve the referenced entries of type B by querying an entry of type A. The response will only include the entries of type B in the default locale. Other locales are missing.
I was able to get localized nodes by using a filter in my query. I have two node_locale in Contentful. Hope it's useful:
Query
{
allContentfulBlogPost(
filter: {node_locale: {regex: "/da-DK/"}}
) {
edges {
node {
title
}
}
}
}
output
{
"data": {
"allContentfulBlogPost": {
"edges": [
{
"node": {
"title": "Ny Blog Post - Juhuuu"
}
}
]
}
}
}
Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!
Most helpful comment
I was able to get localized nodes by using a filter in my query. I have two node_locale in Contentful. Hope it's useful:
Query
output