Skip to main content

@mercell/i18n

Introduction

This packages is to used in combination with i18next and Sanity CMS. It exposes the following feature:

Usage

Prerequisites

Installation

Install the package

yarn add @mercell/i18n

You'll need to configure the i18n instance with using the SanityBackend. This can have slight variations depending on your application framework.

import {
I18nextBrowserLanguageDetector,
LOCALE,
SanityBackend,
} from '@mercell/i18n';
import i18n from 'i18next';

i18n.use(SanityBackend)
.use(I18nextBrowserLanguageDetector)
.init({
fallbackLng: LOCALE,
backend: {
backendOption: {
sanity: {
projectId: '<SANITY_PROJECT_ID>',
dataset: 'production',
useCdn: true,
},
},
},
});

That should be it. Now just fetch your t-function from your i18next framework and use the translations from sanity.