Fix untranslatable UI strings, broken pluralization, and translation reactivity (#3108) (#3233)

This commit is contained in:
ACX
2026-03-07 16:50:12 -07:00
committed by GitHub
parent a03297bb46
commit 1b3e3da699
18 changed files with 350 additions and 177 deletions
@@ -38,7 +38,7 @@
<div class="weights-grid">
@for (key of orderedKeys; track key) {
<div class="weight-field">
<label class="field-label">{{ labelMap[key] }}</label>
<label class="field-label">{{ getFieldLabel(key) }}</label>
<p-inputNumber
size="small"
[formControlName]="key"
@@ -23,34 +23,14 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
})
export class MetadataMatchWeightsComponent implements OnInit {
readonly labelMap: Record<string, string> = {
title: 'Title',
subtitle: 'Subtitle',
authors: 'Authors',
description: 'Description',
publisher: 'Publisher',
publishedDate: 'Published Date',
categories: 'Categories',
coverImage: 'Cover Image',
seriesName: 'Series Name',
seriesNumber: 'Series Number',
seriesTotal: 'Series Total',
language: 'Language',
isbn13: 'ISBN-13',
isbn10: 'ISBN-10',
pageCount: 'Page Count',
amazonRating: 'Amazon Rating',
amazonReviewCount: 'Amazon Rating #',
goodreadsRating: 'Goodreads Rating',
goodreadsReviewCount: 'Goodreads Rating #',
hardcoverRating: 'Hardcover Rating',
hardcoverReviewCount: 'Hardcover Rating #',
audibleRating: 'Audible Rating',
audibleReviewCount: 'Audible Rating #',
doubanRating: 'Douban Rating',
doubanReviewCount: 'Douban Rating #',
ranobedbRating: 'Ranobedb Rating',
};
readonly orderedFieldKeys: string[] = [
'title', 'subtitle', 'authors', 'description', 'publisher', 'publishedDate',
'categories', 'coverImage', 'seriesName', 'seriesNumber', 'seriesTotal',
'language', 'isbn13', 'isbn10', 'pageCount',
'amazonRating', 'amazonReviewCount', 'goodreadsRating', 'goodreadsReviewCount',
'hardcoverRating', 'hardcoverReviewCount', 'audibleRating', 'audibleReviewCount',
'doubanRating', 'doubanReviewCount', 'ranobedbRating'
];
form!: FormGroup;
isSaving = false;
@@ -103,7 +83,11 @@ export class MetadataMatchWeightsComponent implements OnInit {
}
get orderedKeys(): string[] {
return Object.keys(this.labelMap);
return this.orderedFieldKeys;
}
getFieldLabel(key: string): string {
return this.t.translate('settingsMeta.matchWeights.fields.' + key);
}
save(): void {
@@ -19,13 +19,15 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
})
export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
readonly sortingOptions = [
{label: 'Name | Ascending', value: {field: 'name', order: 'asc'}, translationKey: 'nameAsc'},
{label: 'Name | Descending', value: {field: 'name', order: 'desc'}, translationKey: 'nameDesc'},
{label: 'Creation Date | Ascending', value: {field: 'id', order: 'asc'}, translationKey: 'creationAsc'},
{label: 'Creation Date | Descending', value: {field: 'id', order: 'desc'}, translationKey: 'creationDesc'},
private readonly sortingOptionDefs = [
{value: {field: 'name', order: 'asc'}, translationKey: 'nameAsc'},
{value: {field: 'name', order: 'desc'}, translationKey: 'nameDesc'},
{value: {field: 'id', order: 'asc'}, translationKey: 'creationAsc'},
{value: {field: 'id', order: 'desc'}, translationKey: 'creationDesc'},
];
sortingOptions: {label: string; value: {field: string; order: string}; translationKey: string}[] = [];
selectedLibrarySorting: SidebarLibrarySorting = {field: 'id', order: 'asc'};
selectedShelfSorting: SidebarShelfSorting = {field: 'id', order: 'asc'};
selectedMagicShelfSorting: SidebarMagicShelfSorting = {field: 'id', order: 'asc'};
@@ -39,6 +41,9 @@ export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
private currentUser: User | null = null;
ngOnInit(): void {
this.buildSortingOptions();
this.t.langChanges$.pipe(takeUntil(this.destroy$)).subscribe(() => this.buildSortingOptions());
this.userData$.pipe(
filter(userState => !!userState?.user && userState.loaded),
takeUntil(this.destroy$)
@@ -53,6 +58,13 @@ export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
this.destroy$.complete();
}
private buildSortingOptions(): void {
this.sortingOptions = this.sortingOptionDefs.map(opt => ({
...opt,
label: this.t.translate('settingsView.sidebarSort.' + opt.translationKey)
}));
}
private loadPreferences(settings: UserSettings): void {
this.selectedLibrarySorting = settings.sidebarLibrarySorting;
this.selectedShelfSorting = settings.sidebarShelfSorting;
@@ -44,47 +44,42 @@ import {CdkDrag, CdkDragDrop, CdkDragHandle, CdkDropList, moveItemInArray} from
export class ViewPreferencesComponent implements OnInit, OnDestroy {
private t = inject(TranslocoService);
sortOptions: {label: string; field: string; translationKey: string}[] = [
{label: 'Title', field: 'title', translationKey: 'sortTitle'},
{label: 'File Name', field: 'fileName', translationKey: 'sortFileName'},
{label: 'File Path', field: 'filePath', translationKey: 'sortFilePath'},
{label: 'Author', field: 'author', translationKey: 'sortAuthor'},
{label: 'Author (Surname)', field: 'authorSurnameVorname', translationKey: 'sortAuthorSurname'},
{label: 'Series Name', field: 'seriesName', translationKey: 'sortSeriesName'},
{label: 'Series Number', field: 'seriesNumber', translationKey: 'sortSeriesNumber'},
{label: 'Last Read', field: 'lastReadTime', translationKey: 'sortLastRead'},
{label: 'Personal Rating', field: 'personalRating', translationKey: 'sortPersonalRating'},
{label: 'Added On', field: 'addedOn', translationKey: 'sortAddedOn'},
{label: 'File Size', field: 'fileSizeKb', translationKey: 'sortFileSize'},
{label: 'Locked', field: 'locked', translationKey: 'sortLocked'},
{label: 'Publisher', field: 'publisher', translationKey: 'sortPublisher'},
{label: 'Published Date', field: 'publishedDate', translationKey: 'sortPublishedDate'},
{label: 'Read Status', field: 'readStatus', translationKey: 'sortReadStatus'},
{label: 'Date Finished', field: 'dateFinished', translationKey: 'sortDateFinished'},
{label: 'Reading Progress', field: 'readingProgress', translationKey: 'sortReadingProgress'},
{label: 'Book Type', field: 'bookType', translationKey: 'sortBookType'},
{label: 'Amazon Rating', field: 'amazonRating', translationKey: 'sortAmazonRating'},
{label: 'Amazon #', field: 'amazonReviewCount', translationKey: 'sortAmazonCount'},
{label: 'Goodreads Rating', field: 'goodreadsRating', translationKey: 'sortGoodreadsRating'},
{label: 'Goodreads #', field: 'goodreadsReviewCount', translationKey: 'sortGoodreadsCount'},
{label: 'Hardcover Rating', field: 'hardcoverRating', translationKey: 'sortHardcoverRating'},
{label: 'Hardcover #', field: 'hardcoverReviewCount', translationKey: 'sortHardcoverCount'},
{label: 'Ranobedb Rating', field: 'ranobedbRating', translationKey: 'sortRanobedbRating'},
{label: 'Narrator', field: 'narrator', translationKey: 'sortNarrator'},
{label: 'Pages', field: 'pageCount', translationKey: 'sortPages'},
{label: 'Random', field: 'random', translationKey: 'sortRandom'},
private readonly sortOptionDefs: {field: string; translationKey: string}[] = [
{field: 'title', translationKey: 'sortTitle'},
{field: 'fileName', translationKey: 'sortFileName'},
{field: 'filePath', translationKey: 'sortFilePath'},
{field: 'author', translationKey: 'sortAuthor'},
{field: 'authorSurnameVorname', translationKey: 'sortAuthorSurname'},
{field: 'seriesName', translationKey: 'sortSeriesName'},
{field: 'seriesNumber', translationKey: 'sortSeriesNumber'},
{field: 'lastReadTime', translationKey: 'sortLastRead'},
{field: 'personalRating', translationKey: 'sortPersonalRating'},
{field: 'addedOn', translationKey: 'sortAddedOn'},
{field: 'fileSizeKb', translationKey: 'sortFileSize'},
{field: 'locked', translationKey: 'sortLocked'},
{field: 'publisher', translationKey: 'sortPublisher'},
{field: 'publishedDate', translationKey: 'sortPublishedDate'},
{field: 'readStatus', translationKey: 'sortReadStatus'},
{field: 'dateFinished', translationKey: 'sortDateFinished'},
{field: 'readingProgress', translationKey: 'sortReadingProgress'},
{field: 'bookType', translationKey: 'sortBookType'},
{field: 'amazonRating', translationKey: 'sortAmazonRating'},
{field: 'amazonReviewCount', translationKey: 'sortAmazonCount'},
{field: 'goodreadsRating', translationKey: 'sortGoodreadsRating'},
{field: 'goodreadsReviewCount', translationKey: 'sortGoodreadsCount'},
{field: 'hardcoverRating', translationKey: 'sortHardcoverRating'},
{field: 'hardcoverReviewCount', translationKey: 'sortHardcoverCount'},
{field: 'ranobedbRating', translationKey: 'sortRanobedbRating'},
{field: 'narrator', translationKey: 'sortNarrator'},
{field: 'pageCount', translationKey: 'sortPages'},
{field: 'random', translationKey: 'sortRandom'},
];
entityTypeOptions: {label: string; value: string; translationKey: string}[] = [
{label: 'Library', value: 'LIBRARY', translationKey: 'entityLibrary'},
{label: 'Shelf', value: 'SHELF', translationKey: 'entityShelf'},
{label: 'Magic Shelf', value: 'MAGIC_SHELF', translationKey: 'entityMagicShelf'}
];
sortOptions: {label: string; field: string; translationKey: string}[] = [];
viewModeOptions: {label: string; value: string; translationKey: string}[] = [
{label: 'Grid', value: 'GRID', translationKey: 'viewGrid'},
{label: 'Table', value: 'TABLE', translationKey: 'viewTable'}
];
entityTypeOptions: {label: string; value: string; translationKey: string}[] = [];
viewModeOptions: {label: string; value: string; translationKey: string}[] = [];
libraryOptions: { label: string; value: number }[] = [];
shelfOptions: { label: string; value: number }[] = [];
@@ -128,6 +123,20 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
private messageService = inject(MessageService);
ngOnInit(): void {
this.rebuildTranslatedLabels();
this.t.langChanges$.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.rebuildTranslatedLabels();
this.allSortAsOptions = this.sortOptions.map(o => ({
label: this.t.translate('settingsView.librarySort.' + o.translationKey),
field: o.field,
direction: SortDirection.ASCENDING
}));
this.globalSortAsOptions = this.toSortOptions(this.sortCriteria);
this.overrides.forEach(o => {
o.sortCriteriaAsOptions = this.toSortOptions(o.sortCriteria);
});
});
combineLatest([
this.userService.userState$.pipe(filter(userState => !!userState?.user && userState.loaded), take(1)),
this.libraryService.libraryState$.pipe(filter(libraryState => !!libraryState?.libraries && libraryState.loaded), take(1)),
@@ -196,6 +205,23 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
});
}
private rebuildTranslatedLabels(): void {
this.sortOptions = this.sortOptionDefs.map(o => ({
label: this.t.translate('settingsView.librarySort.' + o.translationKey),
field: o.field,
translationKey: o.translationKey
}));
this.entityTypeOptions = [
{label: this.t.translate('settingsView.librarySort.entityLibrary'), value: 'LIBRARY', translationKey: 'entityLibrary'},
{label: this.t.translate('settingsView.librarySort.entityShelf'), value: 'SHELF', translationKey: 'entityShelf'},
{label: this.t.translate('settingsView.librarySort.entityMagicShelf'), value: 'MAGIC_SHELF', translationKey: 'entityMagicShelf'}
];
this.viewModeOptions = [
{label: this.t.translate('settingsView.librarySort.viewGrid'), value: 'GRID', translationKey: 'viewGrid'},
{label: this.t.translate('settingsView.librarySort.viewTable'), value: 'TABLE', translationKey: 'viewTable'}
];
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();