flutter_auto_translate 1.0.3
flutter_auto_translate: ^1.0.3 copied to clipboard
Wrap any Text widget with AutoTranslate to add automatic translation with caching. Supports 85+ languages.
Flutter Auto Translate #
π― Wrap any Text widget to add automatic translation with smart caching!
Features #
β¨ Wrapper Widget - Wrap ANY existing Text widget
πΎ Smart Caching - Instant translation loading
π 85+ Languages - All major languages supported
π¨ Beautiful Language Selector - Pre-built UI with flags
β‘ Zero Refactoring - Works with your existing code
π§ Easy Setup - 2 minutes integration
Installation #
dependencies:
flutter_auto_translate: ^1.0.3
Quick Start #
1. Initialize #
import 'package:flutter_auto_translate/flutter_auto_translate.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await TranslationService().init();
runApp(MyApp());
}
2. Wrap Your Text #
// Before
Text('Hello, World!')
// After
AutoTranslate(
child: Text('Hello, World!'),
)
That's it! Your text now auto-translates! π
3. Add Language Selector #
IconButton(
icon: Icon(Icons.language),
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LanguageSelectionScreen(),
),
);
setState(() {}); // Rebuild to show new language
},
)
Examples #
Wrap Custom Text Widgets #
// Your existing custom widget
class CustomTextOne extends StatelessWidget {
final String text;
CustomTextOne({required this.text});
@override
Widget build(BuildContext context) {
return AutoTranslate( // β Just wrap it!
child: Text(
text,
style: TextStyle(fontSize: 20),
),
);
}
}
Disable Translation for Specific Text #
AutoTranslate(
enable: false, // β Disable translation
child: Text('API_KEY_12345'),
)
Override Language #
AutoTranslate(
languageCode: 'es', // β Force Spanish
child: Text('Hello'),
)
Supported Languages #
85+ languages including: English, Spanish, French, German, Chinese, Japanese, Korean, Arabic, Hindi, Bengali, Portuguese, Russian, Turkish, Italian, and many more!
API Reference #
AutoTranslate Widget #
| Property | Type | Default | Description |
|---|---|---|---|
| child | Widget | required | Text widget to translate |
| languageCode | String? | null | Override global language |
| enable | bool | true | Enable/disable translation |
| loadingWidget | Widget? | null | Custom loading indicator |
TranslationService #
// Initialize service
await TranslationService().init();
// Get current language
String lang = TranslationService().currentLanguage;
// Set language
await TranslationService().setLanguage('es');
// Clear cache
await TranslationService().clearCache();
// Clear cache for specific language
await TranslationService().clearCacheForLanguage('es');
How It Works #
- Wrap any Text widget with AutoTranslate
- Extract text automatically from child
- Translate using Google Translate API
- Cache locally for instant loading
- Display translated text with original styling
Benefits #
β
No Code Refactoring - Works with existing widgets
β
Type Safe - Full Dart type support
β
Performance - Cached translations load instantly
β
Flexible - Use globally or per-widget
β
Beautiful - Pre-built language selector UI
Example App #
Check out the example directory for a complete working app.
License #
MIT
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
Support #
If you find this package helpful, please give it a β on GitHub! EOF