feat: add i18n translations for book components, services, and readers (en/es) (#2738)
This commit is contained in:
@@ -9,6 +9,7 @@ import {LoadingService} from '../../../core/services/loading.service';
|
||||
import {User} from '../../settings/user-management/user.service';
|
||||
import {APIException} from '../../../shared/models/api-exception.model';
|
||||
import {HttpErrorResponse} from '@angular/common/http';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -19,6 +20,7 @@ export class BookMenuService {
|
||||
messageService = inject(MessageService);
|
||||
bookService = inject(BookService);
|
||||
loadingService = inject(LoadingService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
getMetadataMenuItems(
|
||||
autoFetchMetadata: () => void,
|
||||
@@ -34,7 +36,7 @@ export class BookMenuService {
|
||||
|
||||
if (permissions?.canBulkAutoFetchMetadata) {
|
||||
items.push({
|
||||
label: 'Auto Fetch Metadata',
|
||||
label: this.t.translate('book.menuService.menu.autoFetchMetadata'),
|
||||
icon: 'pi pi-bolt',
|
||||
command: autoFetchMetadata
|
||||
});
|
||||
@@ -42,7 +44,7 @@ export class BookMenuService {
|
||||
|
||||
if (permissions?.canBulkCustomFetchMetadata) {
|
||||
items.push({
|
||||
label: 'Custom Fetch Metadata',
|
||||
label: this.t.translate('book.menuService.menu.customFetchMetadata'),
|
||||
icon: 'pi pi-sync',
|
||||
command: fetchMetadata
|
||||
});
|
||||
@@ -50,12 +52,12 @@ export class BookMenuService {
|
||||
|
||||
if (permissions?.canBulkEditMetadata) {
|
||||
items.push({
|
||||
label: 'Bulk Metadata Editor',
|
||||
label: this.t.translate('book.menuService.menu.bulkMetadataEditor'),
|
||||
icon: 'pi pi-table',
|
||||
command: bulkEditMetadata
|
||||
});
|
||||
items.push({
|
||||
label: 'Multi-Book Metadata Editor',
|
||||
label: this.t.translate('book.menuService.menu.multiBookMetadataEditor'),
|
||||
icon: 'pi pi-clone',
|
||||
command: multiBookEditMetadata
|
||||
});
|
||||
@@ -63,12 +65,12 @@ export class BookMenuService {
|
||||
|
||||
if (permissions?.canBulkRegenerateCover) {
|
||||
items.push({
|
||||
label: 'Regenerate Covers',
|
||||
label: this.t.translate('book.menuService.menu.regenerateCovers'),
|
||||
icon: 'pi pi-image',
|
||||
command: regenerateCovers
|
||||
});
|
||||
items.push({
|
||||
label: 'Generate Custom Covers',
|
||||
label: this.t.translate('book.menuService.menu.generateCustomCovers'),
|
||||
icon: 'pi pi-palette',
|
||||
command: generateCustomCovers
|
||||
});
|
||||
@@ -84,27 +86,27 @@ export class BookMenuService {
|
||||
|
||||
if (permissions?.canBulkResetBookReadStatus) {
|
||||
items.push({
|
||||
label: 'Update Read Status',
|
||||
label: this.t.translate('book.menuService.menu.updateReadStatus'),
|
||||
icon: 'pi pi-book',
|
||||
items: Object.entries(readStatusLabels).map(([status, label]) => ({
|
||||
label,
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to mark ${count} book(s) as "${label}"?`,
|
||||
header: 'Confirm Read Status Update',
|
||||
message: this.t.translate('book.menuService.confirm.readStatusMessage', {count, label}),
|
||||
header: this.t.translate('book.menuService.confirm.readStatusHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
acceptButtonProps: {
|
||||
label: 'Yes',
|
||||
label: this.t.translate('common.yes'),
|
||||
severity: 'success'
|
||||
},
|
||||
rejectButtonProps: {
|
||||
label: 'No',
|
||||
label: this.t.translate('common.no'),
|
||||
severity: 'secondary'
|
||||
},
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Updating read status for ${count} book(s)...`);
|
||||
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.updatingReadStatus', {count}));
|
||||
|
||||
this.bookService.updateBookReadStatus(Array.from(selectedBooks), status as ReadStatus)
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
@@ -112,8 +114,8 @@ export class BookMenuService {
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Read Status Updated',
|
||||
detail: `Marked as "${label}"`,
|
||||
summary: this.t.translate('book.menuService.toast.readStatusUpdatedSummary'),
|
||||
detail: this.t.translate('book.menuService.toast.readStatusUpdatedDetail', {label}),
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
@@ -121,8 +123,8 @@ export class BookMenuService {
|
||||
const apiError = err.error as APIException;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: apiError?.message || 'Could not update read status.',
|
||||
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
|
||||
detail: apiError?.message || this.t.translate('book.menuService.toast.readStatusFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
@@ -136,20 +138,20 @@ export class BookMenuService {
|
||||
|
||||
if (permissions?.canBulkEditMetadata) {
|
||||
items.push({
|
||||
label: 'Set Age Rating',
|
||||
label: this.t.translate('book.menuService.menu.setAgeRating'),
|
||||
icon: 'pi pi-user',
|
||||
items: [
|
||||
...AGE_RATING_OPTIONS.map(option => ({
|
||||
label: option.label,
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to set the age rating to "${option.label}" for ${count} book(s)?`,
|
||||
header: 'Confirm Age Rating Update',
|
||||
message: this.t.translate('book.menuService.confirm.ageRatingMessage', {label: option.label, count}),
|
||||
header: this.t.translate('book.menuService.confirm.ageRatingHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Setting age rating for ${count} book(s)...`);
|
||||
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.settingAgeRating', {count}));
|
||||
this.bookService.updateBooksMetadata({
|
||||
bookIds: Array.from(selectedBooks),
|
||||
ageRating: option.id
|
||||
@@ -158,8 +160,8 @@ export class BookMenuService {
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Age Rating Updated',
|
||||
detail: `Set to "${option.label}"`,
|
||||
summary: this.t.translate('book.menuService.toast.ageRatingUpdatedSummary'),
|
||||
detail: this.t.translate('book.menuService.toast.ageRatingUpdatedDetail', {label: option.label}),
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
@@ -167,8 +169,8 @@ export class BookMenuService {
|
||||
const apiError = err.error as APIException;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: apiError?.message || 'Could not update age rating.',
|
||||
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
|
||||
detail: apiError?.message || this.t.translate('book.menuService.toast.ageRatingFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
@@ -181,17 +183,17 @@ export class BookMenuService {
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: 'Clear Age Rating',
|
||||
label: this.t.translate('book.menuService.menu.clearAgeRating'),
|
||||
icon: 'pi pi-times',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to clear the age rating for ${count} book(s)?`,
|
||||
header: 'Confirm Clear Age Rating',
|
||||
message: this.t.translate('book.menuService.confirm.clearAgeRatingMessage', {count}),
|
||||
header: this.t.translate('book.menuService.confirm.clearAgeRatingHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Clearing age rating for ${count} book(s)...`);
|
||||
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.clearingAgeRating', {count}));
|
||||
this.bookService.updateBooksMetadata({
|
||||
bookIds: Array.from(selectedBooks),
|
||||
clearAgeRating: true
|
||||
@@ -200,8 +202,8 @@ export class BookMenuService {
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Age Rating Cleared',
|
||||
detail: 'Age rating has been cleared.',
|
||||
summary: this.t.translate('book.menuService.toast.ageRatingClearedSummary'),
|
||||
detail: this.t.translate('book.menuService.toast.ageRatingClearedDetail'),
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
@@ -209,8 +211,8 @@ export class BookMenuService {
|
||||
const apiError = err.error as APIException;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: apiError?.message || 'Could not clear age rating.',
|
||||
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
|
||||
detail: apiError?.message || this.t.translate('book.menuService.toast.clearAgeRatingFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
@@ -223,20 +225,20 @@ export class BookMenuService {
|
||||
});
|
||||
|
||||
items.push({
|
||||
label: 'Set Content Rating',
|
||||
label: this.t.translate('book.menuService.menu.setContentRating'),
|
||||
icon: 'pi pi-shield',
|
||||
items: [
|
||||
...Object.entries(CONTENT_RATING_LABELS).map(([value, label]) => ({
|
||||
label: label,
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to set the content rating to "${label}" for ${count} book(s)?`,
|
||||
header: 'Confirm Content Rating Update',
|
||||
message: this.t.translate('book.menuService.confirm.contentRatingMessage', {label, count}),
|
||||
header: this.t.translate('book.menuService.confirm.contentRatingHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Setting content rating for ${count} book(s)...`);
|
||||
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.settingContentRating', {count}));
|
||||
this.bookService.updateBooksMetadata({
|
||||
bookIds: Array.from(selectedBooks),
|
||||
contentRating: value
|
||||
@@ -245,8 +247,8 @@ export class BookMenuService {
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Content Rating Updated',
|
||||
detail: `Set to "${label}"`,
|
||||
summary: this.t.translate('book.menuService.toast.contentRatingUpdatedSummary'),
|
||||
detail: this.t.translate('book.menuService.toast.contentRatingUpdatedDetail', {label}),
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
@@ -254,8 +256,8 @@ export class BookMenuService {
|
||||
const apiError = err.error as APIException;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: apiError?.message || 'Could not update content rating.',
|
||||
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
|
||||
detail: apiError?.message || this.t.translate('book.menuService.toast.contentRatingFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
@@ -268,17 +270,17 @@ export class BookMenuService {
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: 'Clear Content Rating',
|
||||
label: this.t.translate('book.menuService.menu.clearContentRating'),
|
||||
icon: 'pi pi-times',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to clear the content rating for ${count} book(s)?`,
|
||||
header: 'Confirm Clear Content Rating',
|
||||
message: this.t.translate('book.menuService.confirm.clearContentRatingMessage', {count}),
|
||||
header: this.t.translate('book.menuService.confirm.clearContentRatingHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Clearing content rating for ${count} book(s)...`);
|
||||
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.clearingContentRating', {count}));
|
||||
this.bookService.updateBooksMetadata({
|
||||
bookIds: Array.from(selectedBooks),
|
||||
clearContentRating: true
|
||||
@@ -287,8 +289,8 @@ export class BookMenuService {
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Content Rating Cleared',
|
||||
detail: 'Content rating has been cleared.',
|
||||
summary: this.t.translate('book.menuService.toast.contentRatingClearedSummary'),
|
||||
detail: this.t.translate('book.menuService.toast.contentRatingClearedDetail'),
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
@@ -296,8 +298,8 @@ export class BookMenuService {
|
||||
const apiError = err.error as APIException;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: apiError?.message || 'Could not clear content rating.',
|
||||
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
|
||||
detail: apiError?.message || this.t.translate('book.menuService.toast.clearContentRatingFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
@@ -313,17 +315,17 @@ export class BookMenuService {
|
||||
// Shelf Actions
|
||||
if (permissions?.canManageLibrary || permissions?.admin) { // Assuming these permissions cover shelf management for books
|
||||
items.push({
|
||||
label: 'Remove from all shelves',
|
||||
label: this.t.translate('book.menuService.menu.removeFromAllShelves'),
|
||||
icon: 'pi pi-bookmark-fill', // Or bookmark-slash
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to remove ${count} book(s) from ALL their shelves?`,
|
||||
header: 'Confirm Unshelve',
|
||||
message: this.t.translate('book.menuService.confirm.unshelveMessage', {count}),
|
||||
header: this.t.translate('book.menuService.confirm.unshelveHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Removing ${count} book(s) from shelves...`);
|
||||
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.removingFromShelves', {count}));
|
||||
const books = this.bookService.getBooksByIdsFromState(Array.from(selectedBooks));
|
||||
const allShelfIds = new Set<number>();
|
||||
books.forEach(b => b.shelves?.forEach(s => {
|
||||
@@ -332,7 +334,7 @@ export class BookMenuService {
|
||||
|
||||
if (allShelfIds.size === 0) {
|
||||
this.loadingService.hide(loader);
|
||||
this.messageService.add({ severity: 'info', summary: 'Info', detail: 'Selected books are not on any shelves.' });
|
||||
this.messageService.add({ severity: 'info', summary: 'Info', detail: this.t.translate('book.menuService.toast.noBooksOnShelvesDetail') });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -340,10 +342,10 @@ export class BookMenuService {
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Books removed from all shelves'});
|
||||
this.messageService.add({severity: 'success', summary: this.t.translate('common.success'), detail: this.t.translate('book.menuService.toast.unshelveSuccessDetail')});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update books shelves'});
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('common.error'), detail: this.t.translate('book.menuService.toast.unshelveFailedDetail')});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -354,17 +356,17 @@ export class BookMenuService {
|
||||
|
||||
if (permissions?.canBulkResetBookloreReadProgress) {
|
||||
items.push({
|
||||
label: 'Reset Booklore Progress',
|
||||
label: this.t.translate('book.menuService.menu.resetBookloreProgress'),
|
||||
icon: 'pi pi-undo',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to reset Booklore reading progress for ${count} book(s)?`,
|
||||
header: 'Confirm Reset',
|
||||
message: this.t.translate('book.menuService.confirm.resetBookloreMessage', {count}),
|
||||
header: this.t.translate('book.menuService.confirm.resetHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Resetting Booklore progress for ${count} book(s)...`);
|
||||
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.resettingBookloreProgress', {count}));
|
||||
|
||||
this.bookService.resetProgress(Array.from(selectedBooks), ResetProgressTypes.BOOKLORE)
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
@@ -372,8 +374,8 @@ export class BookMenuService {
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Progress Reset',
|
||||
detail: 'Booklore reading progress has been reset.',
|
||||
summary: this.t.translate('book.menuService.toast.progressResetSummary'),
|
||||
detail: this.t.translate('book.menuService.toast.bookloreProgressResetDetail'),
|
||||
life: 1500
|
||||
});
|
||||
},
|
||||
@@ -381,8 +383,8 @@ export class BookMenuService {
|
||||
const apiError = err.error as APIException;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Failed',
|
||||
detail: apiError?.message || 'Could not reset progress.',
|
||||
summary: this.t.translate('book.menuService.toast.failedSummary'),
|
||||
detail: apiError?.message || this.t.translate('book.menuService.toast.progressResetFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
@@ -395,17 +397,17 @@ export class BookMenuService {
|
||||
|
||||
if (permissions?.canBulkResetKoReaderReadProgress) {
|
||||
items.push({
|
||||
label: 'Reset KOReader Progress',
|
||||
label: this.t.translate('book.menuService.menu.resetKOReaderProgress'),
|
||||
icon: 'pi pi-undo',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to reset KOReader reading progress for ${count} book(s)?`,
|
||||
header: 'Confirm Reset',
|
||||
message: this.t.translate('book.menuService.confirm.resetKOReaderMessage', {count}),
|
||||
header: this.t.translate('book.menuService.confirm.resetHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Resetting KOReader progress for ${count} book(s)...`);
|
||||
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.resettingKOReaderProgress', {count}));
|
||||
|
||||
this.bookService.resetProgress(Array.from(selectedBooks), ResetProgressTypes.KOREADER)
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
@@ -413,8 +415,8 @@ export class BookMenuService {
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Progress Reset',
|
||||
detail: 'KOReader reading progress has been reset.',
|
||||
summary: this.t.translate('book.menuService.toast.progressResetSummary'),
|
||||
detail: this.t.translate('book.menuService.toast.koreaderProgressResetDetail'),
|
||||
life: 1500
|
||||
});
|
||||
},
|
||||
@@ -422,8 +424,8 @@ export class BookMenuService {
|
||||
const apiError = err.error as APIException;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Failed',
|
||||
detail: apiError?.message || 'Could not reset progress.',
|
||||
summary: this.t.translate('book.menuService.toast.failedSummary'),
|
||||
detail: apiError?.message || this.t.translate('book.menuService.toast.progressResetFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user