diff --git a/frontend/messages/en.json b/frontend/messages/en.json index 61c68003..cca694eb 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -17,6 +17,7 @@ "image_should_be_in_format": "The image should be in PNG or JPEG format.", "items_per_page": "Items per page", "no_items_found": "No items found", + "select_items": "Select items...", "search": "Search...", "expand_card": "Expand card", "copied": "Copied", diff --git a/frontend/src/lib/components/audit-log-list.svelte b/frontend/src/lib/components/audit-log-list.svelte index 48ce1ce3..384a2cc8 100644 --- a/frontend/src/lib/components/audit-log-list.svelte +++ b/frontend/src/lib/components/audit-log-list.svelte @@ -3,6 +3,7 @@ import { Badge } from '$lib/components/ui/badge'; import * as Table from '$lib/components/ui/table'; import { m } from '$lib/paraglide/messages'; + import {translateAuditLogEvent} from "$lib/utils/audit-log-translator"; import AuditLogService from '$lib/services/audit-log-service'; import type { AuditLog } from '$lib/types/audit-log.type'; import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type'; @@ -18,14 +19,6 @@ } = $props(); const auditLogService = new AuditLogService(); - - function toFriendlyEventString(event: string) { - const words = event.split('_'); - const capitalizedWords = words.map((word) => { - return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); - }); - return capitalizedWords.join(' '); - } {/if} - {toFriendlyEventString(item.event)} + {translateAuditLogEvent(item.event)} {item.city && item.country ? `${item.city}, ${item.country}` : m.unknown()} void; oninput?: FormEventHandler; isLoading?: boolean; - placeholder?: string; - searchText?: string; - noItemsText?: string; disableInternalSearch?: boolean; id?: string; } = $props(); @@ -93,7 +88,7 @@ {label} {/each} {:else} - {placeholder} + {m.select_items()} {/if} @@ -103,7 +98,7 @@ { filterItems(e.currentTarget.value); @@ -116,7 +111,7 @@ {:else} - {noItemsText} + {m.no_items_found()} {/if} diff --git a/frontend/src/lib/utils/audit-log-translator.ts b/frontend/src/lib/utils/audit-log-translator.ts new file mode 100644 index 00000000..d5e41798 --- /dev/null +++ b/frontend/src/lib/utils/audit-log-translator.ts @@ -0,0 +1,29 @@ +import { m } from '$lib/paraglide/messages'; + +export const eventTypes: Record = { + SIGN_IN: m.sign_in(), + TOKEN_SIGN_IN: m.token_sign_in(), + CLIENT_AUTHORIZATION: m.client_authorization(), + NEW_CLIENT_AUTHORIZATION: m.new_client_authorization(), + ACCOUNT_CREATED: m.account_created() +} + +/** + * Translates an audit log event type using paraglide messages. + * Falls back to a formatted string if no specific translation is found. + * @param event The event type string from the backend (e.g., "CLIENT_AUTHORIZATION"). + * @returns The translated string. + */ +export function translateAuditLogEvent(event: string): string { + if (event in eventTypes) { + return eventTypes[event]; + } + + // If no specific translation is found, provide a readable fallback. + // This converts "SOME_EVENT" to "Some Event". + const words = event.split('_'); + const capitalizedWords = words.map((word) => { + return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); + }); + return capitalizedWords.join(' '); +} diff --git a/frontend/src/routes/settings/admin/users/+page.svelte b/frontend/src/routes/settings/admin/users/+page.svelte index da0b59ec..45674251 100644 --- a/frontend/src/routes/settings/admin/users/+page.svelte +++ b/frontend/src/routes/settings/admin/users/+page.svelte @@ -21,7 +21,7 @@ let signupTokens = $state(data.signupTokens); let signupTokensRequestOptions = $state(data.signupTokensRequestOptions); - let selectedCreateOptions = $state('Add User'); + let selectedCreateOptions = $state(m.add_user()); let expandAddUser = $state(false); let signupTokenModalOpen = $state(false); let signupTokenListModalOpen = $state(false); diff --git a/frontend/src/routes/settings/audit-log/global/+page.svelte b/frontend/src/routes/settings/audit-log/global/+page.svelte index e8acc98b..26fb4c9d 100644 --- a/frontend/src/routes/settings/audit-log/global/+page.svelte +++ b/frontend/src/routes/settings/audit-log/global/+page.svelte @@ -7,6 +7,7 @@ import AuditLogService from '$lib/services/audit-log-service'; import type { AuditLogFilter } from '$lib/types/audit-log.type'; import AuditLogSwitcher from '../audit-log-switcher.svelte'; + import {eventTypes as eventTranslations} from "$lib/utils/audit-log-translator"; let { data } = $props(); @@ -27,13 +28,7 @@ internal: 'Internal Networks' }); - const eventTypes = $state({ - SIGN_IN: m.sign_in(), - TOKEN_SIGN_IN: m.token_sign_in(), - CLIENT_AUTHORIZATION: m.client_authorization(), - NEW_CLIENT_AUTHORIZATION: m.new_client_authorization(), - ACCOUNT_CREATED: m.account_created() - }); + const eventTypes = $state(eventTranslations); $effect(() => { auditLogService.listAllLogs(requestOptions, filters).then((response) => (auditLogs = response));