feat(localization): Implement Swedish localization and error messages
- Added localization support for Swedish and English languages. - Integrated localized strings for user messages in the API error mapper. - Updated UI components to use localized strings for labels and messages. - Ensured all error messages are context-aware and utilize the localization framework. - Created regression test to prevent common ASCII fallbacks in Swedish UI text.
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
import 'api_exception.dart';
|
||||
|
||||
String mapErrorToUserMessage(Object error) {
|
||||
String mapErrorToUserMessage(Object error, BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
if (error is ApiException) {
|
||||
switch (error.type) {
|
||||
case ApiErrorType.unauthorized:
|
||||
return 'Din session har gatt ut. Logga in igen.';
|
||||
return l10n.sessionExpiredError;
|
||||
case ApiErrorType.forbidden:
|
||||
return 'Du saknar behorighet for denna funktion.';
|
||||
return l10n.forbiddenError;
|
||||
case ApiErrorType.server:
|
||||
return 'Serverfel uppstod. Forsok igen om en stund.';
|
||||
return l10n.serverError;
|
||||
case ApiErrorType.network:
|
||||
return 'Natverksfel. Kontrollera anslutningen och forsok igen.';
|
||||
return l10n.networkError;
|
||||
case ApiErrorType.unknown:
|
||||
return error.message.isNotEmpty
|
||||
? error.message
|
||||
: 'Ett ovantat fel uppstod.';
|
||||
return error.message.isNotEmpty ? error.message : l10n.unexpectedError;
|
||||
}
|
||||
}
|
||||
return 'Ett ovantat fel uppstod.';
|
||||
return l10n.unexpectedError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user