Skip to content

kaliberjs/sanity-plugin-multi-language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Nov 29, 2024
176ddb6 · Nov 29, 2024
Oct 29, 2021
Nov 29, 2024
Sep 4, 2023
Sep 4, 2023
Sep 4, 2023
Sep 19, 2023
Nov 29, 2024
Sep 20, 2023
Sep 27, 2022
Sep 4, 2023
Sep 2, 2023

Repository files navigation

Kaliber Sanity Multi Language Plugin

Document level translations.

Installation

> yarn add @kaliber/sanity-plugin-multi-language

Usage

sanity.config.js

import { addFields as addMultiLanguageFields } from '@kaliber/sanity-plugin-multi-language'

defineConfig({
  plugins: [
    deskTool({
      defaultDocumentNode: (S, context) => {
        const getClient = context.getClient.bind(context)

        const views = [
          S.view.form(),
          typeHasLanguage(context) && S.view
            .component(Translations)
            .options({ multiLanguage, reportError })
            .title('Translations'),
          
        ].filter(Boolean)

        return S.document().views(views)
      }
    }),
  ],
  schema: {
      types: (prev, context) => prev
        .concat(schemaTypes)
        .map(addMultiLanguageFields({ multiLanguage: clientConfig.multiLanguage, reportError })),
    },
})

schema/documents/page.js

export const page = {
  type: 'document',
  name: 'page',
  title: 'Page',
  options: {
    kaliber: {
      multiLanguage: true,
      ...
    },
    ...
  },
  ...
}

Config

config.multiLanguage

{
  defaultLanguage: 'nl',
  languages: {
    nl: {
      title: 'Dutch',
      adjective: 'dutch',
      language: 'nl',
      icu: 'nl_NL'
    },
    en: {
      title: 'English',
      adjective: 'english',
      language: 'en',
      icu: 'en_US'
    }
  },
}

Development

In this plugin:

> yarn
> yarn link

In your project:

> yarn link @kaliber/sanity-plugin-multi-language 

Publish

yarn publish
git push
git push --tags