Home/i18nexus-tools/i18n-wrapper
๐Ÿ”ง

i18n-wrapper

Automatically wrap Korean text with t() and add imports

Overview

i18n-wrapperis a CLI tool that automatically detects hardcoded Korean text in your code, wraps it with the t() function, and adds necessary import statements.

โœ“Auto-detect Korean text within JSX elements
โœ“Supports string literals and template literals
โœ“Automatically skip already wrapped text
โœ“Automatically add useTranslation import
โœ“Preserve code formatting

Installation

Install globally (recommended):

npm install -g i18nexus-tools

Or run directly with npx:

npx i18n-wrapper

Basic Usage

Process the entire app directory

npx i18n-wrapper --pattern "app/**/*.tsx"

Wraps Korean text in all .tsx files within the 'app' directory.

Preview Mode

npx i18n-wrapper --dry-run

Previews what changes will be made without modifying files.

Process specific files only

npx i18n-wrapper --pattern "app/page.tsx"

Processes only a single file.

Conversion Example

๐Ÿ“

Before

export default function Welcome() {
  return (
    <div>
      <h1>ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค</h1>
      <p>i18nexus ์‚ฌ์šฉ๋ฒ•</p>
      <button>์‹œ์ž‘ํ•˜๊ธฐ</button>
    </div>
  );
}
โœจ

After

import { useTranslation } from "i18nexus";

export default function Welcome() {
  const { t } = useTranslation();
  return (
    <div>
      <h1>{t("ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค")}</h1>
      <p>{t("i18nexus ์‚ฌ์šฉ๋ฒ•")}</p>
      <button>{t("์‹œ์ž‘ํ•˜๊ธฐ")}</button>
    </div>
  );
}

Complex Example

Before:

const title = "์ œ๋ชฉ";
const msg = \`์•ˆ๋…•ํ•˜์„ธ์š” \${name}๋‹˜\`;

return (
  <div title="ํˆดํŒ ํ…์ŠคํŠธ">
    <p>{"๋ฌธ์ž์—ด"}</p>
  </div>
);

After:

const { t } = useTranslation();
const title = t("์ œ๋ชฉ");
const msg = t(\`์•ˆ๋…•ํ•˜์„ธ์š” \${name}๋‹˜\`);

return (
  <div title={t("ํˆดํŒ ํ…์ŠคํŠธ")}>
    <p>{t("๋ฌธ์ž์—ด")}</p>
  </div>
);

Command Options

--pattern, -pString

Specifies the glob pattern for files to process.

--pattern "app/**/*.{ts,tsx}"
--dry-runFlags

Previews changes without actually modifying files.

--help, -hFlags

Displays the help message.

Smart Detection

Cases that are automatically processed:

  • โœ“
    JSX Text Node
    <div>Korean text</div> โ†’ <div>{t("Korean text")}</div>
  • โœ“
    JSX Attribute Value
    <div title="Title"> โ†’ <div title={t("Title")}>
  • โœ“
    String Literal
    const text = "์•ˆ๋…•"; โ†’ const text = t("์•ˆ๋…•");
  • โœ“
    Template Literal
    const msg = \`์•ˆ๋…• \${name}\`; โ†’ const msg = t(\`์•ˆ๋…• \${name}\`);

Cases that are automatically skipped:

  • โŠ—Text already wrapped with t()
  • โŠ—Text containing only English
  • โŠ—Text containing only numbers or special characters
  • โŠ—Text inside comments

Best Practices

โœ…Check with dry-run first

Check changes with the --dry-run option before actually modifying files.

npx i18n-wrapper --dry-run

โœ…Use a version control system

Use version control like Git to be prepared to revert changes.

โœ…Start with a small scope

Start with a single file or small directory first to check the results.

โš ๏ธManual review needed

After automatic conversion, always review the changed files to ensure there are no unintended changes.

Next Steps