tinloof / sanity-kit

83 stars 11 forks source link

feat: add requireLocale option to allow working with non-translatable page types even with i18n enabled #57

Closed marcusforsberg closed 5 months ago

marcusforsberg commented 5 months ago

Here's a use case I don't necessarily know if you wish to support but that I hope you'll consider. 😊

For our current project, we have a mix of localized and non-localized page types which we want to be able to access from the navigator. Since they all have a pathname field they automatically show up in the navigator, up until i18n is enabled at which point the list is filtered by the selected locale, causing the page types that don't have a locale field at all to disappear and become inaccessible.

This PR adds a requireLocale option which can be set to false in order to get the non-localized page types to show up in the list regardless of the filtered locale.

For example, take an employee type which maps to an employee profile page on the front-end, which we want editors to be able to live preview and edit within Presentation. These documents only have a couple of translatable fields for which we use internationalized arrays instead of separate documents. With requireLocale set to false these documents are now accessible despite not having a locale field:

Screenshot 2024-05-31 at 17 16 59
thomasKn commented 5 months ago

Thanks for the PR @marcusforsberg, it looks great! Can you just add a changeset file using pnpm run changeset?

marcusforsberg commented 5 months ago

@thomasKn Done, hopefully!

marcusforsberg commented 5 months ago

@thomasKn I went ahead and merged main to fix the conflict 😊