-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V3-languages for localisation (#646)
* cleanup of deskstructure * language for localization * renaming from languagedetails to supportedlanguages * update schema with supportedLanguage * Update studio/schemas/deskStructure.ts Co-authored-by: christinaroise <[email protected]> * variablename update * Update studio/schemas/deskStructure.ts Co-authored-by: Mathias Oterhals Myklebust <[email protected]> * Update studio/schemas/deskStructure.ts Co-authored-by: Mathias Oterhals Myklebust <[email protected]> * variable name fix --------- Co-authored-by: christinaroise <[email protected]> Co-authored-by: Mathias Oterhals Myklebust <[email protected]>
- Loading branch information
1 parent
5b415d7
commit 96f69a3
Showing
4 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { defineType } from "sanity"; | ||
import { languages } from "languages"; | ||
|
||
const languageOptions = languages.map((language) => { | ||
return { title: language.title, value: language.id }; | ||
}); | ||
|
||
export const supportedLanguagesID = "supportedLanguages"; | ||
|
||
const supportedLanguages = defineType({ | ||
name: supportedLanguagesID, | ||
type: "document", | ||
fields: [ | ||
{ | ||
name: "languages", | ||
type: "array", | ||
description: | ||
"Select languages available for translation and designate one as the default language for the homepage.", | ||
of: [ | ||
{ | ||
type: "object", | ||
fields: [ | ||
{ | ||
name: "language", | ||
type: "string", | ||
description: "Select the language available for translation", | ||
title: "Language", | ||
options: { | ||
list: languageOptions, | ||
}, | ||
}, | ||
{ | ||
name: "isDefault", | ||
type: "boolean", | ||
title: "Default Language", | ||
description: | ||
"Indicate whether the language should be set as the default. Please note that only one default language is allowed.", | ||
}, | ||
], | ||
preview: { | ||
select: { | ||
title: "language", | ||
}, | ||
prepare(selection) { | ||
const { title } = selection; | ||
const languageOption = languageOptions.find( | ||
(option) => option.value === title, | ||
); | ||
return { | ||
title: languageOption ? languageOption.title : title, | ||
}; | ||
}, | ||
}, | ||
}, | ||
], | ||
validation: (Rule) => | ||
Rule.custom((languages: { language: string; isDefault: boolean }[]) => { | ||
const defaultLanguages = languages.filter((lang) => lang.isDefault); | ||
if (defaultLanguages.length > 1) { | ||
return "Only one default language is allowed"; | ||
} | ||
if (defaultLanguages.length === 0 && languages.length > 0) { | ||
return "At least one language must be marked as default"; | ||
} | ||
return true; | ||
}), | ||
}, | ||
], | ||
}); | ||
|
||
export default supportedLanguages; |