Skip to main content

Server side rendering

Note: This page is specific to application built on top of Next.js

Oneki.js proposes a help function to use the translation files on server side

NameTypeDescription
withI18nStaticProps(locale: string, staticProps?: StaticProps, namespaces: string[] = []): anyInject the content of the translation files in the props that will be received by the page component

Note: if no namespace are specified, only the common file is injected

Example

If the translation file public/locales/fr/common.json is:

{
"Welcome": "Bienvenue"
}

then
withI18nStaticProps('fr', {
props: {
name: 'Doe',
firstname: 'John'
},
});

returns
{
props: {
name: 'Doe',
firstname: 'John',
translations: {
common: {
"Welcome": "Bienvenue"
}
}
}
}

The <App /> component can automatically retrieve the translations of this structure

Example