added i18n for backend errors

This commit is contained in:
2026-01-28 19:31:14 +01:00
parent f029a322c4
commit 81d9624c9e
15 changed files with 316 additions and 162 deletions
+30
View File
@@ -0,0 +1,30 @@
import { useFluent } from 'fluent-vue';
import { ApiError } from './api/client';
export function useErrorTranslator() {
const { $t } = useFluent();
function translateError(err: unknown): string {
if (err instanceof ApiError) {
// Convert "AUTH_INVALID_CREDENTIALS" -> "error-auth-invalid-credentials"
const key = `error-${err.code.toLowerCase().replace(/_/g, '-')}`;
const translated = $t(key);
// Fallback to the message provided by backend.
if (translated === key) {
return err.message;
}
return translated;
}
if (err instanceof Error) {
return err.message;
}
return $t('shared-error');
}
return { translateError };
}