auto_translate_plugin 1.0.1
auto_translate_plugin: ^1.0.1 copied to clipboard
A Flutter plugin that extends the standard Text widget to automatically translate text using Google ML Kit on-device translation.
Auto Translate Plugin #
A Flutter plugin for seamless on-device text translation using Google ML Kit. It provides easy-to-use widgets and state management to automatically translate text dynamically within your Flutter application without requiring an active internet connection (once the language models are downloaded).
Features #
- On-Device Translation: Uses Google ML Kit for privacy-first, offline translations.
- Easy Integration: Drop-in
AutoTranslateTextwidget that can replace your standardTextwidgets. - State Management Built-in: Uses a
ChangeNotifierto notify all text widgets instantly when the user switches their preferred language. - Automatic Model Management: Models for translation are smartly initialized and disposed of dynamically.
Getting started #
Include the plugin in your pubspec.yaml:
dependencies:
flutter:
sdk: flutter
auto_translate_plugin: ^1.0.0
provider: ^6.1.5
Usage #
- Wrap your app in the TranslatorProvider
import 'package:provider/provider.dart';
import 'package:auto_translate_plugin/auto_translate_plugin.dart';
void main() {
runApp(
ChangeNotifierProvider(
create: (_) => TranslatorProvider(),
child: const MyApp(),
),
);
}
- Use the
AutoTranslateTextwidget
AutoTranslateText(
'Welcome to my application!',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
)
- Change the language globally
// Switch the entire app's text from English to Hindi dynamically!
context.read<TranslatorProvider>().changeLanguage('hi');
Additional information #
Ensure you have updated your project dependencies like Google ML Kit and follow platform requirements defined by google_mlkit_translation. The supported list of target languages in the template maps specific codes like ta, hi, te, and ml.