Socket
Book a DemoInstallSign in
Socket

gt-react

Package Overview
Dependencies
Maintainers
4
Versions
481
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gt-react

A React library for automatic internationalization.

10.4.3
latest
Source
npmnpm
Version published
Weekly downloads
2.1K
-20.98%
Maintainers
4
Weekly downloads
 
Created
Source

General Translation

gt-react: Automatic i18n for React

gt-react is a powerful internationalization library designed for React 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-react via npm:

npm install gt-react
npm install gt-react-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. Select languages

<GTProvider> is used to configure the behavior of gt-react. It should be placed as high up in your app as possible, ideally at the root.

Just pass a list of locale codes to add them to your app.

import { GTProvider } from 'gt-react';
import MyApp from './MyApp';

export default function App() {
  return (
    <GTProvider locales={['fr', 'zh']}>
      {' '}
      // French and Chinese support
      <MyApp />
    </GTProvider>
  );
}

3. Add the <T> component

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

import { T } from 'gt-react';

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-react';

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-react-cli setup

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

import { useGT } from 'gt-react';

export default function Example() {
  const t = useGT();
  return <p>{t('This gets translated.')}</p>;
}

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!

Keywords

react

FAQs

Package last updated on 04 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.