Closed gaauwe closed 1 year ago
Thanks for this @gaauwe! A feature I'd wanted myself :)
I've tagged @stipsan on this since he added the function to fetch Languages and may have thoughts on the work here.
:tada: This PR is included in version 1.6.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Great work so far on this plugin @SimeonGriggs! Loading the languages asynchronously helps us a lot. In our case (as discussed with Tom in our Sanity x Belsimpel trial), we needed to load languages based on data in a document, so I want to take this opportunity to share this feature.
Feature
I looked into multiple options for providing the document as parameter to the language callback, but the tricky thing is that the document changes a lot while editing. This made it so that the languages kept reloading and reloading. In the end, I wound up building a solution that's very similar to Sanity list previews. You can select your own fields in the document that should trigger a reload, and you get those fields directly in the language callback:
Possible optimization
This works great already, but I have a small optimization in mind that I could use your help on. In our case, we want to load languages based on an array of references. The minor issue that we're seeing is that once you add an item to the array, it updates the document with an empty reference already before you choose a value: UI, data. Ideally we'd only want to reload languages if an actual reference value is filled in, do you know if there is a good way to fix this?