Skip to content

Commit

Permalink
feat: add localization support
Browse files Browse the repository at this point in the history
  • Loading branch information
BolajiAyodeji committed Feb 16, 2021
1 parent 53cc8b7 commit 89b3457
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion studio/schemas/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
{
name: 'name',
title: 'Name',
type: 'string',
type: 'localeString',
validation: (rule) => rule.required(),
},
{
Expand Down
2 changes: 1 addition & 1 deletion studio/schemas/country.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
{
name: 'name',
title: 'Name',
type: 'string',
type: 'localeString',
validation: (rule) => rule.required(),
},
{
Expand Down
19 changes: 19 additions & 0 deletions studio/schemas/locale/Slug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import supportedLanguages from "./supportedLanguages"

export default {
name: "localeSlug",
type: "object",
fieldsets: [
{
title: "Translations",
name: "translations",
options: {collapsible: true},
},
],
fields: supportedLanguages.map((lang) => ({
title: lang.title,
name: lang.id,
type: "slug",
fieldset: lang.isDefault ? null : "translations",
})),
}
3 changes: 1 addition & 2 deletions studio/schemas/locale/supportedLanguages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default [
{id: "en", title: "English", isDefault: true},
{id: "es", title: "Spanish"},
{id: "nb", title: "Norwegian"},
{id: "it", title: "Italian"}
]
6 changes: 3 additions & 3 deletions studio/schemas/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export default {
id: 'name',
name: 'name',
title: 'Name',
type: 'string',
type: 'localeString',
validation: (rule) => rule.required(),
},
{
id: 'description',
name: 'description',
title: 'Description',
type: 'text',
type: 'localeText',
},
{
id: 'slug',
name: 'slug',
title: 'Slug',
type: 'slug',
type: 'localeSlug',
options: {
source: 'Name',
maxLength: 200,
Expand Down
4 changes: 2 additions & 2 deletions studio/schemas/productImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export default {
{
name: 'name',
title: 'Name',
type: 'string',
type: 'localeString',
validation: (rule) => rule.required(),
},
{
name: 'description',
title: 'Description',
type: 'text',
type: 'localeText',
},
{
name: 'images',
Expand Down
4 changes: 3 additions & 1 deletion studio/schemas/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import blockContent from './blockContent'
import productImage from './productImage'
import localeString from './locale/String'
import localeText from './locale/Text'
import localeSlug from './locale/Slug'
import localeBlockContent from './locale/BlockContent'

// Then we give our schema to the builder and provide the result to Sanity
Expand All @@ -36,8 +37,9 @@ export default createSchema({
// { type: "typename" } in other document schemas
productImage,
blockContent,
localeString,
localeText,
localeSlug,
localeBlockContent,
localeString,
]),
})
2 changes: 1 addition & 1 deletion studio/schemas/size.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
id: 'name',
name: 'name',
title: 'Name',
type: 'string',
type: 'localeString',
validation: (rule) => rule.required(),
},
],
Expand Down
8 changes: 4 additions & 4 deletions studio/schemas/taxon.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ export default {
{
name: 'name',
title: 'Name',
type: 'string',
type: 'localeString',
validation: (rule) => rule.required(),
},
{
name: 'label',
title: 'Label',
type: 'string',
type: 'localeString',
},
{
name: 'slug',
title: 'Slug',
type: 'slug',
type: 'localeSlug',
options: {
source: 'Name',
},
Expand All @@ -30,7 +30,7 @@ export default {
{
name: 'description',
title: 'Description',
type: 'text',
type: 'localeText',
},
{
name: 'images',
Expand Down
4 changes: 2 additions & 2 deletions studio/schemas/taxonomy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export default {
{
name: 'name',
title: 'Name',
type: 'string',
type: 'localeString',
validation: (rule) => rule.required(),
},
{
name: 'label',
title: 'Label',
type: 'string',
type: 'localeString',
},
{
name: 'taxons',
Expand Down
4 changes: 2 additions & 2 deletions studio/schemas/variant.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
{
name: 'name',
title: 'Name',
type: 'string',
type: 'localeString',
validation: (rule) => rule.required(),
},
{
Expand All @@ -22,7 +22,7 @@ export default {
{
name: 'description',
title: 'Description',
type: 'text',
type: 'localeText',
},
{
name: 'images',
Expand Down

0 comments on commit 89b3457

Please sign in to comment.