translator 0.1.0+5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 83

translator

Free Google Translate API for Dart

See it in pub: https://pub.dartlang.org/packages/translator
and GitHub: https://github.com/gabrielpacheco23/google-translator

Usage

void main() async {
  GoogleTranslator translator = new GoogleTranslator();

  String input = "Здравствуйте. Ты в порядке?";

  translator.translate(input, from: 'ru', to: 'en').then((s) {
    print(s);
  });
  // prints Hello. Are you okay?
  
  var translation = await translator.translate("Dart is very cool!", to: 'pl');
  print(translation);
  // prints Dart jest bardzo fajny!
}

 

Using translate method passing the args from and to designates the language from text you're typing and the language to be translated

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 use auto key that auto-detect the language of source text

translator.translate("Hello", to: 'es').then((s) => print(s));
// prints Hola

 

and also pass the value to a var using await

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.

 

There is translateAndPrint method that prints directly

translator.translateAndPrint("This means 'testing' in chinese", to: 'zh-cn');
// prints 这意味着用中文'测试'

 

API

For full API docs take a look at https://pub.dartlang.org/documentation/translator/latest/

License

MIT License

Copyright © 2018 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.

Releases

0.1.0+5

  • Support http ^0.12.0

0.1.0+4

  • Support < 2.0.0
  • Wrapped files

0.1.0+3

  • Initial open source release.
  • Usage and example updated.

 

Pre-dev releases

0.0.12

  • README Updated.

0.0.11

  • README Updated.

0.0.10

  • README Updated.

example/main.dart

import 'package:translator/translator.dart';

void main() async {
  GoogleTranslator translator = GoogleTranslator();

  String input = "Здравствуйте. Ты в порядке?";

  translator.translate(input, to: 'en')
      .then((s) =>  print("Source: " + input + "\n"
      "Translated: " + s + "\n"));


  // for countries that default base URL doesn't work
  translator.baseUrl = "https://translate.google.cn/translate_a/single";
  translator.translateAndPrint("This means 'testing' in chinese", to: 'zh-cn');
  //prints 这意味着用中文'测试'


  var translation = await translator.translate("I would buy a car, if I had money.", from: 'en', to: 'it');
  print("translation: " + translation);
  // prints translation: Vorrei comprare una macchina, se avessi i soldi.
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  translator: ^0.1.0+5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:translator/translator.dart';
  
Version Uploaded Documentation Archive
0.1.0+5 Nov 11, 2018 Go to the documentation of translator 0.1.0+5 Download translator 0.1.0+5 archive
0.1.0+4 Oct 4, 2018 Go to the documentation of translator 0.1.0+4 Download translator 0.1.0+4 archive
0.1.0+3 Oct 4, 2018 Go to the documentation of translator 0.1.0+3 Download translator 0.1.0+3 archive
0.1.0+2 Sep 24, 2018 Go to the documentation of translator 0.1.0+2 Download translator 0.1.0+2 archive
0.1.0+1 Sep 24, 2018 Go to the documentation of translator 0.1.0+1 Download translator 0.1.0+1 archive
0.1.0 Sep 24, 2018 Go to the documentation of translator 0.1.0 Download translator 0.1.0 archive
0.0.12 Sep 23, 2018 Go to the documentation of translator 0.0.12 Download translator 0.0.12 archive
0.0.11 Sep 23, 2018 Go to the documentation of translator 0.0.11 Download translator 0.0.11 archive
0.0.10 Sep 23, 2018 Go to the documentation of translator 0.0.10 Download translator 0.0.10 archive
0.0.9 Sep 23, 2018 Go to the documentation of translator 0.0.9 Download translator 0.0.9 archive

All 18 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
67
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:translator/translator.dart.

Health suggestions

Format lib/translator.dart.

Run dartfmt to format lib/translator.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
http ^0.12.0 0.12.0
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.6
path 1.6.2
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
Dev dependencies
test any