Skip to content

Conversation

@kevalyq
Copy link
Contributor

@kevalyq kevalyq commented Nov 2, 2025

Summary

Implements Accept-Language header detection middleware and adds German translations for password reset emails.

Changes

Middleware Implementation

  • ✅ Created SetLocaleFromHeader middleware to automatically detect and set locale from HTTP Accept-Language header
  • ✅ Registered middleware in API group to apply to all API routes
  • ✅ Support for English (en) and German (de) locales with fallback to configured default
  • ✅ Handles quality values in Accept-Language header (e.g., de-DE,de;q=0.9,en;q=0.8)
  • ✅ Type-safe fallback handling for PHPStan Level Max compliance

Translations

  • ✅ Translated password reset email template to German
  • ✅ Created JSON-based translation file (lang/de.json) with 11 translated strings
  • ✅ Used Laravel's __() helper for all user-facing strings in email template
  • ✅ Parameter replacement support (e.g., :minutes placeholder)

Testing

  • ✅ 7 comprehensive PEST tests for middleware functionality
  • ✅ 5 comprehensive PEST tests for email localization
  • ✅ All 152 tests passing (446 assertions)

Quality Assurance

  • ✅ PHPStan Level Max: No errors
  • ✅ Laravel Pint: Code style compliant
  • ✅ REUSE 3.3: License compliance verified
  • ✅ CHANGELOG updated

Testing

# Run all tests
ddev exec vendor/bin/pest

# Test middleware specifically
ddev exec vendor/bin/pest tests/Feature/LocaleMiddlewareTest.php

# Test translations
ddev exec vendor/bin/pest tests/Feature/PasswordResetEmailLocalizationTest.php

Example Usage

API Request with Accept-Language header

curl -H "Accept-Language: de" https://api.secpal.com/api/health
# Locale will be set to 'de' for this request

Password Reset Email

When a German-speaking user requests password reset:

  • Subject: "Passwort zurücksetzen"
  • Body: "Hallo {name}, Sie haben eine Passwort-Zurücksetzung für Ihr SecPal-Konto angefordert..."

Related Issues

Part of: #83
Fixes: #87

Checklist

  • Code follows project coding standards (Pint, PHPStan Level Max)
  • All tests pass (152 tests, 446 assertions)
  • CHANGELOG.md updated
  • REUSE 3.3 compliant (copyright headers added)
  • Commit messages follow conventional commits
  • PR size < 600 LOC

- Create SetLocaleFromHeader middleware to read Accept-Language header
- Register middleware in api group to apply to all API routes
- Support English (en) and German (de) locales with fallback
- Handle quality values in Accept-Language header
- Create lang/ directory structure for translations
- Add 7 comprehensive PEST tests for middleware functionality
- Translate password reset email template to German
- Create German translation file (lang/de.json) with 11 strings
- Add 5 comprehensive PEST tests for email localization
- Update CHANGELOG.md with middleware and translation features

Part of: #83
Fixes: #87
Copilot AI review requested due to automatic review settings November 2, 2025 21:06
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds internationalization (i18n) support for password reset emails, enabling German translations alongside English. The implementation includes locale detection via HTTP Accept-Language headers and comprehensive test coverage for both translation functionality and middleware behavior.

  • Introduces SetLocaleFromHeader middleware to automatically detect and set application locale based on Accept-Language HTTP headers
  • Adds German translations for all password reset email strings in lang/de.json
  • Updates password reset email template to use Laravel's __() translation helper

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/Http/Middleware/SetLocaleFromHeader.php New middleware to parse Accept-Language header and set application locale with fallback to configured default
bootstrap/app.php Registers SetLocaleFromHeader middleware to API route group
resources/views/emails/password-reset.blade.php Wraps all user-facing strings with __() helper for translation support
lang/de.json German translations for all password reset email strings
lang/de.json.license License header for German translation file
lang/.translation_io Translation.io timestamp metadata
lang/.translation_io.license License header for translation metadata
tests/Feature/PasswordResetEmailLocalizationTest.php 5 tests verifying translation strings exist and work correctly in both English and German
tests/Feature/LocaleMiddlewareTest.php 7 tests validating middleware locale detection, header parsing, and fallback behavior
CHANGELOG.md Documents new i18n features and test additions

- Remove redundant test 'middleware applies to all API routes'
- Update CHANGELOG test count from 7 to 6 for locale middleware
- 11 tests total (6 middleware + 5 translations) all passing
@kevalyq kevalyq merged commit 3684b43 into main Nov 2, 2025
12 checks passed
@kevalyq kevalyq deleted the feat/locale-middleware-implementation branch November 2, 2025 21:16
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PR-2: Implement Accept-Language Middleware & Translate Existing Strings

2 participants