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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dontepsu/gatsby-plugin-awesome-i18next

v1.7.0

Published

Gatsby plugin to integrate i18next

Downloads

53

Readme

Gatsby plugin for i18next

Gatsby plugin that wraps react-i18next and supports localized urls.

Installation

npm i -S @dontepsu/gatsby-plugin-awesome-i18next i18next react-i18next

Usage

To use to the plugin, you need to define the translations in a JSON file and add config object to gatsby.config.js.

Gatsby config

In gatsby-config define following configuration to the plugin.

{
  resolve: `gatsby-plugin-awesome-i18next`,
  options: {
    availableLngs: ['en', 'fi'],
    fallbackLng: 'en',
    siteUrl: 'https://www.example.com/',
},

Locales

In the project root add the translations JSON files as follows:

root
- locales
  - en
    messages.json
    my-namespace.json
  - fi
    messages.json
    my-namespace.json

these translation will be available in the Gatsbys GraphQL.

Add to pages

export const query = graphql`
  query($lng: String!) {
    locales: allLocale(filter: { lng: { eq: $lng }, ns: { regex: "/messages|my-namespace/i" } }) {
      ...LocaleFragment
    }
  }
`;

export default withI18next(MyPageComponent, {
  // optional hook
  afterI18nInit: (18next => doSomethingAfteInit(i18next),
});

Usage in components

This plugin is designed to be used with useTranslation-hook. For more information please refer to React-i18next documentation.

This plugin exports an extended version of useTranslation-hook.

import { useTranslation } from 'gatsby-plugin-awesome-i18next';

const Component = () => {
  const {
    t,
    i18n, 
    context, 
    resolvePath, 
    resolveAllLanguageVersions,
    changeLang
  } = useTranslation([ 'my-namespace' ]);

  return <h1>{t('my-namespace:Component.hello')}</h1>;
}

Localized URLS

Feature to enable url localization. URL localization will be done in gatsby-node.onCreatePage hook. Developer should not worry about hanlding the localzied url when creating linking within pages in Gatsby project.

The urls

Localized URL Example

{
  resolve: `gatsby-plugin-awesome-i18next`,
  options: {
    availableLngs: ['en', 'fi'],
    fallbackLng: 'en',
    siteUrl: 'https://www.example.com/',
    localizedPaths: {
      '/about/': {
        fi: '/tietoja/',
      },
      '/products/:slug/': {
        fi: '/tuotteet/:slug',
      },
      /products/:slug/subsite': {
        fi: '/tuotteet/:slug/subsite',
      },
    },
  },
},

Localized URL with Localized Paths Example

{
  resolve: `gatsby-plugin-awesome-i18next`,
  options: {
    availableLngs: ['en', 'fi'],
    fallbackLng: 'en',
    siteUrl: 'https://www.example.com/',
    localizedPaths: {
      '/about/': {
        fi: '/tietoja/',
      },
      '/products/:slug/': {
        fi: '/tuotteet/:slug',
      },
      /products/:slug/subsite': {
        fi: '/tuotteet/:slug/subsite',
      },
    },
    pathParametersLocalizations: {
      ':slug': {
        'chocolates': {
          fi: 'suklaat',
        }
      }
    }
  },
},

Ignore paths

Ignore paths that you don't want this plugin to process. You can use one of the following:

  1. Set of strings
{
  resolve: `gatsby-plugin-awesome-i18next`,
  options: {
    availableLngs: ['en', 'fi'],
    fallbackLng: 'en',
    siteUrl: 'https://www.example.com/',
    ignorePaths: new Set([
      '/oauth-callback/',
    ])
  },
},
  1. Array of string
{
  resolve: `gatsby-plugin-awesome-i18next`,
  options: {
    availableLngs: ['en', 'fi'],
    fallbackLng: 'en',
    siteUrl: 'https://www.example.com/',
    ignorePaths: [
      '/oauth-callback/',
    ]
  },
},
  1. function => boolean
{
  resolve: `gatsby-plugin-awesome-i18next`,
  options: {
    availableLngs: ['en', 'fi'],
    fallbackLng: 'en',
    siteUrl: 'https://www.example.com/',
    ignorePaths: page => page.path.substr(0, path.length - 1) === '/oauth-callback'
  },
},

Linking to pages

Plugin exports a <Link /> component that takes a non localized url as props.to

import { Link } from 'gatsby-plugin-awesome-i18next';

const LinkComponent = () => {
  return <Link to="/about/">{t('my-namespace:LinkComponent.about_link')}</Link>;
}

If you use localized paths, the default language url will be automatically translated to localized url.

Contributors

  • Kodit.io - Europes #1 real estate instant buyer

Change log

1.7.0

  • Ignore paths: Specify routes that you want this plugin to ignore

License

MIT