How to persist multiple localizations at once? #2421
Replies: 5 comments 4 replies
-
Hey @luca-nardelli, saving multiple locales is on our radar, but I can't say when it will be available.
To avoid this, you'll need to use the mongoose models directly instead of Payload's APIs until we can build it in. Does that help? |
Beta Was this translation helpful? Give feedback.
-
It does! However, how do I access the models directly? I tried looking for this in the docs but did not find pointers. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Didn't know that, cool! Thanks for the help, will try later. Is this something that could be added to the docs? If so, I can see if I have some time to write something down. |
Beta Was this translation helpful? Give feedback.
-
I'm dealing with multiple languages right now and I have to say that a bulk update of all locales is a very important feature. Without a bulk edit you will run into inconsistencies. If fields are required AND localized the current system won't enforce the right localization. Instead it relies on the fallback language mechanism which just provides the wrong translation. There should be at least a flag in the config which enforces a strict localization. A document should only save if every localized field is translated. The same goes for the API. It should be possible or needed (if strict translation turned on) that if a document is updated/created every translation is mandatory and there needs to be a way to pass these in one API call. If a translation is missing Payload should reject the operation completly. Without these behaviour there will be data which don't fullfill the contract of the type. If you fetch a language which wasn't provided but the field is required and therefor it is not optional and has to be set in the right language. |
Beta Was this translation helpful? Give feedback.
-
Do we have any updates on this for v3? I have a similar problem: I'm writing an export / import feature, where I want to export a collection, to eventually import this on another environment. This collection has localized fields, so I initially wanted to do something like this: Having a collection with a localized field: ...
fields: [
{
name: 'question',
label: 'Question',
type: 'text',
localized: true,
required: true,
},
... const posts = await payload.find({
collection: 'posts',
pagination: false,
locale: 'all',
}) Note that now question isn't of type string, but an object like: {
question: {
en: 'Hello',
nl: 'Hallo',
}
} To eventually import it: await payload.create({
collection: 'posts',
data: posts, // containing the localized question field
}); This isn't possible now. I could of course iterate through all the available locales, and create one and then update the entry for the remaining languages, but this feels very cumbersome. |
Beta Was this translation helpful? Give feedback.
-
Hi all!
I was looking into the localization solution that Payload offers out of the box, however I cannot seem to find a way to persist multiple languages at once within the same API call.
If I try to push the object representation of the field (e.g.
{it: '...', en: '...'}
) instead of the field value, I either get a mongoose validation error if I don't specify the locale or I don't get anything persisted if I setlocale: 'all'
.Does anyone know how to achieve this? I wanted to run some bulk imports of data and I would like to avoid sending 1 update request for every locale
Beta Was this translation helpful? Give feedback.
All reactions