Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahyangnb/flutter_google_translate
https://github.com/ahyangnb/flutter_google_translate
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/ahyangnb/flutter_google_translate
- Owner: ahyangnb
- License: mit
- Created: 2024-05-31T06:41:27.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-09-10T08:53:33.000Z (4 months ago)
- Last Synced: 2024-10-16T14:13:08.310Z (3 months ago)
- Language: Dart
- Size: 487 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_google_translate
A dart wrapper on the Google Could Translation API to be used in Flutter applications. As this is
using the http REST API it works both with Android and iOS.It can be cache the translate result and manage text translate status.
![](https://github.com/ahyangnb/flutter_google_translate/blob/main/example/assets/translate_screen.gif?raw=true)
## How to use it
There is an [example](./example) app that demonstrates how to use the plugin,
You just need to instantiate the class and you'll be ready to send `translate` texts.
NOTICE: This package uses in production, but only for the simple translation. If you need additional
API please create issue or make PR.```dart
class _MyHomePageState extends State {
late Translation _translation;
final String _text =
'Toda persona tiene derecho a la educación. La educación debe ser gratuita, al menos en lo concerniente a la instrucción elemental y fundamental. La instrucción elemental será obligatoria. La instrucción técnica y profesional habrá de ser generalizada; el acceso a los estudios superiores será igual para todos, en función de los méritos respectivos.';
TranslationModel _translated = TranslationModel(translatedText: '', detectedSourceLanguage: '');
TranslationModel _detected = TranslationModel(translatedText: '', detectedSourceLanguage: '');@override
void initState() {
_translation = Translation(
apiKey: 'YOUR_API_KEY',
);
super.initState();
}@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Translate demo'),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Initial text',
style: Theme
.of(context)
.textTheme
.headline3,
),
Text(_text),
SizedBox(height: 30),
Text('Translated text', style: Theme
.of(context)
.textTheme
.headline3),
Text(_translated.translatedText, style: TextStyle(color: Colors.blueAccent)),
Text('Detected language - ${_translated.detectedSourceLanguage}',
style: TextStyle(color: Colors.red)),
const SizedBox(height: 20),
Text('Language detected with detectLang, without translation - ${_detected
.detectedSourceLanguage}',
style: TextStyle(color: Colors.red)),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
_translated = await _translation.translate(text: _text, to: 'en');
_detected = await _translation.detectLang(text: _text);
setState(() {});
},
tooltip: 'Translate',
child: Icon(Icons.language),
),
);
}
}
```