custom_google_translate 1.0.3
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'sText
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.