fix(login-i18n): translate the 3 hardcoded JS toasts in customer login
Some checks failed
CI / pytest (push) Has been cancelled
CI / ruff (push) Successful in 17s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled

Three more hardcoded English strings in customers/storefront/login.html
were still bypassing i18n because they were emitted from Alpine
showAlert() calls in <script>:

- "Account created successfully! Please sign in." (post-register toast)
- "Login successful! Redirecting..." (post-login toast)
- "Invalid email or password" (login-error fallback)

Same pattern as the earlier forgot/reset-password sweep: defined
window.__customerLoginI18n with `tojson` server-rendered values, read
them once at function entry as `const i18n = ...`, and swapped each
hardcoded string for an i18n property.

Two new auth.* keys × 4 locales (registration_success_signin,
login_success_redirecting). The third reuses the existing
auth.invalid_credentials.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-29 22:41:15 +02:00
parent bbb481aad4
commit c9fe717184
5 changed files with 21 additions and 3 deletions

View File

@@ -187,6 +187,15 @@
<!-- Alpine.js v3 -->
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.0/dist/cdn.min.js"></script>
{# Translated client-side strings — kept in sync with auth.* keys above #}
<script>
window.__customerLoginI18n = {
registrationSuccess: {{ _('auth.registration_success_signin')|tojson }},
loginSuccess: {{ _('auth.login_success_redirecting')|tojson }},
invalidCredentials: {{ _('auth.invalid_credentials')|tojson }},
};
</script>
<!-- Login Logic -->
<script>
function languageSelector(currentLang, enabledLanguages) {
@@ -206,6 +215,7 @@
}
function customerLogin() {
const i18n = window.__customerLoginI18n || {};
return {
// Data
credentials: {
@@ -234,7 +244,7 @@
checkRegistrationSuccess() {
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('registered') === 'true') {
this.showAlert('Account created successfully! Please sign in.', 'success');
this.showAlert(i18n.registrationSuccess, 'success');
}
},
@@ -293,7 +303,7 @@
localStorage.setItem('customer_token', data.access_token);
localStorage.setItem('customer_user', JSON.stringify(data.user));
this.showAlert('Login successful! Redirecting...', 'success');
this.showAlert(i18n.loginSuccess, 'success');
// Redirect to account page or return URL.
// Accepts `?next=` (apiClient's 401-handler convention)
@@ -306,7 +316,7 @@
} catch (error) {
console.error('Login error:', error);
this.showAlert(error.message || 'Invalid email or password');
this.showAlert(error.message || i18n.invalidCredentials);
} finally {
this.loading = false;
}