0.0.994 • Published 3 years ago

next-ntms v0.0.994

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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)
0.0.994

3 years ago

0.0.993

3 years ago

0.0.992

3 years ago

0.0.991

3 years ago

0.0.99

3 years ago

0.0.986

3 years ago

0.0.985

3 years ago

0.0.982

3 years ago

0.0.981

3 years ago

0.0.98

3 years ago

0.0.979

3 years ago

0.0.976

3 years ago

0.0.975

3 years ago

0.0.97

3 years ago

0.0.94

3 years ago

0.0.93

3 years ago

0.0.92

3 years ago

0.0.91

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.61

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.45

3 years ago

0.0.40

3 years ago

0.0.30

3 years ago

0.0.20

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.1

3 years ago

1.0.0

3 years ago