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 🙏

© 2024 – Pkg Stats / Ryan Hefner

next-ntms

v0.0.994

Published

A dead simple way to add i18n to your Next.js app using the Notion API and Deepl

Downloads

10

Readme

next-ntms

Turn your Notion into a powerful, collaborative and automatic Translation Management System for your next.js app.

Features 😻

  • Very small footprint. 🌬️
  • Notion as main source of truth thanks to their API. ⭐
  • Empower non technical users to directly improve your site content for better DX and TeamX. 👩‍❤️‍👩
  • Render simple string or complex rich text. 📝
  • Automatic and precise translation into more than 20 languages thanks to the DeepL API integration. 🌍
  • Data efficient:
    • Translations are fetched and revalidate in the background using next.js getStaticProps.⚡
    • Client receive only necessary translations based on his localization. ⚡
  • Extendable with translations outside of notion. ⇒ incremental adoption. 🔓
  • Familiar and boilerplate-free api as it's rely on Next.js locale configuration. 💫

Drawbacks 😿

  • next-ntms rely on getStaticProps i.e: translation fetching cannot be use in combination with getServerSideProps as Next.js sadly don't allow this for now ⇒ see [#11424] While it's still possible to use the getStaticTranslations function inside your server side logic, we do not advice to do so because of the speed of the Notion API. A workaround would be to encapsulate all you components translations inside small databases and use your _app getStaticProps to fetch them.
  • As the Notion API is still in beta and only return text-like blocks, this library is not (yet) suitable for a full and complex translated content management system.

Getting started 💨

npm i next-ntms
  1. Notion:
    1. Create your notion integration.
    2. get your api key.
    3. allow your integration to access your translations databases.
    4. set your NOTION_API_KEY inside your environnement variables.
  2. Automatic translation:
    1. set DEEPL_API_KEY inside your environnement variables.
    2. set DEEPL_URL inside your environnement variables.
    3. define your locale to DeepL target_lang mapping in your next.config.js file under serverRuntimeConfig.ntms.deepl object.
  3. Configure your i18n strategy inside next.config.js file and make sure to add the corresponding columns in your Notion's databases.
  4. Export a getStaticProps function of your translated pages as getStaticTranslations (or use the fetchTranslations function to pass a translations props to your page).
  5. Wrap your page with the withTranslation HOC
  6. Display your translations with the useTranslation hook or the Trans component.

Documentation

Documentation

Minimal example

databaseName | key | en | fr | |----------------|-------------------|------------------------| | translationKey | ntms is awesome ! | ntms est fantastique ! |

next.config.js

module.exports = {
  i18n: {
    locales: ['en', 'fr'],
    defaultLocale: 'en'
  },
  serverRuntimeConfig: {
    ntms: {
      deepl: {
        fr: 'FR'
      }
    }
  }
}

/pages/translatedPage.js

import {
  withNotionTranslation,
  getStaticTranslations,
  useTranslation
} from 'next-ntms'

const TranslatedPage = () => {
  const { t } = useTranslation()
  return (
    <div>
      <h1>{t('databaseName.translationKey')}</h1>
      {/*
    will display either "ntms is awesome !"
    or "ntms est fantastique !"
    depending on the locale
    */}
    </div>
  )
}

export const getStaticProps = getStaticTranslations('databaseId')

export default withNotionTranslation(TranslatedPage)