-
Notifications
You must be signed in to change notification settings - Fork 10.3k
WIP: feat(gatsby-source-drupal): Add multilingual support by prefixing nodes not in the default language with their langcode #26642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Things left to do:
|
| // Default defaultLanguage to `en` | ||
| defaultLanguage = defaultLanguage || `en` | ||
|
|
||
| const languagePrefix = defaultLanguage !== language ? language : `` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to just pass in languagePrefix. I think that makes the most sense from a DevX perspective. "I am trying to use an endpoint with a /es/ prefix, I put languagePrefix: es into the gatsby-config"
smthomas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting pretty close, but there are a few things we need to consider before this can be merged:
-
Right now this expects a JSON:API endpoint to only return entities from one language. I have plans to be able to bundle multilingual endpoints into a single endpoints (for efficiency reasons and build time performance). Ideally, we could create a way to use the langcode returned from the entity instead of just using a constant language prefix from gatsby-config.
-
This isn't going to work with incremental builds, fastbuilds, or instant preview yet. In utils.js there is a handleWebhookUpdate function that needs some updating. I think this is the start of what needs updating. Right now it just tries to use the UUID to find the node, we need to make sure it appends the same language prefix here so it finds the correct node.
| let allData | ||
| try { | ||
| const data = await axios.get(`${baseUrl}/${apiBase}`, { | ||
| const data = await axios.get(`${baseUrl}/${languagePrefix}/${apiBase}`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this always work? It seems that this will default to "/en/jsonapi" which doesn't seem to work out of the box with JSON:API.
I think the better approach might be to default to the current URL (baseURL/apiBase) unless a language prefix is added to gatsby-config.js. If it's added then it can be appended to the URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw the same thing, fortunately Drupal does redirect /// to / so in the case a languagePrefix is not specified it would change to baseUrl//jsonapi rather than baseUrl/es/jsonapi which both work. I don't like forcing a redirect in default case though so I will definitely refactor this so that it's not required when langaugePrefix is not specified.
|
Got fast builds working with the translated content there's just some funkiness going on with the relationships in the translated content that needs to be resolved. Most likely the references are just missing their prefixes in some cases. |
|
@smthomas With the I might rework this PR to do that but for the mean time we are using a forked version that just specifies the If we only have to pull translations for content that has translations available it should make the process a lot faster rather than including 2 different This request will get all translatable entities:
|
…her languages when pulling translations
|
Closed in favor of #26720 |
Description
We're currently using
gatsby-source-drupalto pull content from our D8 site and we got stuck trying to pull content from another language because it gets overwritten by the last source plugin in the list. eg.gatsby-config.jsDocumentation
languageanddefaultLanguageto the README.mdRelated Issues
Addresses #10020