Find and fix hardcoded strings using i18next-cli with a self-verification loop
Automates i18next translation workflow to find and fix hardcoded strings with verification
/plugin marketplace add basaltbytes/agentic-tools/plugin install i18next-translate@basaltbytes-pluginsYou are running a translation workflow to find and fix hardcoded strings using i18next-cli.
$ARGUMENTS - Optional path to app directory (for monorepos), e.g., apps/mobileFirst, determine where to run commands:
# If path provided, cd into it
# Otherwise, check current directory for config
find . -maxdepth 3 -name "i18next.config.ts" -o -name "i18next.config.js" -o -name "i18next.config.mjs" 2>/dev/null | head -10
Determine project type:
apps/* or packages/* → cd into that directoryIf no config found, ask user if they want to create one with npx i18next-cli init.
# Check lockfiles to determine package manager
if [ -f "pnpm-lock.yaml" ]; then
echo "pnpm"
elif [ -f "yarn.lock" ]; then
echo "yarn"
else
echo "npm"
fi
Use the appropriate runner:
pnpm dlx i18next-cli or pnpm i18next-cli if installedyarn dlx i18next-clinpx i18next-cliGet baseline translation status:
<package-runner> i18next-cli status
Report to user:
Enter the fix-and-verify loop:
<package-runner> i18next-cli lint
Parse the output to identify:
For each hardcoded string found, apply the appropriate fix:
Plain text in JSX:
// ❌ Before
<Text>Welcome back!</Text>
// ✅ After
<Text>{t('welcome_back')}</Text>
Text with interpolation:
// ❌ Before
<Text>Hello {userName}!</Text>
// ✅ After
<Text>{t('hello_user', { name: userName })}</Text>
Rich text with nested elements (use Trans component):
// ❌ Before
<Text>Read our <Link>terms</Link></Text>
// ✅ After
import { Trans } from 'react-i18next';
<Trans i18nKey="read_terms">
Read our <Link>terms</Link>
</Trans>
Attributes:
// ❌ Before
<Input placeholder="Enter email" />
// ✅ After
<Input placeholder={t('placeholder_email')} />
Ensure t() is available in the file:
// For React components - add if missing
import { useTranslation } from 'react-i18next';
function MyComponent() {
const { t } = useTranslation();
// or with namespace: useTranslation('common')
}
<package-runner> i18next-cli status
Compare with previous run. If issues remain, continue the loop.
Sync translation files with new keys:
<package-runner> i18next-cli extract
This updates JSON files with any new keys.
<package-runner> i18next-cli status
Summarize to user:
| Command | Purpose |
|---|---|
i18next-cli status | Translation progress overview |
i18next-cli status de | Detailed report for German locale |
i18next-cli lint | Find hardcoded strings |
i18next-cli extract | Extract keys to JSON |
i18next-cli init | Create config interactively |