Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabrielpacheco23/google-translator
Free Google Translator for Dart
https://github.com/gabrielpacheco23/google-translator
dart dart-library dartlang google translate
Last synced: 29 days ago
JSON representation
Free Google Translator for Dart
- Host: GitHub
- URL: https://github.com/gabrielpacheco23/google-translator
- Owner: gabrielpacheco23
- License: mit
- Created: 2018-09-22T20:10:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-20T03:00:59.000Z (5 months ago)
- Last Synced: 2024-09-29T16:04:05.825Z (about 1 month ago)
- Topics: dart, dart-library, dartlang, google, translate
- Language: Dart
- Homepage: https://pub.dartlang.org/packages/translator
- Size: 61.5 KB
- Stars: 170
- Watchers: 4
- Forks: 90
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# translator
Free Google Translate API for DartSee it in pub: https://pub.dev/packages/translator \
and GitHub: https://github.com/gabrielpacheco23/google-translator[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Q5Q04C63Q)
# Usage
```dart
void main() async {
final translator = GoogleTranslator();final input = "Здравствуйте. Ты в порядке?";
translator.translate(input, from: 'ru', to: 'en').then(print);
// prints Hello. Are you okay?
var translation = await translator.translate("Dart is very cool!", to: 'pl');
print(translation);
// prints Dart jest bardzo fajny!print(await "example".translate(to: 'pt'));
// prints exemplo
}
```
Using **translate** method passing the args **from** and **to** designates the
language from text you're typing and the language to be translated
``` dart
translator.translate("I love Brazil!", from: 'en', to: 'pt').then((s) {
print(s);
});
// prints Eu amo o Brasil!
```
or you can omit from language and it'll auto-detect the language of source text
```dart
translator.translate("Hello", to: 'es').then(print);
// prints Hola
```
and also pass the value to a var using ```await```
```dart
var translation = await translator.translate("I would buy a car, if I had money.", from: 'en', to: 'it');
print(translation);
// prints Vorrei comprare una macchina, se avessi i soldi.
```
The returned value is a ```Translation``` object which holds the translation stuff
```dart
var translation = await translator.translate('Translation', from: 'en', to: 'es');
print('${translation.source} (${translation.sourceLanguage}) == ${translation.text} (${translation.targetLanguage})');// prints Translation (English) == Traducción (Spanish)
```
You can use the ***extension method*** directly on the string too
```dart
print(await "example".translate(to: 'pt'));
// prints exemplo
```
There is **translateAndPrint** method that prints directly
```dart
translator.translateAndPrint("This means 'testing' in chinese", to: 'zh-cn');
// prints 这意味着用中文'测试'
```
# API
For full API docs take a look at https://pub.dev/documentation/translator/latest/# Support my work :)
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Q5Q04C63Q)# License
MIT LicenseCopyright © 2021 Gabriel Pacheco
# Disclaimer
This package is developed for educational purposes only. Do not depend on this package as it may break anytime as it is based on crawling the Google Translate website. Consider buying Official Google Translate API for other types of usage.