Skip to content
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

Enhancing translation reference selection in document internationalization #186

Open
Ortes opened this issue Apr 28, 2024 · 0 comments
Open

Comments

@Ortes
Copy link

Ortes commented Apr 28, 2024

I came across the problem describe in the here. It is about selecting the right translation reference in the list.

This issue solve this problem by adding suffix to the title of the document this works fine but I wonder if we could find a better way.
The problem is that for each document the contributor needs to select the right translated document.
This is also error prone.

I found 3 potential solutions for this:

  • When creating a document we fill the whole document in one language and when we add the new translation for this document all references are change to translated document reference if exists.
  • In the selection document list filter documents with the current document language (better solution both would be even better)
  • Select any translation of the same document in the reference field and fetch the right translation at run time while fetching documents

I am new to sanity can any of the first 2 solutions already be implemented without changing the plugin ?

EDIT:

It seems like the second solution is already possible like this:

    defineField({
      name: 'exercise',
      type: 'reference',
      to: [{type: 'exercise'}],
      options: {
        filter: ({ document }) => {
          const { language } = document

          if (language) {
            return {
              filter: 'language == $language',
              params: {
                language: language,
              },
            }
          }

          return {}
        },
      },
    }),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant