
偽在地化:無需真實翻譯即可測試 i18n 就緒情況
真實翻譯需要時間和費用。偽在地化會將來源字串轉換為可讀但明顯虛假的文字,立即暴露 i18n 缺陷:硬編碼字串、文字溢出、RTL 問題和串聯問題。
1
什麼是偽在地化?
偽在地化會將來源字串中的字元替換為外觀相似的重音或擴展字元,新增文字擴展填充,並用方括號包裹字串。結果對開發人員仍然可讀,但與真實文字明顯不同,因此很容易發現未使用翻譯函式包裝的字串。
Pseudo-localization examples
// 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 缺陷最快的方式。產生只需幾秒,無需費用,還能發現在使用真實語言測試前看不到的問題。每個 i18n 就緒專案都應在委託真實翻譯前使用它。
2
在專案中使用
安裝 i18n-pseudo 並對語系檔案執行。該工具會自動偵測檔案格式並產生偽在地化版本,您可將其作為測試語系載入到應用程式中。
Issues caught by pseudo-localization
// 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 text開發期間,在應用程式的語言切換器中新增 'pseudo' 語系。開發人員切換到該設定後,未翻譯字串會立即顯現。發佈到生產環境前請移除偽語系。
3
7 種轉換策略
i18n-pseudo 提供 7 種轉換策略,每種測試 i18n 實現的不同方面。可單獨使用以進行針對性測試,也可透過預設組合使用以全面覆蓋。
Pseudo-localization strategies
// 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 pass4
5 種內建預設
預設將多種策略組合為常用設定。可使用預設快速測試,也可根據特定需求建立自訂組合。
CLI & Configuration
// 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.*"
]
}5
CI/CD 整合
在 CI 中執行偽在地化,自動偵測 i18n 回歸。產生偽在地化檔案、呈現關鍵螢幕並與基準螢幕截圖比較。螢幕截圖中任何未轉換文字都表示回歸,即出現繞過翻譯函式的新硬編碼字串。
.github/workflows/pseudo-check.yml
# .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: pseudo立即試用 i18n Agent
將翻譯檔案拖放到此處
JSON, YAML, PO, XML, CSV, Markdown, Properties
或點擊選擇檔案
目標語言
無需註冊即時估價