
i18n のテキスト伸長:翻訳後の長さによるレイアウト崩れを防止
英語の UI ではぴったり収まっていても、30% 長いドイツ語翻訳や 40% 長いフィンランド語翻訳が届くと、ボタンがはみ出し、表が崩れ、慎重に設計したレイアウトが破綻します。テキスト伸長テストでこれを防げます。
1
テキスト伸長でレイアウトが崩れる理由
開発者は、特にコンパクトな言語の 1 つである英語のテキストを使って UI を設計します。翻訳が届くと、長い言語ではコンテナからはみ出し、グリッドレイアウトが崩れ、ボタンラベルが省略され、コンテンツが画面外へ押し出されます。これらの不具合は特定ロケールでしか発生しないため、英語だけでの開発とテストでは見えません。
The expansion problem
// English is one of the most compact languages.
// Translations are almost always LONGER.
// English (source):
"Save" // 4 chars
// Translations:
"Speichern" // German: 10 chars (+150%)
"Enregistrer" // French: 12 chars (+200%)
"Guardar" // Spanish: 7 chars (+75%)
"Сохранить" // Russian: 9 chars (+125%)
"Tallenna" // Finnish: 8 chars (+100%)
// Buttons, labels, and table headers designed for
// English text WILL break in other languages.テキスト伸長は特殊な事例ではありません。複数言語に対応するすべての UI で発生します。ドイツ語は英語より 30%、フィンランド語は 40% 長く、短い文字列では 100% 以上長くなる言語もあります。翻訳が届く前に伸長をテストすれば、費用のかかる再設計を防げます。
2
言語別のテキスト伸長率
英語の原文に対する平均的な伸長率です。短い文字列(20 文字未満)は、個々の単語選択が全体の長さに大きく影響するため、長い文字列より伸長率が高くなります。
Expansion ratios by language
// Average text expansion relative to English:
// European languages:
// German: +30-35% (compound words)
// Finnish: +30-40% (agglutinative)
// French: +15-25% (articles, prepositions)
// Spanish: +15-25%
// Italian: +15-25%
// Portuguese: +15-25%
// Russian: +20-30% (case endings)
// Polish: +20-30%
// Greek: +20-30%
// Asian languages (CJK):
// Chinese: -30-50% (shorter in characters, but wider per char)
// Japanese: -20-40% (kanji compress meaning)
// Korean: -10-20%
// Right-to-left:
// Arabic: +20-30%
// Hebrew: +10-20%
// Rule of thumb by source string length:
// 1-10 chars: expect +200% expansion
// 11-20 chars: expect +80% expansion
// 21-70 chars: expect +40% expansion
// 71+ chars: expect +30% expansionこれらは平均値です。個々の文字列はさらに長くなる場合があります。英語で 2 語のボタンラベルが、ドイツ語では 4 語になることもあります。ボタン、ナビゲーション、表の見出しなど、重要な UI 要素は高い比率(50% 以上)でテストしてください。
3
i18n-pseudo を使ったテスト
i18n-pseudo の expansion 方法は、翻訳後の長さを再現するよう翻訳元文字列へ埋め草を追加します。対象言語に合わせて伸長率を設定し、実際の翻訳が届く前にレイアウトをテストできます。
Terminal
# Method 1: Pseudo-localization with expansion
npx i18n-pseudo generate \
--source locales/en.json \
--output locales/pseudo-expanded.json \
--expansion 1.4 \
--preset expanded
# Method 2: Longest-translation analysis
npx i18n-validate expansion \
--source locales/en.json \
--targets 'locales/*.json' \
--report expansion-report.json
# Output:
# Key | EN | Longest | Lang | Ratio
# ---------------------|-----|---------|------|-------
# nav.settings | 8 | 14 | de | 175%
# buttons.save | 4 | 12 | fr | 300%
# errors.networkFailed | 14 | 28 | fi | 200%
# Method 3: Visual regression with expanded text
npx playwright test \
--project=expansion-test \
--update-snapshotsVisual regression tests
// playwright.config.ts
export default defineConfig({
projects: [
{
name: 'expansion-test',
use: {
locale: 'pseudo-expanded',
},
},
],
});
// tests/expansion.spec.ts
test('buttons do not overflow with expanded text', async ({ page }) => {
await page.goto('/');
// Check no horizontal overflow
const buttons = await page.locator('button').all();
for (const button of buttons) {
const box = await button.boundingBox();
const parent = await button.locator('..').boundingBox();
expect(box!.x + box!.width).toBeLessThanOrEqual(
parent!.x + parent!.width
);
}
// Visual snapshot comparison
await expect(page).toHaveScreenshot('homepage-expanded.png', {
maxDiffPixels: 100,
});
});ヨーロッパの言語には 40%、最悪の場合を想定するには 50% の伸長でテストします。50% の伸長でも維持できるレイアウトなら、ほぼすべての言語に対応できます。
4
i18n 対応デザインのベストプラクティス
テキスト伸長に対応するレイアウトには、翻訳作業を始める前の設計判断が必要です。次の方法で、伸長に関連する一般的な不具合を防げます。
CSS best practices
/* 1. Use flexible containers, not fixed widths */
/* WRONG */
.button { width: 120px; }
/* RIGHT */
.button { min-width: 80px; padding: 8px 16px; }
/* 2. Allow text wrapping in labels */
/* WRONG */
.label { white-space: nowrap; overflow: hidden; }
/* RIGHT */
.label { overflow-wrap: break-word; }
/* 3. Use CSS Grid/Flexbox for adaptive layouts */
.nav {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
/* 4. Reserve space for the longest expected translation */
/* Use min-width based on ~1.4x English length */
.table-header {
min-width: max-content;
padding-right: 16px;
}
/* 5. Test with the longest language first */
/* German and Finnish are good stress-test languages */
/* 6. For CJK: account for wider characters */
/* CJK characters are typically 2x the width of Latin chars */
/* Even though text is shorter, it may be wider visually */i18n Agent を今すぐ試す
翻訳ファイルをここにドロップ
JSON, YAML, PO, XML, CSV, Markdown, Properties
またはクリックしてファイルを選択
翻訳先言語
登録不要すぐに見積もり