General Translation  
Next.js CLI Tool

Scan

Scans your project for translatable content

Usage

npx gt-next-cli scan

Overview

The gt-next-cli scan command scans your project for translatable content. It does this by parsing your project's file tree and using babel to wrap the <T> component around static content. Any dynamic content will be automatically wrapped with <Var> components.

This command is similar to the setup command, but it is more straightforward and only wraps the <T> component around content.

It does not add other components like <GTProvider>. Thus, we recommend running this command occasionally to ensure all the content in your project is translatable.

You should run setup the first time you are integrating General Translation into your project.

src/app/Home.js
import { T, Var } from 'gt-next'; 
 
export default function Home({ user }) {
  return (
    <div>
      <T id="app.home.0">
        Hello, World! My name is <Var>{ user.name }</Var>
      </T>
    </div>
  );
}

Parameters

ParameterDescriptionTypeOptionalDefault
--src <path>The source directory to scanstringtrue./src && ./app && ./pages && ./components
--config <path>The path to the GT config filestringtrue"gt.config.json"
--disable-idsDisable the automatic generation of IDs for <T> componentsflagtruefalse
--disable-formattingDisable auto-formattingflagtruefalse

Behavior

Configuration file

When running the CLI tool for the first time, it will attempt to create a gt.config.json file in the root of your project. This file contains metadata about your project that is used to translate your content.

Read more about the gt.config.json file here.

The id prop

The scan command will automatically generate unique IDs for your <T> components. This is useful for projects that use a lot of <T> components and want to avoid manually having to assign each one a unique ID.

This id is useful for referencing specific translations in the translation editor and in the console.

To disable this behavior, you can use the --disable-ids flag.

<T> injection behavior

Basic case

The CLI will wrap JSX elements at the highest possible level. This means that it will wrap the entire component in a <T> component if it is not already wrapped.

<div>Hello, World!</div> -> <T id="SOME_ID"><div>Hello, World!</div></T>

See the reference for more details on how the <T> component is wrapped.

Auto-formatting

The scan command will automatically format the changes it makes to your codebase with Prettier, Biome, or ESLint depending on your project's configuration.

To disable this behavior, you can use the --disable-formatting flag.

On this page