1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-23 01:27:14 +02:00

Adding Enum translations #569

This commit is contained in:
Patrik J. Braun 2023-01-01 22:37:25 +01:00
parent 84ed0cf256
commit bd5f89fd09
4 changed files with 57 additions and 18 deletions

View File

@ -1,26 +1,12 @@
import { Pipe, PipeTransform } from '@angular/core';
import { SortingMethods } from '../../../common/entities/SortingMethods';
import {EnumTranslations} from '../ui/EnumTranslations';
@Pipe({ name: 'stringifySorting' })
export class StringifySortingMethod implements PipeTransform {
transform(method: SortingMethods): string {
switch (method) {
case SortingMethods.ascRating:
return $localize`ascending rating`;
case SortingMethods.descRating:
return $localize`descending rating`;
case SortingMethods.ascName:
return $localize`ascending name`;
case SortingMethods.descName:
return $localize`descending name`;
case SortingMethods.ascDate:
return $localize`ascending date`;
case SortingMethods.descDate:
return $localize`descending date`;
case SortingMethods.random:
return $localize`random`;
}
return EnumTranslations[SortingMethods[method]];
}
}

View File

@ -0,0 +1,51 @@
import {UserRoles} from '../../../common/entities/UserDTO';
import {ConfigPriority, MapProviders, NavigationLinkTypes} from '../../../common/config/public/ClientConfig';
import {ReIndexingSensitivity} from '../../../common/config/private/PrivateConfig';
import {SortingMethods} from '../../../common/entities/SortingMethods';
export const EnumTranslations: Record<string, string> = {};
export const enumToTranslatedArray = (EnumType: any): { key: number; value: string }[] => {
const arr: Array<{ key: number; value: string }> = [];
for (const enumMember in EnumType) {
const key = parseInt(enumMember, 10);
if (key >= 0) {
arr.push({key, value: EnumTranslations[EnumType[enumMember]] || EnumType[enumMember]});
}
}
return arr;
};
EnumTranslations[UserRoles[UserRoles.Developer]] = $localize`Developer`;
EnumTranslations[UserRoles[UserRoles.Admin]] = $localize`Admin`;
EnumTranslations[UserRoles[UserRoles.User]] = $localize`User`;
EnumTranslations[UserRoles[UserRoles.Guest]] = $localize`Guest`;
EnumTranslations[UserRoles[UserRoles.LimitedGuest]] = $localize`LimitedGuest`;
EnumTranslations[ConfigPriority[ConfigPriority.basic]] = $localize`Basic`;
EnumTranslations[ConfigPriority[ConfigPriority.advanced]] = $localize`Advanced`;
EnumTranslations[ConfigPriority[ConfigPriority.underTheHood]] = $localize`Under the hood`;
EnumTranslations[MapProviders[MapProviders.Custom]] = $localize`Custom`;
EnumTranslations[MapProviders[MapProviders.OpenStreetMap]] = $localize`OpenStreetMap`;
EnumTranslations[MapProviders[MapProviders.Mapbox]] = $localize`Mapbox`;
EnumTranslations[ReIndexingSensitivity[ReIndexingSensitivity.low]] = $localize`low`;
EnumTranslations[ReIndexingSensitivity[ReIndexingSensitivity.high]] = $localize`high`;
EnumTranslations[ReIndexingSensitivity[ReIndexingSensitivity.medium]] = $localize`medium`;
EnumTranslations[SortingMethods[SortingMethods.descDate]] = $localize`descending date`;
EnumTranslations[SortingMethods[SortingMethods.ascDate]] = $localize`ascending date`;
EnumTranslations[SortingMethods[SortingMethods.descName]] = $localize`descending name`;
EnumTranslations[SortingMethods[SortingMethods.ascName]] = $localize`ascending name`;
EnumTranslations[SortingMethods[SortingMethods.descRating]] = $localize`descending rating`;
EnumTranslations[SortingMethods[SortingMethods.ascRating]] = $localize`ascending rating`;
EnumTranslations[SortingMethods[SortingMethods.random]] = $localize`random`;
EnumTranslations[NavigationLinkTypes[NavigationLinkTypes.url]] = $localize`Url`;
EnumTranslations[NavigationLinkTypes[NavigationLinkTypes.search]] = $localize`Search`;
EnumTranslations[NavigationLinkTypes[NavigationLinkTypes.gallery]] = $localize`Gallery`;
EnumTranslations[NavigationLinkTypes[NavigationLinkTypes.albums]] = $localize`Albums`;
EnumTranslations[NavigationLinkTypes[NavigationLinkTypes.faces]] = $localize`Faces`;

View File

@ -11,6 +11,7 @@ import {Utils} from '../../../../common/Utils';
import {WebConfig} from '../../../../common/config/private/WebConfig';
import {ISettingsComponent} from '../settings/template/ISettingsComponent';
import {WebConfigClassBuilder} from '../../../../../node_modules/typeconfig/src/decorators/builders/WebConfigClassBuilder';
import {enumToTranslatedArray} from '../EnumTranslations';
@Component({
selector: 'app-admin',
@ -32,7 +33,7 @@ export class AdminComponent implements OnInit, AfterViewInit {
public notificationService: NotificationService,
public settingsService: SettingsService,
) {
this.configPriorities = Utils.enumToArray(ConfigPriority);
this.configPriorities = enumToTranslatedArray(ConfigPriority);
const wc = WebConfigClassBuilder.attachPrivateInterface(new WebConfig());
this.configPaths = Object.keys(wc.State)
.filter(s => !wc.__state[s].volatile);

View File

@ -7,6 +7,7 @@ import {MapLayers, NavigationLinkConfig, NavigationLinkTypes, TAGS} from '../../
import {SettingsService} from '../../settings.service';
import {WebConfig} from '../../../../../../common/config/private/WebConfig';
import {JobScheduleConfig, UserConfig} from '../../../../../../common/config/private/PrivateConfig';
import {enumToTranslatedArray} from '../../../EnumTranslations';
interface IState {
shouldHide(): boolean;
@ -264,7 +265,7 @@ export class SettingsEntryComponent
value: o + (state.tags?.unit ? state.tags?.unit : '')
}));
} else {
optionsView = Utils.enumToArray(eClass);
optionsView = enumToTranslatedArray(eClass);
}
return optionsView;
}