translator 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 94

translator #

Free Google Translate API for Dart

See it in pub:
and GitHub:

Usage #

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

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

  translator.translate(input, from: 'ru', to: 'en').then((s) {
  // prints Hello. Are you okay?
  var translation = await translator.translate("Dart is very cool!", to: 'pl');
  // 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) {
  // 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');
// 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 这意味着用中文'测试'



For full API docs take a look at

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.


import 'package:translator/translator.dart';

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

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

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

  // for countries that default base URL doesn't work
  translator.baseUrl = "";
  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:

  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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21


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.


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.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.8.0+1
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test any