feat(loyalty): add full i18n support for all loyalty module pages
Replace hardcoded English strings across all 22 templates, 10 JS files, and 4 locale files (en/fr/de/lb) with ~300 translation keys per language. Uses server-side _() for Jinja2 templates and I18n.t() for JS toast messages and dynamic Alpine.js expressions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -190,12 +190,12 @@ function adminLoyaltyMerchantDetail() {
|
||||
};
|
||||
const response = await apiClient.post(`/admin/loyalty/merchants/${this.merchantId}/program`, data);
|
||||
this.program = response;
|
||||
Utils.showToast('Loyalty program created', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.program_created'), 'success');
|
||||
loyaltyMerchantDetailLog.info('Program created for merchant', this.merchantId);
|
||||
// Reload stats
|
||||
await this.loadStats();
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to create program: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.create_failed', {message: error.message}), 'error');
|
||||
loyaltyMerchantDetailLog.error('Failed to create program:', error);
|
||||
}
|
||||
},
|
||||
@@ -207,10 +207,10 @@ function adminLoyaltyMerchantDetail() {
|
||||
try {
|
||||
const response = await apiClient.post(`/admin/loyalty/programs/${this.program.id}/${action}`);
|
||||
this.program.is_active = response.is_active;
|
||||
Utils.showToast(`Program ${action}d successfully`, 'success');
|
||||
Utils.showToast(I18n.t(`loyalty.toasts.program_${action}d`), 'success');
|
||||
loyaltyMerchantDetailLog.info(`Program ${action}d`);
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to ${action} program: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t(`loyalty.toasts.${action}_failed`, {message: error.message}), 'error');
|
||||
loyaltyMerchantDetailLog.error(`Failed to ${action} program:`, error);
|
||||
}
|
||||
},
|
||||
@@ -227,12 +227,12 @@ function adminLoyaltyMerchantDetail() {
|
||||
await apiClient.delete(`/admin/loyalty/programs/${this.program.id}`);
|
||||
this.program = null;
|
||||
this.showDeleteModal = false;
|
||||
Utils.showToast('Loyalty program deleted', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.program_deleted'), 'success');
|
||||
loyaltyMerchantDetailLog.info('Program deleted');
|
||||
// Reload stats
|
||||
await this.loadStats();
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to delete program: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.delete_failed', {message: error.message}), 'error');
|
||||
loyaltyMerchantDetailLog.error('Failed to delete program:', error);
|
||||
this.showDeleteModal = false;
|
||||
}
|
||||
|
||||
@@ -150,14 +150,14 @@ function adminLoyaltyMerchantSettings() {
|
||||
|
||||
if (response) {
|
||||
loyaltyMerchantSettingsLog.info('Settings saved successfully');
|
||||
Utils.showToast('Settings saved successfully', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.settings_saved'), 'success');
|
||||
|
||||
// Navigate back to merchant detail
|
||||
window.location.href = this.backUrl;
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyMerchantSettingsLog.error('Failed to save settings:', error);
|
||||
Utils.showToast(`Failed to save settings: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.settings_save_failed', {message: error.message}), 'error');
|
||||
} finally {
|
||||
this.saving = false;
|
||||
}
|
||||
|
||||
@@ -109,19 +109,19 @@ function adminLoyaltyProgramEdit() {
|
||||
);
|
||||
this.programId = response.id;
|
||||
this.isNewProgram = false;
|
||||
Utils.showToast('Program created successfully', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.program_created'), 'success');
|
||||
} else {
|
||||
await apiClient.patch(
|
||||
`/admin/loyalty/programs/${this.programId}`,
|
||||
payload
|
||||
);
|
||||
Utils.showToast('Program updated successfully', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.program_updated'), 'success');
|
||||
}
|
||||
|
||||
loyaltyProgramEditLog.info('Program saved');
|
||||
window.location.href = this.backUrl;
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to save: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.save_failed', {message: error.message}), 'error');
|
||||
loyaltyProgramEditLog.error('Save failed:', error);
|
||||
} finally {
|
||||
this.saving = false;
|
||||
@@ -134,11 +134,11 @@ function adminLoyaltyProgramEdit() {
|
||||
|
||||
try {
|
||||
await apiClient.delete(`/admin/loyalty/programs/${this.programId}`);
|
||||
Utils.showToast('Program deleted', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.program_deleted'), 'success');
|
||||
loyaltyProgramEditLog.info('Program deleted');
|
||||
window.location.href = this.backUrl;
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to delete: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.delete_failed', {message: error.message}), 'error');
|
||||
loyaltyProgramEditLog.error('Delete failed:', error);
|
||||
} finally {
|
||||
this.deleting = false;
|
||||
|
||||
@@ -249,10 +249,10 @@ function adminLoyaltyPrograms() {
|
||||
try {
|
||||
const response = await apiClient.post(`/admin/loyalty/programs/${program.id}/${action}`);
|
||||
program.is_active = response.is_active;
|
||||
Utils.showToast(`Program ${action}d successfully`, 'success');
|
||||
Utils.showToast(I18n.t(`loyalty.toasts.program_${action}d`), 'success');
|
||||
loyaltyProgramsLog.info(`Program ${program.id} ${action}d`);
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to ${action} program: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t(`loyalty.toasts.${action}_failed`, {message: error.message}), 'error');
|
||||
loyaltyProgramsLog.error(`Failed to ${action} program:`, error);
|
||||
}
|
||||
},
|
||||
@@ -267,13 +267,13 @@ function adminLoyaltyPrograms() {
|
||||
if (!this.deletingProgram) return;
|
||||
try {
|
||||
await apiClient.delete(`/admin/loyalty/programs/${this.deletingProgram.id}`);
|
||||
Utils.showToast('Program deleted successfully', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.program_deleted'), 'success');
|
||||
loyaltyProgramsLog.info('Program deleted:', this.deletingProgram.id);
|
||||
this.showDeleteModal = false;
|
||||
this.deletingProgram = null;
|
||||
await Promise.all([this.loadPrograms(), this.loadStats()]);
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to delete program: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.delete_failed', {message: error.message}), 'error');
|
||||
loyaltyProgramsLog.error('Failed to delete program:', error);
|
||||
this.showDeleteModal = false;
|
||||
this.deletingProgram = null;
|
||||
|
||||
@@ -61,10 +61,10 @@ function merchantLoyaltySettings() {
|
||||
await apiClient.patch('/merchants/loyalty/program', payload);
|
||||
}
|
||||
|
||||
Utils.showToast('Settings saved successfully', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.settings_saved'), 'success');
|
||||
loyaltySettingsLog.info('Settings saved');
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to save: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.save_failed', {message: error.message}), 'error');
|
||||
loyaltySettingsLog.error('Save failed:', error);
|
||||
} finally {
|
||||
this.saving = false;
|
||||
@@ -76,11 +76,11 @@ function merchantLoyaltySettings() {
|
||||
|
||||
try {
|
||||
await apiClient.delete('/merchants/loyalty/program');
|
||||
Utils.showToast('Loyalty program deleted', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.program_deleted'), 'success');
|
||||
loyaltySettingsLog.info('Program deleted');
|
||||
window.location.href = '/merchants/loyalty/program';
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to delete: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.toasts.delete_failed', {message: error.message}), 'error');
|
||||
loyaltySettingsLog.error('Delete failed:', error);
|
||||
} finally {
|
||||
this.deleting = false;
|
||||
|
||||
@@ -99,7 +99,7 @@ function createProgramFormMixin() {
|
||||
if (!payload.card_name) payload.card_name = null;
|
||||
if (!payload.card_secondary_color) payload.card_secondary_color = null;
|
||||
if (!payload.logo_url) {
|
||||
this.error = 'Logo URL is required for wallet integration.';
|
||||
this.error = I18n.t('loyalty.toasts.logo_required');
|
||||
return null;
|
||||
}
|
||||
if (!payload.hero_image_url) payload.hero_image_url = null;
|
||||
|
||||
@@ -80,7 +80,7 @@ function storeLoyaltyEnroll() {
|
||||
loyaltyEnrollLog.info('Customer enrolled successfully:', response.card_number);
|
||||
}
|
||||
} catch (error) {
|
||||
Utils.showToast(`Enrollment failed: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.store.enroll.enrollment_failed', {message: error.message}), 'error');
|
||||
loyaltyEnrollLog.error('Enrollment failed:', error);
|
||||
} finally {
|
||||
this.enrolling = false;
|
||||
|
||||
@@ -87,10 +87,10 @@ function loyaltySettings() {
|
||||
let response;
|
||||
if (this.isNewProgram) {
|
||||
response = await apiClient.post('/store/loyalty/program', payload);
|
||||
Utils.showToast('Program created successfully', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.store.settings.program_created'), 'success');
|
||||
} else {
|
||||
response = await apiClient.put('/store/loyalty/program', payload);
|
||||
Utils.showToast('Program updated successfully', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.store.settings.program_updated'), 'success');
|
||||
}
|
||||
|
||||
this.populateSettings(response);
|
||||
@@ -98,7 +98,7 @@ function loyaltySettings() {
|
||||
|
||||
loyaltySettingsLog.info('Program saved:', response.display_name);
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to save: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.store.settings.save_failed', {message: error.message}), 'error');
|
||||
loyaltySettingsLog.error('Save failed:', error);
|
||||
} finally {
|
||||
this.saving = false;
|
||||
@@ -110,13 +110,13 @@ function loyaltySettings() {
|
||||
|
||||
try {
|
||||
await apiClient.delete('/store/loyalty/program');
|
||||
Utils.showToast('Loyalty program deleted', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.store.settings.program_deleted'), 'success');
|
||||
loyaltySettingsLog.info('Program deleted');
|
||||
// Redirect to terminal page
|
||||
const storeCode = window.location.pathname.split('/')[2];
|
||||
window.location.href = `/store/${storeCode}/loyalty/program`;
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to delete: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.store.settings.delete_failed', {message: error.message}), 'error');
|
||||
loyaltySettingsLog.error('Delete failed:', error);
|
||||
} finally {
|
||||
this.deleting = false;
|
||||
|
||||
@@ -136,9 +136,9 @@ function storeLoyaltyTerminal() {
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
Utils.showToast('Customer not found. You can enroll them as a new member.', 'warning');
|
||||
Utils.showToast(I18n.t('loyalty.store.terminal.customer_not_found'), 'warning');
|
||||
} else {
|
||||
Utils.showToast(`Error looking up customer: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.store.terminal.error_lookup', {message: error.message}), 'error');
|
||||
}
|
||||
loyaltyTerminalLog.error('Lookup failed:', error);
|
||||
} finally {
|
||||
@@ -213,7 +213,7 @@ function storeLoyaltyTerminal() {
|
||||
await this.loadRecentTransactions();
|
||||
|
||||
} catch (error) {
|
||||
Utils.showToast(`Transaction failed: ${error.message}`, 'error');
|
||||
Utils.showToast(I18n.t('loyalty.store.terminal.transaction_failed', {message: error.message}), 'error');
|
||||
loyaltyTerminalLog.error('Transaction failed:', error);
|
||||
} finally {
|
||||
this.processing = false;
|
||||
@@ -229,7 +229,7 @@ function storeLoyaltyTerminal() {
|
||||
staff_pin: this.pinDigits
|
||||
});
|
||||
|
||||
Utils.showToast('Stamp added!', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.store.terminal.stamp_added'), 'success');
|
||||
},
|
||||
|
||||
// Redeem stamps
|
||||
@@ -241,7 +241,7 @@ function storeLoyaltyTerminal() {
|
||||
staff_pin: this.pinDigits
|
||||
});
|
||||
|
||||
Utils.showToast('Stamps redeemed! Reward earned.', 'success');
|
||||
Utils.showToast(I18n.t('loyalty.store.terminal.stamps_redeemed'), 'success');
|
||||
},
|
||||
|
||||
// Earn points
|
||||
@@ -255,7 +255,7 @@ function storeLoyaltyTerminal() {
|
||||
});
|
||||
|
||||
const pointsEarned = response.points_earned || Math.floor(this.earnAmount * (this.program?.points_per_euro || 1));
|
||||
Utils.showToast(`${pointsEarned} points awarded!`, 'success');
|
||||
Utils.showToast(I18n.t('loyalty.store.terminal.x_points_awarded', {points: pointsEarned}), 'success');
|
||||
|
||||
this.earnAmount = null;
|
||||
},
|
||||
@@ -273,7 +273,7 @@ function storeLoyaltyTerminal() {
|
||||
staff_pin: this.pinDigits
|
||||
});
|
||||
|
||||
Utils.showToast(`Reward redeemed: ${reward.name}`, 'success');
|
||||
Utils.showToast(I18n.t('loyalty.store.terminal.reward_redeemed', {name: reward.name}), 'success');
|
||||
|
||||
this.selectedReward = '';
|
||||
},
|
||||
@@ -292,21 +292,11 @@ function storeLoyaltyTerminal() {
|
||||
|
||||
// Format number
|
||||
getTransactionLabel(tx) {
|
||||
const labels = {
|
||||
'card_created': 'Enrolled',
|
||||
'welcome_bonus': 'Welcome Bonus',
|
||||
'stamp_earned': 'Stamp Earned',
|
||||
'stamp_redeemed': 'Stamp Redeemed',
|
||||
'stamp_voided': 'Stamp Voided',
|
||||
'stamp_adjustment': 'Stamp Adjusted',
|
||||
'points_earned': 'Points Earned',
|
||||
'points_redeemed': 'Points Redeemed',
|
||||
'points_voided': 'Points Voided',
|
||||
'points_adjustment': 'Points Adjusted',
|
||||
'points_expired': 'Points Expired',
|
||||
'card_deactivated': 'Deactivated',
|
||||
};
|
||||
return labels[tx.transaction_type] || tx.transaction_type?.replace(/_/g, ' ') || 'Unknown';
|
||||
const type = tx.transaction_type;
|
||||
if (type) {
|
||||
return I18n.t('loyalty.transactions.' + type, {defaultValue: type.replace(/_/g, ' ')});
|
||||
}
|
||||
return I18n.t('loyalty.common.unknown');
|
||||
},
|
||||
|
||||
getTransactionColor(tx) {
|
||||
|
||||
@@ -46,7 +46,7 @@ function customerLoyaltyEnroll() {
|
||||
this.program = null;
|
||||
} else {
|
||||
console.error('Failed to load program:', error);
|
||||
this.error = 'Failed to load program information';
|
||||
this.error = I18n.t('loyalty.enrollment.errors.load_failed');
|
||||
}
|
||||
} finally {
|
||||
this.loading = false;
|
||||
@@ -89,9 +89,9 @@ function customerLoyaltyEnroll() {
|
||||
} catch (error) {
|
||||
console.error('Enrollment failed:', error);
|
||||
if (error.message?.includes('already')) {
|
||||
this.error = 'This email is already registered in our loyalty program.';
|
||||
this.error = I18n.t('loyalty.enrollment.errors.email_exists');
|
||||
} else {
|
||||
this.error = error.message || 'Enrollment failed. Please try again.';
|
||||
this.error = error.message || I18n.t('loyalty.enrollment.errors.failed');
|
||||
}
|
||||
} finally {
|
||||
this.enrolling = false;
|
||||
|
||||
@@ -84,16 +84,10 @@ function customerLoyaltyHistory() {
|
||||
|
||||
getTransactionLabel(tx) {
|
||||
const type = tx.transaction_type || '';
|
||||
const labels = {
|
||||
'points_earned': 'Points Earned',
|
||||
'points_redeemed': 'Reward Redeemed',
|
||||
'points_voided': 'Points Voided',
|
||||
'welcome_bonus': 'Welcome Bonus',
|
||||
'points_expired': 'Points Expired',
|
||||
'stamp_earned': 'Stamp Earned',
|
||||
'stamp_redeemed': 'Stamp Redeemed'
|
||||
};
|
||||
return labels[type] || type.replace(/_/g, ' ');
|
||||
if (type) {
|
||||
return I18n.t('loyalty.transactions.' + type, {defaultValue: type.replace(/_/g, ' ')});
|
||||
}
|
||||
return type;
|
||||
},
|
||||
|
||||
formatNumber(num) {
|
||||
|
||||
Reference in New Issue
Block a user