Skip to content

Enhancing translation reference selection in document internationalization #186

@Ortes

Description

@Ortes

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 {}
        },
      },
    }),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions