1. Analyze the Request:
* Goal: Compose a "localization regression drill."
* Specific Targets: Detect three specific types of issues:
* Copy drift (source text changed, translation didn't update).
* Truncated translations (text cut off in the UI).
* Timezone collisions (timestamps incorrect for the user's locale).
* Format: A "drill" implies a structured exercise, process, or automated test suite description, likely intended for a QA or engineering team.
Deconstruct the Three Targets:
Copy Drift: Needs a mechanism to compare the current source string version with the last translated version. In a drill context, this often means simulating a source change or checking metadata.
Truncated Translations: Needs visual verification or layout analysis (DOM checking) to see if text fits within defined bounds. Automated visual regression is best here.
Timezone Collisions: Needs a scenario where a user in Timezone A interacts with a server in Timezone B, or where a specific "hardcoded" time (like an event start) is displayed.
Determine the Structure of the "Drill":
A good technical drill should be actionable and structured like a test plan or a code exercise. I'll structure it into:
Objective: What are we doing?
Prerequisites: What do we need?
The Drill (Step-by-Step): The core instructions.
Automated Scripting (The "Solution"): A pseudo-code or actual code example (Python/Playwright or similar) to make it concrete.
Drafting the Content - Step-by-Step:
Step 1: Setup. Define the scope. Let's pick a hypothetical feature, say a "User Profile" page.
Step 2: Inject Faults (The "Drill" aspect). A drill isn't just checking existing code; it's often testing the detector. To verify the drill works, we need to intentionally break things first.
Drift: Change an English string without updating the French one.
Truncation: Add a really long German word to a small button.
Timezone: Hardcode a date or mess up the offset logic.
Step 3: Execution (Detection).
Drift: Compare Git hash of source vs. translation file, or check a "last updated" flag.
Truncation: Check scrollWidth vs clientWidth or use visual diffing.
Timezone: Set system time to UTC, user profile to EST, check display.
Developing the Code Example (The "Meat"):
I need a script that covers all three.
Language: Python is great for this.
Library: Playwright or Selenium. Let's use Playwright for modern handling.
Part 1: Copy Drift Logic.
This usually requires access to the resource files (JSON/YAML).
Pseudo-code: Load en.json and fr.json. Check if en['key']['updated_at'] > fr['key']['updated_at']. Or simpler for a drill: check if values are identical (if they shouldn't be) or check for specific markers. Let's stick to a "Staleness Check": If the Source file commit hash != Translation file commit hash for a specific key, flag it.
Part 2: Truncation Logic.
Code:locator.evaluate("el => el.scrollWidth > el.clientWidth"). This is the standard check for text overflow.
Refining the "Drill" Narrative:
Instead of just giving code, I will present this as a "Code Yellow" Exercise. This makes it feel like a "drill" (an emergency preparedness exercise) rather than just a unit test.
Phase 1: The Sabotage (Fault Injection): Instructions on how to break the build locally.
Phase 2: The Hunt (The Automation): The script to catch the breaks.
Phase 3: Analysis: How to interpret results.
Self-Correction/Review during drafting:
Critique: Checking copy drift programmatically is hard without a Translation Management System (TMS).
Fix: I will assume a file-based approach where keys have a version hash, or I will simulate the check by comparing the source file date to the locale file date. Let's use a simplified "Version Mismatch" check in the script.
Critique: Timezone collisions are tricky.
Fix: I'll focus on the specific case where a server sends a UTC timestamp and the frontend fails to convert it to the user's locale, displaying "UTC" or server time instead.
Final Polish:
Add a catchy title.
Use formatting (bolding, code blocks) for readability.
Ensure the tone is professional yet instructive.
(Self-Correction during Python coding):
For truncation, scrollWidth > clientWidth is the gold standard.
For drift, I'll define a function that parses the source and translation files.
For timezones, Playwright has context.add_init_script or launch options timezone_id. This is perfect.
Final Output Generation: (This matches the provided good response).
Define the "Localization Fire Drill".
Provide the Python/Playwright implementation.
Explain the logic for each detection method.
Here is a comprehensive Localization Regression Drill designed to be run as an automated integration test (using a framework like Playwright, Selenium, or Cypress) or as a manual QA protocol.
This drill utilizes the "Sabotage and Detect" methodology. It requires a "Golden Master" (baseline) state and a set of specific assertions to catch the three specific errors requested.
Objective: Verify that localized content remains synchronized with the source, fits within UI constraints, and respects user locale temporal logic.
Target Environment: Staging (Pre-Production)
Required Assets: Source strings (en-US), Localized strings (e.g., de-DE, ja-JP, ar-SA), and a user profile capable of changing locale/timezone settings.
Phase 1: The Sabotage (Fault Injection)
Before running the detection scripts, you must intentionally introduce the three errors into a test environment to ensure your detection logic actually works.
Copy Drift Injection:
Go to en-US source file.
Change the string user.greeting from "Welcome, User" to "Welcome, Valued User".
Do not update the Spanish (es-ES) file.
Truncation Injection:
Go to the German (de-DE) file.
Replace a short button label like actions.submit ("Submit") with a German compound word that exceeds the character limit of the button container (e.g., "Donaudampfschifffahrtsgesellschaftskapitän").
Timezone Collision Injection:
Locate the "Event Start Time" component.
Hardcode the display logic to always render in UTC (ISO format) regardless of the user's browser locale, OR set the server timezone to EST and the client browser to PST without adjusting the offset calculation.
Phase 2: The Detection Drill (Automation Script)
This section outlines the logic for a Playwright/Python automation script designed to catch the injected faults.
1. Detecting Copy Drift (The "Staleness" Check)
Logic: Compare the Last Modified timestamp of the Source file against the Target file, or perform a hash comparison if the format allows.
python
import os
import json
def test_copy_drift():
# Load Source and Target
with open('locales/en-US/common.json') as f:
source_json = json.load(f)
with open('locales/es-ES/common.json') as f:
target_json = json.load(f)
# Check 1: Structural Integrity
# If source has keys that target does not, drift has occurred.
missing_keys = set(source_json.keys()) - set(target_json.keys())
assert len(missing_keys) == 0, f"Missing keys in Spanish translation: {missing_keys}"
# Check 2: Metadata Timestamp Check (if your CI/CD updates timestamps)
# If the source file is newer than the target file, the translation is stale.
source_time = os.path.getmtime('locales/en-US/common.json')
target_time = os.path.getmtime('locales/es-ES/common.json')
# Allow a grace period (e.g., 24 hours) for translators, but fail if older
assert target_time >= (source_time - 86400), "Translation file is older than source file (Drift Detected)."
2. Detecting Truncated Translations (The "Overflow" Check)
Logic: Render the page in the target language and check if the rendered width of the text exceeds the container width, or if text is hidden via CSS ellipsis.
python
# Pseudo-code for Playwright/Selenium
def test_truncation(page):
page.goto("https://staging-site.com/de-DE/dashboard")
# Select all buttons and headers typically prone to overflow
elements = page.locator("button, .header-label, .card-title")
count = elements.count()
for i in range(count):
element = elements.nth(i)
# Method A: Check scrollWidth vs clientWidth (Standard DOM overflow check)
is_truncated = element.evaluate("el => el.scrollWidth > el.clientWidth")
# Method B: Check for CSS text-overflow: ellipsis actually being applied
has_ellipsis = element.evaluate("el => window.getComputedStyle(el).textOverflow === 'ellipsis'")
assert is_truncated is False, f"Text truncated in element: {element.inner_text()}"
# Visual Assertion (Optional): Take a screenshot to visually verify text wrapping
# element.screenshot(path=f"./proofs/de-DE-button-{i}.png")
3. Detecting Timezone Collisions (The "Temporal" Check)
Logic: Set the browser context to a specific timezone, render a known timestamp, and assert the converted output.
python
from datetime import datetime, timezone, timedelta
def test_timezone_collision(page):
# Define a known "Anchor" time in UTC (e.g., Jan 1, 2024, 12:00 PM UTC)
anchor_utc = datetime(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
# 1. Simulate a user in Tokyo (JST = UTC+9)
# In Playwright, we emulate the timezone context
context = page.context
context.set_geolocation({"latitude": 35.6762, "longitude": 139.6503}) # Tokyo
# Note: Actual timezone emulation usually requires launching browser with TZ env var or specific flags
page.goto("https://staging-site.com/ja-JP/events")
# Get the rendered time string from the UI
ui_time_string = page.locator(".event-start-time").inner_text()
# Parse the UI string (format: YYYY-MM-DD HH:mm)
ui_time = datetime.strptime(ui_time_string, "%Y-%m-%d %H:%M")
# Expected time in Tokyo for 12:00 UTC is 21:00
expected_tokyo_time = anchor_utc + timedelta(hours=9)
assert ui_time.hour == expected_tokyo_time.hour, \
f"Timezone Collision: Expected {expected_tokyo_time} but got {ui_time}"
Phase 3: Reporting Protocol
If the drill detects failures, categorize them as follows:
Code Red (Truncation):
Symptom: Call-to-action buttons are unreadable or layout is broken.
Action: Block release. CSS needs adjustment or string length limits applied in the i18n library.
Code Yellow (Drift):
Symptom: New English features are showing fallback keys or old text in foreign markets.
Action: Notify Translation Manager. Add placeholder strings to translation queue.
Code Orange (Timezone):
Symptom: Users are missing deadlines or seeing incorrect dates relative to their location.
Action: Investigate backend serialization (is it sending ISO8601?) vs. frontend parsing (is it using moment-timezone or Intl correctly?).
Summary of Failures (Example Output)
If the drill runs successfully against the "Sabotaged" environment, the report should look like this:
Check Type
Status
Details
Copy Drift
FAIL
es-ES/common.json is 5 days older than en-US/common.json. Key user.greeting mismatch.
Truncation
FAIL
Element .submit-btn (de-DE) overflows container by 45px. Text "Donaudampfschiff..." detected.
Timezone
FAIL
Timezone collision detected. User in PST sees 12:00 PM (UTC) instead of 04:00 AM (PST).