Ni18n
  • README
  • Usage
    • Installing
    • Getting Started
    • Server Side Loading
    • Client Side Loading
  • Extras
    • List of Examples
    • F.A.Q.
Powered by GitBook
On this page

Was this helpful?

  1. Usage

Client Side Loading

PreviousServer Side LoadingNextList of Examples

Last updated 3 years ago

Was this helpful?

All the namespaces are always loaded on the client side if no or clientNamespaces are called on a page's server callback. In order to prevent that, you can use clientNamespaces to only allow the client to load the specific namespaces given to the function.

// pages/index.ts

export const getStaticProps = async (props) => {
  return {
    props: {
      ...clientNamespaces(['client-namespace']),
    },
  }
}

You can use both or clientNamespaces in the same page if necessary.

// pages/index.ts

export const getStaticProps = async (props) => {
  return {
    props: {
      ...(await loadTranslations(ni18nConfig, props.locale, [
        'server-namespace',
      ])),
      ...clientNamespaces(['client-namespace']),
    },
  }
}
loadTranslations
loadTranslations