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.
Installation
Install globally (recommended):
npm install -g i18nexus-toolsOr run directly with npx:
npx i18n-wrapperBasic 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-runPreviews 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, -pStringSpecifies the glob pattern for files to process.
--pattern "app/**/*.{ts,tsx}"--dry-runFlagsPreviews changes without actually modifying files.
--help, -hFlagsDisplays 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.