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
Name | Type | Description |
---|---|---|
withI18nStaticProps | (locale: string, staticProps?: StaticProps, namespaces: string[] = []): any | Inject 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"
}
withI18nStaticProps('fr', {
props: {
name: 'Doe',
firstname: 'John'
},
});
{
props: {
name: 'Doe',
firstname: 'John',
translations: {
common: {
"Welcome": "Bienvenue"
}
}
}
}
The <App /> component can automatically retrieve the translations of this structure