gt-next
TypeScript icon, indicating that this package has built-in type declarations

5.2.23 • Public • Published

General Translation

gt-next: Automatic i18n for Next.js

gt-next is a powerful internationalization library designed for Next.js applications. It replaces your existing localization library, and integrates with generaltranslation.com for translations.

See our docs for more information including guides, examples, and API references.

Installation

Install gt-next via npm:

npm install gt-next
npm install gt-next-cli --save-dev

Getting Started

Step 1: Configure Your Environment Variables

Add the following environment variables to your .env file:

GT_API_KEY="your-api-key"
GT_PROJECT_ID="your-project-id"

2. Add the withGTConfig() plugin

Add withGTConfig() to your next.config.js file. You can specify the languages you want to support by passing an array of locale codes.

import { withGTConfig } from 'gt-next/config';

const nextConfig = {};

export default withGTConfig(nextConfig, {
  locales: ['pt', 'es'], // Support for Portuguese and Spanish
});

3. Add the <T> component

Wrap any nested JSX content in the <T> component to make it translatable. For more information, check out this guide on using <T> components.

import { T } from "gt-next";

export default function Example() {
  return (
    <T>
      <p>
        This gets translated.
      </p>
    </T>
  );
}

Use the <Var> component to designate JSX content that should not be translated.

import { T, Var } from "gt-next";

export default function Example() {
  return (
    <T>
      <p>
        This gets translated. <Var>This does not.</Var>
      </p>
    </T>
  );
}

Tip: To save time, run the setup command. It will scan your codebase for translatable JSX and insert the <T> tags for you.

npx gt-next-cli setup

Strings: For strings, you can use useGT() or getGT() for translation. For more information, check out this guide.

Documentation

Full documentation, including guides, examples, and API references, can be found at General Translation Docs.

Contributing

We welcome any contributions to our libraries. Please submit a pull request!

Package Sidebar

Install

npm i gt-next

Weekly Downloads

598

Version

5.2.23

License

FSL-1.1-ALv2

Unpacked Size

396 kB

Total Files

178

Last publish

Collaborators

  • archiemckenzie
  • ernest-general-translation
  • brian_lou