npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

next10-intl

v0.0.5

Published

A simple i18n solution for next.js 10+ based on react-intl that doesn't force you to include all your messages in your main bundle

Readme

A simple internationalisation solution for next.js 10+ based on react-intl that doesn't force you to include all your messages in the final bundle.

Description

Since version 10, Next.js supports the internationalisation of routes and all you have to do is use the library of your choice to manage the localisation of messages in your application. React-intl is very suitable for this task, however you may wish to reduce the first load size of your pages by initially loading only the translations you need.

With next10-intl, only the essential messages present on all pages will be present in your main bundle. Messages specific to each page can be loaded individually, using a namespacing system.

Advantages of this approach:

  • You can separate the translations of your application by namespaces
  • your pages are lighter since not all translations are included in the bundle

Disadvantages:

  • the payload of pages that depend on one or more namespaces is a bit heavier, since messages in questions are included in the page props (in the requested locale).

If you have any ideas on how not to include translations in the pages props (without flashes of translations temporally unavailable), I'm listening!

Notes

I have only tested this with a statically generated next.js application. But I don't see why it wouldn't work with a dynamic application with SSR that uses getServerSideProps rather than getStaticProps.

Setup

npm install next10-intl

or

yarn add next10-intl

Follow the next.js instructions to implement internationalisation on your project: https://nextjs.org/docs/advanced-features/i18n-routing#getting-started

Then you need to add a locales folder containing your messages. For example, if you have configured your project with the locales en, fr and de:

src/locales
├── de
│   ├── category.json
│   ├── common.json
│   ├── home.json
│   └── project.json
├── en
│   ├── category.json
│   ├── common.json
│   ├── home.json
│   └── project.json
└── fr
    ├── category.json
    ├── common.json
    ├── home.json
    └── project.json

where common.json will contain translations shared throughout the application.

Create a next10Intl.js file:

import { Next10Intl } from 'next10-intl';

export default new Next10Intl({
  messagesPath: 'src/locales', // relative to the root of your application
  // this will have webpack include our common messages in the bundle
  loadCommonMessages: (locale) => require(`locales/${locale}/common.json`),
});

Then you need to wrap your application with the Next10IntlProvider, configured like this:

import { Next10IntlProvider } from 'next10-intl';
import next1OIntl from 'config/next10Intl';

function MyApp({ Component, pageProps }) {
  return (
    <Next10IntlProvider
        pageContext={pageProps.i18n}
        next1OIntl={next1OIntl}
    >
        <Component {...pageProps} />
    </Next10IntlProvider>
  );
}

export default MyApp;

For each of your pages, specify the namespaces to load. Example with getStaticProps, in the case of a static site:

import next10Intl from '../config/next10Intl';

export async function getStaticProps({ locale }) {
  return {
    props: {
      //... (your props here)
      i18n: await next10Intl.getI18nContext(locale, ['first_namespace', 'second_namespace']]),
    },
  };
}

Using the useNext10Intl hook

react-intl is handy, but it can be very verbose even for simple things. useNext10Intl exposes a function, t, enough for translating messages in most cases, that allows you to load a message for a given namespace.

import { useNext10Intl } from 'next10-intl';

const MyComponent = () => {
    const { t } = useNext10Intl();
    return <button className={styles.submit} type="submit">{t('search')}</button>
}

By default, messages are retrieved from the 'common' namespace. If you wish to specify a different namespace, specify its name as the second argument. To pass variables as parameters, pass an object as the third argument.

t('currently-displaying-project', 'project', { project: project.title })

Use of react-intl components

You can use directly the components offered by react-intl. You will just have to be careful to prefix by the namespace you want to use (including for the common namespace) all the ids of the messages.

<FormattedMessage
  id="common:greeting"
  description="Greeting to welcome the user to the app"
  defaultMessage="Hello, {name}!"
  values={{
    name: 'Eric',
  }}
/>

Using the useIntl hook

In the same way, you can continue to use the useIntl hook as usual:

const  intl = useIntl();

const messages = defineMessages({
greeting: {
    id: 'common:greeting',
    defaultMessage: 'Hello, <bold>{name}</bold>!',
    description: 'Greeting to welcome the user to the app',
  },
})

intl.formatMessage(greeting, {
  name: 'Eric',
  bold: str => <b>{str}</b>,
});