Replies: 1 comment 3 replies
-
You'd be surprised! The yankees at TRBL are actually currently localizing like 3 separate large-scale sites that were all built with headless WP before Payload was released. It's thrilling, let me tell you. One of the reasons we decided to build Payload was because of the industry's lack of support for proper localization, and even though our features can still be expanded, I think we have the requisite groundwork and infrastructure to do exactly that: expand those features. That said, this discussion is great. I have some ideas bubbling already, but let me see if I can break down solutions / ask questions regarding each of your points:
I'm not sure if this is possible in your case, but you could just request the top-level document in a specified locale, and the document returned from the For example, if you are requesting all pages with
Payload passes on top-level locales through all APIs so in most cases you wouldn't need to do anything there. I might be missing your goal here entirely though. Alternatively, if for some reason you need to know the document's language and can't simply request with a specified locale, you could do something like the below field hook: const pages = {
slug: 'pages',
fields: [
{
name: 'language',
type: 'select',
options: [
{
label: 'English',
value: 'en',
},
{
label: 'German',
value: 'de',
},
],
},
{
name: 'nonLocalizedRelationship',
type: 'relationship',
relationTo: 'some-other-collection',
hooks: {
afterRead: [
async ({ req, value, data }) => {
// Manually "populate" the related document in the document's set language
return req.payload.findByID({
id: value, // the ID of the related document that is saved to db
collection: 'some-other-collection',
locale: data.language // the language from full document being read
});
}
]
}
},
],
} I have not tested the above but the idea in principle should work and is basically just you being responsible for returning that relationship data however you need, based on the language set on the doc itself. Note - this approach will lose out on a bit of Payload's internal performance optimizations we've built into the auto-population
Phew. Got carried away with that second example. Curious to hear if that is what you meant / if the solution I offered is relevant. Big chance I totally missed what you were going for. Let's keep this going! |
Beta Was this translation helpful? Give feedback.
-
Since it seems most of the issues I'm running into are related to multilingual and localisation, I thought it might be best to start one open discussion for all issues related to this. You yankees don't get what we have to deal with over here in Europe ;) Still, one of the reasons I'm betting on Payload for the long-term is for its already great localisation support and all the building blocks are there.
If you guys don't agree with an open forum like approach, please - knowing I'd fully understand - remove this discussion so I can open separate issues that are "real" issues. Not yet sure what the goal of discussions is on GitHub, but this seems to be one 🙃
Otherwise I'll elaborate on the issues listed below more;
language
field - and needs to have a relationship to a localised field. Right now a relationship contains the collection and id, but not localeI'll continue to detail these issues below, directions I tried and what I felt worked best if this is the way to discuss this. Anyone that can burn everything - or just a little thing here or there - I did to the ground; please do.
Questions on how I did things are also more than welcome. Open forum code-review ftw.
Beta Was this translation helpful? Give feedback.
All reactions