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

Differentiate between languages in Documents List #143

Closed
lauradecc opened this issue Jun 12, 2023 · 2 comments
Closed

Differentiate between languages in Documents List #143

lauradecc opened this issue Jun 12, 2023 · 2 comments

Comments

@lauradecc
Copy link

lauradecc commented Jun 12, 2023

I am trying to display the language of each document in the documents list.

Reading the documentation I found a way to display a list of the different singleton languages, but how can it be done for documents?

I tried to modify the structure based on the Structure Builder Reference documentation, but I can only list the documents with documentTypeListItem, and I don't know how to access each document and its data. In the case of singletons, we know in advance what we want to create, while with documents we don't (for example, if we were talking about blog posts, they would be created from sanity studio).

I saw something similar to what I want to do, but creating a custom tool. I don't quite understand how to use that documentation, but still, I need it on the desk to diff when creating/editing.

This issue (Differentiating between languages in reference selector) is related, as I would also like to achieve that, but I think it's not the same, and it hasn't been answered yet.

In summary, as an example, if we had two languages and with the same titles, how could we show the language in the list of documents?
Captura de pantalla 2023-06-12 a las 12 27 33

This is the goal (but with documents list):
image

I understand that there should be a way to do it, because the more languages, the more difficult it will be to deal with if we don't know the language (both with references and for editing, for example).

Thanks in advance!

@lauradecc lauradecc changed the title differentiate between languages in Documents List Differentiate between languages in Documents List Jun 12, 2023
@deanfields
Copy link

deanfields commented Jun 12, 2023

I'm quite new to Sanity CMS so apologies if this doesn't help at all, but I have just done this by putting this in the schema for the document:

preview: {
    select: {
      title: 'title',
      language: 'language',
    },
    prepare({ title, language }) {

      const formattedLanguage = language ? `(${language.toUpperCase()})` : null
      const titleFormat = language ? `${title} ${formattedLanguage}` : title

      return {
        title: titleFormat,
        subtitle: 'Page',
      }
    },
  },

@lauradecc
Copy link
Author

This was exactly what I needed! And it also solves the other issue I mentioned in the description.

Here the documentation that I found about it after reading your comment: List Previews. It may be useful for someone else.

Thank you very much!

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

2 participants