supabase_error_translator_flutter 1.0.2
supabase_error_translator_flutter: ^1.0.2 copied to clipboard
Translate Supabase error codes into user-friendly messages in 9 languages. Perfect for international Flutter apps with automatic language detection and robust fallback system.
<<<<<<< HEAD
Supabase Error Translator Flutter #
π Make your Flutter app globally accessible! Translate Supabase error messages into 9 languages with zero configuration. Perfect for international apps that need user-friendly error messages.
β¨ Why Use This Package? #
- π Instant Setup: Works out of the box with any Flutter app
- π 9 Languages: English, Spanish, French, German, Italian, Portuguese, Dutch, Polish, Russian
- π― Complete Coverage: All Supabase services (Auth, Database, Storage, Realtime, Functions)
- οΏ½ Smart Detection: Automatically detects user's device language
- π Never Fails: Robust fallback system ensures users always get meaningful messages
- π§ͺ Battle Tested: 100% test coverage with 31 comprehensive tests
- π Well Documented: Clear examples and API documentation
π Quick Start #
Add to your pubspec.yaml
:
dependencies:
supabase_error_translator_flutter: ^1.0.0
Use in your app:
import 'package:supabase_error_translator_flutter/supabase_error_translator_flutter.dart';
// Set language once (auto-detects device language by default)
SupabaseErrorTranslator.setLanguage(SupportedLanguage.spanish);
// Translate any Supabase error
String friendlyMessage = SupabaseErrorTranslator.translate(
'invalid_credentials',
ErrorService.auth,
);
// Returns: "Credenciales invΓ‘lidas" (in Spanish)
π Supported Languages #
Language | Code | Native Name | Status |
---|---|---|---|
English | en |
English | β Complete |
Spanish | es |
EspaΓ±ol | β Complete |
French | fr |
FranΓ§ais | β Complete |
German | de |
Deutsch | β Complete |
Italian | it |
Italiano | β Complete |
Portuguese | pt |
PortuguΓͺs | β Complete |
Dutch | nl |
Nederlands | β Complete |
Polish | pl |
Polski | β Complete |
Russian | ru |
Π ΡΡΡΠΊΠΈΠΉ | β Complete |
π― Supabase Service Coverage #
π Authentication (ErrorService.auth
) #
- Login/signup errors (
invalid_credentials
,email_not_confirmed
) - User management (
user_not_found
,email_exists
) - Password policies (
password_too_weak
,password_too_short
) - Rate limiting (
too_many_requests
,email_rate_limit_exceeded
) - MFA and security (
mfa_challenge_expired
,invalid_otp_token
)
ποΈ Database (ErrorService.database
) #
- Connection issues (
connection_error
,server_disconnected
) - Query problems (
query_failed
,table_not_found
) - Constraint violations (
unique_constraint_violation
,foreign_key_violation
) - Permission errors (
access_denied
,invalid_authorization
)
π Storage (ErrorService.storage
) #
- File operations (
file_not_found
,upload_failed
) - Bucket management (
bucket_not_found
,bucket_already_exists
) - Authorization (
access_denied
,invalid_token
) - Size limits (
file_size_exceeded
,storage_quota_exceeded
)
π Realtime (ErrorService.realtime
) #
- Connection issues (
connection_failed
,websocket_error
) - Subscription errors (
subscription_error
,channel_error
) - Rate limiting (
connection_limit_exceeded
,channel_limit_exceeded
)
β‘ Functions (ErrorService.functions
) #
- Execution errors (
function_not_found
,execution_error
) - Timeout issues (
timeout_error
,memory_limit_exceeded
) - Network problems (
network_error
,internal_error
)
π‘ Usage Examples #
π¨ Basic Translation #
import 'package:supabase_error_translator_flutter/supabase_error_translator_flutter.dart';
// Set language once in your app
SupabaseErrorTranslator.setLanguage(SupportedLanguage.french);
// Translate any error
String message = SupabaseErrorTranslator.translate(
'email_not_confirmed',
ErrorService.auth,
);
print(message); // "Adresse e-mail non confirmΓ©e"
π€ Auto-Detection #
// Enable auto-detection to use device language
SupabaseErrorTranslator.setAutoDetection(true);
// Or use 'auto' for specific translations
String message = SupabaseErrorTranslator.translate(
'invalid_credentials',
ErrorService.auth,
language: 'auto', // Uses device language
);
π― Real-World Integration #
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:supabase_error_translator_flutter/supabase_error_translator_flutter.dart';
class AuthService {
Future<String?> signIn(String email, String password) async {
try {
final response = await Supabase.instance.client.auth.signInWithPassword(
email: email,
password: password,
);
if (response.user != null) {
return null; // Success
}
return SupabaseErrorTranslator.translate(
'unknown_error',
ErrorService.auth,
);
} on AuthException catch (error) {
// Automatically translate Supabase errors
return SupabaseErrorTranslator.translate(
error.code,
ErrorService.auth,
);
} catch (error) {
// Handle any other errors
return SupabaseErrorTranslator.translate(
'unknown_error',
ErrorService.auth,
);
}
}
}
πΌοΈ Flutter Widget Example #
import 'package:flutter/material.dart';
import 'package:supabase_error_translator_flutter/supabase_error_translator_flutter.dart';
class ErrorDisplay extends StatelessWidget {
final String? errorCode;
final ErrorService service;
const ErrorDisplay({
Key? key,
this.errorCode,
required this.service,
}) : super(key: key);
@override
Widget build(BuildContext context) {
if (errorCode == null) return SizedBox.shrink();
final message = SupabaseErrorTranslator.translate(errorCode!, service);
return Container(
padding: EdgeInsets.all(12),
margin: EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Colors.red.shade100,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.red.shade300),
),
child: Row(
children: [
Icon(Icons.error, color: Colors.red.shade700),
SizedBox(width: 12),
Expanded(
child: Text(
message,
style: TextStyle(
color: Colors.red.shade700,
fontWeight: FontWeight.w500,
),
),
),
],
),
);
}
}
π§ Advanced Features #
π Language Override #
// Translate to specific language without changing global setting
String spanishMessage = SupabaseErrorTranslator.translate(
'user_not_found',
ErrorService.auth,
language: SupportedLanguage.spanish,
);
// Use string codes too
String frenchMessage = SupabaseErrorTranslator.translate(
'connection_error',
ErrorService.database,
language: 'fr',
);
π Rich Translation Results #
// Get detailed translation information
TranslationResult result = SupabaseErrorTranslator.translateErrorCode(
'invalid_credentials',
ErrorService.auth,
);
print(result.message); // "Invalid credentials"
print(result.language); // SupportedLanguage.english
print(result.originalCode); // "invalid_credentials"
print(result.isFallback); // false
π Language Management #
// Check supported languages
List<String> languages = SupabaseErrorTranslator.getSupportedLanguages();
print(languages); // ['en', 'es', 'fr', 'de', 'it', 'pt', 'nl', 'pl', 'ru']
// Check if language is supported
bool isSupported = SupabaseErrorTranslator.isLanguageSupported('es');
print(isSupported); // true
// Get current language
SupportedLanguage current = SupabaseErrorTranslator.getCurrentLanguage();
print(current); // SupportedLanguage.english
π‘οΈ Bulletproof Error Handling #
The package uses a 4-step fallback system to ensure users always get meaningful messages:
- π― Service-specific translation in user's language
- π Service-specific English if translation missing
- π Generic message in user's language
- π Generic English as final fallback
// Even with unknown error codes, users get helpful messages
String message = SupabaseErrorTranslator.translate(
'some_unknown_error_code',
ErrorService.auth,
);
// Returns: "An unknown error occurred" (or in user's language)
π Complete API Reference #
SupabaseErrorTranslator
(Main Class) #
Core Methods
translate(String? errorCode, ErrorService service, {dynamic language})
βString
translateErrorCode(String? errorCode, ErrorService service, {dynamic language})
βTranslationResult
Language Management
setLanguage(dynamic language, {bool autoDetect = false})
βvoid
getCurrentLanguage()
βSupportedLanguage
getSupportedLanguages()
βList<String>
isLanguageSupported(String languageCode)
βbool
setAutoDetection(bool enabled)
βvoid
Utilities
getTranslatorInfo()
βMap<String, dynamic>
SupportedLanguage
(Enum) #
enum SupportedLanguage {
english, spanish, french, german, italian,
portuguese, dutch, polish, russian
}
Extensions:
languageCode
βString
(e.g., 'en', 'es')displayName
βString
(e.g., 'English', 'EspaΓ±ol')fromCode(String code)
βSupportedLanguage?
allCodes
βList<String>
ErrorService
(Enum) #
enum ErrorService {
auth, database, storage, realtime, functions
}
TranslationResult
(Class) #
class TranslationResult {
final String message; // Translated message
final SupportedLanguage language; // Language used
final String originalCode; // Original error code
final bool isFallback; // Whether fallback was used
}
π§ͺ Testing & Quality #
The package includes 31 comprehensive tests covering:
- β Language Management: Setting, getting, and validating languages
- β Translation Accuracy: Correct translations for all error codes
- β Fallback System: Robust error handling with 4-step fallbacks
- β Auto-Detection: Device language detection functionality
- β Service Coverage: All Supabase services and error types
- β Edge Cases: Null values, empty strings, unknown codes
- β Model Validation: Data structures and enums
- β Exception Handling: Proper error propagation
Run tests:
flutter test
π¦ Installation #
Add to your pubspec.yaml
:
dependencies:
supabase_error_translator_flutter: ^1.0.0
Then run:
flutter pub get
π€ Contributing #
We welcome contributions! Here's how you can help:
π Adding New Languages #
- Add the language to
SupportedLanguage
enum - Add translations to
TranslationData
class - Update extension methods for language codes
- Add comprehensive tests
- Update documentation
π§ Adding New Error Codes #
- Add error code to appropriate service section
- Provide translations for all 9 languages
- Add test cases for the new error code
- Update documentation
π Reporting Issues #
Please use the GitHub issue tracker to report bugs or request features.
π License #
This project is licensed under the MIT License - see the LICENSE file for details.
β οΈ Disclaimer #
This is an independent project and is NOT officially associated with Supabase. It's created by the community for the community.
π Roadmap #
- β Add more languages (Japanese, Korean, Chinese)
- β Support for custom error codes
- β Integration with Flutter's
Localizations
- β Contextual error messages
- β Error analytics and reporting
- β VS Code extension for managing translations
π Support #
- π Documentation: Check the API reference above
- π¬ Issues: GitHub Issues
- π§ Email: contact@mrehman.co.uk
- π» Examples: Check the
/example
folder
π Acknowledgments #
- Thanks to the Flutter and Supabase communities
- All contributors who helped with translations
- Beta testers who provided feedback
Made with β€οΈ for the Flutter community
Give us a β if this package helped you build better apps!