Testing Internationalisation and Locales

๐Ÿ“‹ Table of Contents โ–พ
  1. Testing Localised UI and Formatting
  2. Common Mistakes

Internationalised applications must handle different languages, locales and formatting rules. Playwright can help you verify that translations appear correctly and that locale-specific formatting behaves as expected.

Testing Localised UI and Formatting

You can pass locale or language settings via URLs, cookies, headers or configuration and then assert on translated text and formatting.

// i18n-locales.spec.ts
import { test, expect } from '@playwright/test';

test('shows translated text for German locale', async ({ page }) => {
  await page.goto('https://demo.myshop.com/de-DE');

  await expect(page.getByText('Warenkorb')).toBeVisible();
});
Note: Tests should focus on whether appropriate translations and formats are used, not on validating full language correctness.
Tip: Reuse the same flows across locales by parameterising tests with language or region data.
Warning: Hard-coding English-only selectors (like button text) can break when testing other languages; prefer roles and data attributes where possible.

Internationalisation tests are particularly important for pricing, dates, number formatting and legal content, where mistakes may have serious consequences.

Common Mistakes

Mistake 1 โ€” Using English-only selectors for localised tests

This is brittle.

โŒ Wrong: Selecting elements by English text when you expect translations.

โœ… Correct: Use roles, test IDs or language-agnostic attributes.

Mistake 2 โ€” Testing only one locale

This misses regional differences.

โŒ Wrong: Assuming that if it works in en-US, it works everywhere.

โœ… Correct: Identify key locales based on user base and test those explicitly.

🧠 Test Yourself

What is a good practice for i18n testing with Playwright?