
疑似ローカリゼーション:実際の翻訳なしで i18n 対応をテスト
実際の翻訳には時間と費用がかかります。疑似ローカリゼーションは、翻訳元の文字列を「読めるものの明らかに偽物と分かる」テキストへ変換し、ハードコードされた文字列、テキストのはみ出し、RTL、文字列連結などの i18n の問題をすぐに明らかにします。
疑似ローカリゼーションとは
疑似ローカリゼーションは、翻訳元の文字列にある文字を見た目が似たアクセント付き文字や拡張文字へ置き換え、テキスト伸長用の埋め草を追加し、文字列を括弧で囲みます。開発者には読める一方、通常のテキストとは明らかに異なります。翻訳関数を通していない文字列を簡単に見つけられます。
// Pseudo-localization transforms your source strings
// to simulate translation without real translators
// Original:
"Welcome to our application"
// Accented (simulates diacritics):
"[Ẁëľčöṁë ţö öüŕ àṗṗľïčàţïöñ]"
// Expanded (simulates text expansion ~30%):
"[Weeelcooomee tooo ouuur aaappliiicaaatiiioon]"
// Mirrored (simulates RTL layout):
"[noitacilppa ruo ot emocleW]"
// Brackets make untranslated strings immediately visibleプロジェクトでの使用方法
i18n-pseudo をインストールし、ロケールファイルに対して実行します。ファイル形式を自動検出し、アプリでテスト用ロケールとして読み込める疑似ローカライズ版を生成します。
// 1. Hardcoded strings (not wrapped in t())
// Pseudo strings have brackets/accents, so untranslated
// strings are immediately obvious in the UI
// 2. Text truncation
// Expanded text reveals buttons and labels that break
// when translations are longer than English
// 3. Layout issues
// Accented characters reveal font rendering problems
// RTL mode reveals directional layout bugs
// 4. Concatenation bugs
// "Hello " + name vs t('greeting', { name })
// Pseudo-localization breaks concatenated strings
// 5. Missing i18n wrappers
// Any string not going through the i18n system
// appears as plain English among pseudo text7 つの変換方法
i18n-pseudo は、i18n 実装の異なる側面をそれぞれテストする 7 つの変換方法を提供します。特定の問題を調べるには個別に、包括的に確認するにはプリセットで組み合わせて使用します。
// Strategy 1: Accented characters
// Replace ASCII with similar-looking Unicode
// a -> à, e -> ë, o -> ö, etc.
// Preserves readability while testing rendering
// Strategy 2: Text expansion
// Pad strings to simulate longer translations
// German is ~30% longer, Finnish ~40% longer
// Helps catch UI overflow early
// Strategy 3: Brackets/wrappers
// Wrap strings in [brackets] or «guillemets»
// Makes untranslated strings visually obvious
// Strategy 4: Bidi/RTL
// Mirror text for right-to-left testing
// Catches layout issues before Arabic/Hebrew testing
// Strategy 5: Combined
// Apply all strategies simultaneously
// Maximum coverage in one pass5 つの組み込みプリセット
プリセットは、複数の方法を一般的な用途に合わせて組み合わせた設定です。すぐにテストするにはプリセットを使用し、固有の要件には独自の組み合わせを作成します。
// Using i18n-pseudo CLI
npx i18n-pseudo generate \
--source locales/en.json \
--output locales/pseudo.json \
--preset accented
# Available presets:
# accented - Ḣëľľö Ẁöŕľð (default)
# expanded - Heeellooo Wooorld
# mirrored - dlroW olleH
# brackets - [Hello World]
# maximum - [Ḣëëëľľľöööö Ẁöööŕŕŕľľľðððð]
// i18n-pseudo.config.json
{
"source": "locales/en.json",
"output": "locales/pseudo.json",
"preset": "maximum",
"expansion": 1.4,
"wrapper": ["[", "]"],
"exclude": [
"*.url",
"*.email",
"branding.*"
]
}CI/CD との連携
CI で疑似ローカリゼーションを実行し、i18n のリグレッションを自動検出します。疑似ローカライズ済みファイルを生成し、主要画面を描画して基準スクリーンショットと比較します。スクリーンショット内に変換されていないテキストがあれば、翻訳関数を迂回する新しいハードコード文字列によるリグレッションです。
# .github/workflows/pseudo-check.yml
name: Pseudo-Localization Check
on:
pull_request:
paths:
- 'src/**'
jobs:
pseudo-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Generate pseudo locale
run: npx i18n-pseudo generate \
--source locales/en.json \
--output locales/pseudo.json \
--preset maximum
- name: Build with pseudo locale
run: npm run build
env:
NEXT_PUBLIC_LOCALE: pseudo
- name: Run visual regression tests
run: npx playwright test --project=pseudo
env:
LOCALE: pseudoi18n Agent を今すぐ試す
翻訳ファイルをここにドロップ
JSON, YAML, PO, XML, CSV, Markdown, Properties
またはクリックしてファイルを選択
翻訳先言語