added translations
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, computed, ChangeDetectionStrategy, signal, OnDestroy } from '@angular/core';
|
||||
import { Component, computed, ChangeDetectionStrategy, signal, OnDestroy, inject } from '@angular/core';
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
@@ -10,10 +10,12 @@ import { EmptyCartIconComponent } from '../../components/empty-cart-icon/empty-c
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { getDiscountedPrice, getMainImage, trackByItemId } from '../../utils/item.utils';
|
||||
import { LangRoutePipe } from '../../pipes/lang-route.pipe';
|
||||
import { TranslatePipe } from '../../i18n/translate.pipe';
|
||||
import { TranslateService } from '../../i18n/translate.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cart',
|
||||
imports: [DecimalPipe, RouterLink, FormsModule, EmptyCartIconComponent, LangRoutePipe],
|
||||
imports: [DecimalPipe, RouterLink, FormsModule, EmptyCartIconComponent, LangRoutePipe, TranslatePipe],
|
||||
templateUrl: './cart.component.html',
|
||||
styleUrls: ['./cart.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
@@ -25,6 +27,8 @@ export class CartComponent implements OnDestroy {
|
||||
termsAccepted = false;
|
||||
isnovo = environment.theme === 'novo';
|
||||
|
||||
private i18n = inject(TranslateService);
|
||||
|
||||
// Swipe state
|
||||
swipedItemId = signal<number | null>(null);
|
||||
|
||||
@@ -116,7 +120,7 @@ export class CartComponent implements OnDestroy {
|
||||
}
|
||||
|
||||
clearCart(): void {
|
||||
if (confirm('Вы уверены, что хотите очистить корзину?')) {
|
||||
if (confirm(this.i18n.t('cart.confirmClear'))) {
|
||||
this.cartService.clearCart();
|
||||
}
|
||||
}
|
||||
@@ -127,7 +131,7 @@ export class CartComponent implements OnDestroy {
|
||||
|
||||
checkout(): void {
|
||||
if (!this.termsAccepted) {
|
||||
alert('Пожалуйста, примите условия оферты, политику возврата и возврата для подтверждения оформления заказа.');
|
||||
alert(this.i18n.t('cart.acceptTerms'));
|
||||
return;
|
||||
}
|
||||
this.openPaymentPopup();
|
||||
@@ -249,7 +253,7 @@ export class CartComponent implements OnDestroy {
|
||||
this.linkCopied.set(true);
|
||||
setTimeout(() => this.linkCopied.set(false), 2000);
|
||||
}).catch(err => {
|
||||
console.error('Ошибка копирования:', err);
|
||||
console.error(this.i18n.t('cart.copyError'), err);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -314,7 +318,7 @@ export class CartComponent implements OnDestroy {
|
||||
next: () => {
|
||||
this.emailSubmitting.set(false);
|
||||
// Show success message
|
||||
alert('Email успешно отправлен! Проверьте свою почту.');
|
||||
alert(this.i18n.t('cart.emailSuccess'));
|
||||
// Close popup and redirect to home page
|
||||
setTimeout(() => {
|
||||
this.closePaymentPopup();
|
||||
@@ -325,7 +329,7 @@ export class CartComponent implements OnDestroy {
|
||||
error: (err) => {
|
||||
console.error('Error submitting email:', err);
|
||||
this.emailSubmitting.set(false);
|
||||
alert('Произошла ошибка при отправке email. Пожалуйста, попробуйте снова.');
|
||||
alert(this.i18n.t('cart.emailError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -386,11 +390,11 @@ export class CartComponent implements OnDestroy {
|
||||
}
|
||||
|
||||
if (digitsOnly.length === 0) {
|
||||
this.phoneError.set('Номер телефона обязателен');
|
||||
this.phoneError.set(this.i18n.t('cart.phoneRequired'));
|
||||
} else if (digitsOnly.length < 11) {
|
||||
this.phoneError.set(`Введите ещё ${11 - digitsOnly.length} цифр`);
|
||||
this.phoneError.set(this.i18n.t('cart.phoneMoreDigits', { count: 11 - digitsOnly.length }));
|
||||
} else if (digitsOnly.length > 11) {
|
||||
this.phoneError.set('Слишком много цифр');
|
||||
this.phoneError.set(this.i18n.t('cart.phoneTooMany'));
|
||||
} else {
|
||||
this.phoneError.set('');
|
||||
}
|
||||
@@ -418,19 +422,19 @@ export class CartComponent implements OnDestroy {
|
||||
}
|
||||
|
||||
if (email.length === 0) {
|
||||
this.emailError.set('Email обязателен');
|
||||
this.emailError.set(this.i18n.t('cart.emailRequired'));
|
||||
} else if (email.length < 5) {
|
||||
this.emailError.set('Email слишком короткий (минимум 5 символов)');
|
||||
this.emailError.set(this.i18n.t('cart.emailTooShort'));
|
||||
} else if (email.length > 100) {
|
||||
this.emailError.set('Email слишком длинный (максимум 100 символов)');
|
||||
this.emailError.set(this.i18n.t('cart.emailTooLong'));
|
||||
} else if (!email.includes('@')) {
|
||||
this.emailError.set('Email должен содержать @');
|
||||
this.emailError.set(this.i18n.t('cart.emailNeedsAt'));
|
||||
} else if (!email.includes('.')) {
|
||||
this.emailError.set('Email должен содержать домен (.com, .ru и т.д.)');
|
||||
this.emailError.set(this.i18n.t('cart.emailNeedsDomain'));
|
||||
} else {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email)) {
|
||||
this.emailError.set('Некорректный формат email');
|
||||
this.emailError.set(this.i18n.t('cart.emailInvalid'));
|
||||
} else {
|
||||
this.emailError.set('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user