Skip to content

next-i18next example of loading translations from a non-public directory

Notifications You must be signed in to change notification settings

HugoDF/next-i18next-shared-translations-example

Repository files navigation

next-i18next shared translations example

Modified version of next-i18next "simple" example.

Showcases the ability to load translations conditionally from a directory other than public based on the namespace (or locale).

Approach

next-i18next.config.js, uses a localePath function which checks the namespace. In order for next-i18next to work, ns and serializeConfig: false need to be provided.

Passing the next-i18next configuration to appWithTranslation in ./pages/_app.tsx and each page's serverSideTranslations.

The footer content is loaded from non-public (node_modules also works but only tested on Mac where cp is available, after running npm run dev:setup).

  localePath(locale, namespace) {
    if (namespace === 'footer') {
      return `./non-public/locales/${locale}/${namespace}.json`;
    }
    return `./public/locales/${locale}/${namespace}.json`;
  },

About

next-i18next example of loading translations from a non-public directory

Topics

Resources

Stars

Watchers

Forks