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

Translatable string list option #24

Closed
mikkopaderes-iona opened this issue Jul 1, 2023 · 4 comments
Closed

Translatable string list option #24

mikkopaderes-iona opened this issue Jul 1, 2023 · 4 comments

Comments

@mikkopaderes-iona
Copy link

I may be missing something, but is there a solution for string list option to be translatable?

defineField({
  name: 'categories',
  title: 'Categories',
  type: 'string',
  options: {
    // This should be translatable
    list: [
      'Shirts',
      'Shorts',
      'Shoes',
    ]
  }
})
@SimeonGriggs
Copy link
Collaborator

SimeonGriggs commented Jul 2, 2023

Use the same method described in this section

// listType.ts

import { defineType } from "sanity";

export const listType = defineType({
    name: 'list',
    type: 'string',
    options: {list: ['one', 'two', 'three']},
  })

Register that to your schema types in sanity.config.ts

Then add the custom type to your plugin config:

internationalizedArray({
  // ...other settings
  fieldTypes: ['list']
})
Screenshot 2023-07-02 at 19 49 51

@mikkopaderes-iona
Copy link
Author

mikkopaderes-iona commented Jul 3, 2023

@SimeonGriggs but that means we get English choices only even for the other languages. With this, what's going to happen is only being able to choose a different choice per language, not the actual content being translated.

@SimeonGriggs
Copy link
Collaborator

Got it. In that instance, perhaps rethink the content model. If you need "the same value, but in different languages," perhaps the field only needs to be set once, and your consuming applications display the right language value.

Instead of having the same value set in different languages, independently in separate fields.

@mikkopaderes-iona
Copy link
Author

Hmm, yes, that would be an alternative approach. Not quite the same experience with the other translatable resources but we could try that if there's no built-in solution. Thanks

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