translator 0.1.2

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 {
  final translator = new GoogleTranslator();

  final 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 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 © 2019 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.2 #

  • Fixed bug with Google API changes

0.1.1 #

  • Fixed newline bug

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 {
  final translator = GoogleTranslator();

  final 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.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/src/google_translator.dart. (-0.50 points)

Analysis of lib/src/google_translator.dart reported 1 hint:

line 84 col 3: Avoid return types on setters.

Fix lib/src/tokens/google_token_gen.dart. (-0.50 points)

Analysis of lib/src/tokens/google_token_gen.dart reported 1 hint:

line 54 col 9: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
http ^0.12.0 0.12.0+2
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.7
path 1.6.2
pedantic 1.8.0+1
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test any

Admin