Auto Translate Plugin

pub package license

A powerful, seamless, and privacy-first Flutter plugin for on-device text translation using Google ML Kit. Translate your app's content dynamically without requiring an active internet connection (once language models are downloaded).

🚀 Features

  • 🌍 On-Device Translation: Powered by Google ML Kit for offline processing and user privacy.
  • Seamless Integration: Replace standard Text widgets with AutoTranslateText effortlessly.
  • 🔄 Reactive State Management: Built-in TranslatorProvider (using provider) automatically updates all text widgets when the language changes.
  • 📦 Smart Model Management: Automatically handles initialization and cleanup of translation models.
  • 🛠️ Customizable: Full support for text styling, alignment, and standard Text widget properties.

📦 Getting Started

1. Add dependency

Add auto_translate_plugin and provider to your pubspec.yaml:

dependencies:
  auto_translate_plugin: ^1.0.1
  provider: ^6.1.5

2. Platform Setup

Android

The plugin requires internet access only for downloading the language models initially. Ensure you have the following in your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

iOS

ML Kit requires a minimum deployment target of 15.5 or higher. Update your Podfile:

platform :ios, '15.5'

🛠️ Usage

1. Initialize the Provider

Wrap your application with ChangeNotifierProvider to enable global language management.

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:auto_translate_plugin/auto_translate_plugin.dart';

void main() {
  runApp(
    ChangeNotifierProvider(
      create: (_) => TranslatorProvider(),
      child: const MyApp(),
    ),
  );
}

2. Use AutoTranslateText

Simply replace your Text widgets with AutoTranslateText. It will listen to the TranslatorProvider and update automatically.

AutoTranslateText(
  'Hello, welcome to our world-class application!',
  style: TextStyle(fontSize: 18, fontWeight: FontWeight.normal),
  textAlign: TextAlign.center,
)

3. Change Language Dynamically

Switch the entire app's language from anywhere in your code using the TranslatorProvider.

// Switch to Tamil
context.read<TranslatorProvider>().changeLanguage('ta');

// Switch to Hindi
context.read<TranslatorProvider>().changeLanguage('hi');

// Switch back to English
context.read<TranslatorProvider>().changeLanguage('en');

🌐 Supported Languages

Currently, this plugin specifically maps and supports:

  • 🇮🇳 Tamil (ta)
  • 🇮🇳 Hindi (hi)
  • 🇮🇳 Telugu (te)
  • 🇮🇳 Malayalam (ml)
  • 🇺🇸 English (en - default)

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Libraries

auto_translate_plugin
A Flutter plugin for seamless on-device text translation using Google ML Kit.