custom_google_translate 1.0.3 copy "custom_google_translate: ^1.0.3" to clipboard
custom_google_translate: ^1.0.3 copied to clipboard

A customizable widget package for Google Translate support in Flutter.

custom_google_translate #

A customizable Flutter package to easily translate your app's text widgets using Google Translate API. Supports global language switching and a reusable TranslateText widget to simplify translations.


โœจ Features #

  • ๐ŸŒ Translate any text into 100+ languages using Google Translate API.
  • ๐Ÿง  Cache and manage a global target language without having to pass it every time.
  • ๐Ÿงฑ TranslateText widget works just like Flutter's Text widget.
  • ๐ŸŽฏ Option to dynamically change language at runtime.
  • ๐Ÿ“ฆ Easy integration into any Flutter project.

๐Ÿ“ฆ Installation #

Add this to your pubspec.yaml:

dependencies:
  custom_google_translate: ^1.0.0

Then run:

flutter pub get

๐Ÿงช Usage #

1. Wrap Your App With TranslationControllerProvider #

void main() {
  runApp(
    TranslationControllerProvider(
      child: MyApp(),
    ),
  );
}

2. Use the TranslateText Widget #

TranslateText(
  'Hola mundo',
  style: TextStyle(fontSize: 24),
)

By default, the target language is English. To change it:

TranslationController.instance.setLanguage('hi'); // Set to Hindi

๐ŸŒ Supported Languages #

All Google Translate-supported languages are available, including:

  • English (en)
  • Hindi (hi)
  • Spanish (es)
  • French (fr)
  • German (de)
  • Japanese (ja)
  • Chinese (zh)
  • Arabic (ar)
  • Russian (ru)
  • And many more...

You can use the _languages map provided in the example to populate dropdowns.


๐Ÿ“‚ Example #

import 'package:flutter/material.dart';
import 'package:custom_google_translate/custom_google_translate.dart';

void main() {
  runApp(TranslationControllerProvider(child: MyApp()));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Translation Demo',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('TranslateText Widget Example'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            DropdownButton<String>(
              value: TranslationController.instance.currentLanguage,
              items: _languages.entries.map((entry) {
                return DropdownMenuItem<String>(
                  value: entry.key,
                  child: Text(entry.value),
                );
              }).toList(),
              onChanged: (value) {
                if (value != null) {
                  TranslationController.instance.setLanguage(value);
                }
              },
            ),
            const SizedBox(height: 20),
            const TranslateText(
              "Hola mundo",
              style: TextStyle(fontSize: 24),
            ),
          ],
        ),
      ),
    );
  }
}

โš ๏ธ Important Notes #

  • This package uses the unofficial free Google Translate API (via translate.googleapis.com). For production apps, consider using an authenticated or official service to ensure long-term reliability.
  • Internet access is required for translation.

๐Ÿ“„ License #

MIT License


๐Ÿ’ฌ Contributing #

Feel free to open issues or pull requests on GitHub.

1
likes
140
points
278
downloads

Publisher

unverified uploader

Weekly Downloads

A customizable widget package for Google Translate support in Flutter.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http

More

Packages that depend on custom_google_translate