translate 1.0.0

translate #

A simple to use Dart package, for detecting & translating text and html pages using Yandex.Translate API

Show some ❤️, by putting ⭐

what does it do ? #

  • Fetches list of languages along with language codes, supported by Yandex.Translate API
  • Detects which language given text belongs to
  • Translates text or html page to certain language, denoted by language code

How to use ? #

First get yourself a Yandex.Translate API Key, which can be found here.

Languages('api_key')
      .fetch()
      .then(
        (data) => print(data),
        onError: (e) => print(e),
      ).then((val) => exit(0));

supported_languages

Response in case of success,

{
    ru: 'Russian',
    en: 'English',
}

Response in case of error,

{
    error: ' ... '
}

DetectIt('api_key')
      .detect('Hello World', hint: [
        'en',
        'de',
        'ru',
        'hi',
      ]) // hints are to be prioritized by platform while detecting language, if provided
      .then(
        (data) => print(data),
        onError: (e) => print(e),
      )
      .then((val) => exit(0));

detect_language

Response in case of success,

{
    lang: 'en'
}

Response in case of error,

{
    error: ' ... '
}

TranslateIt('api_key')
      .translate(
          '<!DOCTYPE html><html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>',
          'en-ru', // only `ru` will also do same job
          type: 'html') // type is `html`, cause this text is markedup
      .then(
        (data) => print(data),
        onError: (e) => print(e),
      )
      .then((val) => exit(0));

English | Russian --------|--------- html_page_in_english|html_page_in_russian

Response in case of success,

{
    text: ' ... '
}

Response in case of error,

{
    error: ' ... '
}

Courtesy : #

Translation API is powered by Yandex.Translate, so all thanks goes to them.

If you're interested in learning more about T&C, take a look here.

You can also go for priced version.

Hoping, it was helpful 😉

1.0.0 #

what's new ? #

  • Fetches list of languages along with language codes, supported by Yandex.Translate API
  • Detects which language given text belongs to
  • Translates text or html page to certain language, denoted by language code or conversion direction

example/example.dart

import 'dart:io';

import 'package:translate/translate.dart';

main() {
  /*
  Languages('api_key')
      .fetch()
      .then(
        (data) => print(data),
        onError: (e) => print(e),
      ).then((val) => exit(0));
  */
  /*
  DetectIt('api_key')
      .detect('Hello World', hint: [
        'en',
        'de',
        'ru',
        'hi',
      ]) // hints are to be prioritized by platform while detecting language, if provided
      .then(
        (data) => print(data),
        onError: (e) => print(e),
      )
      .then((val) => exit(0));
  */
  TranslateIt('api_key')
      .translate(
          '<!DOCTYPE html><html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>',
          'ru',
          type: 'html')
      .then(
        (data) => print(data),
        onError: (e) => print(e),
      )
      .then((val) => exit(0));
}

Use this package as a library

1. Depend on it

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


dependencies:
  translate: ^1.0.0

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:translate/translate.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
20
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Jul 10, 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, other

Primary library: package:translate/translate.dart with components: io.

Health suggestions

Fix lib/src/translate_it.dart. (-2.48 points)

Analysis of lib/src/translate_it.dart reported 5 hints:

line 16 col 16: Use = to separate a named parameter from its default value.

line 17 col 14: Use = to separate a named parameter from its default value.

line 54 col 16: Use = to separate a named parameter from its default value.

line 58 col 7: DO use curly braces for all flow control structures.

line 62 col 7: DO use curly braces for all flow control structures.

Fix lib/src/detect_it.dart. (-1.99 points)

Analysis of lib/src/detect_it.dart reported 4 hints:

line 16 col 16: Use = to separate a named parameter from its default value.

line 17 col 14: Use = to separate a named parameter from its default value.

line 43 col 7: DO use curly braces for all flow control structures.

line 47 col 7: DO use curly braces for all flow control structures.

Fix lib/src/languages.dart. (-1.49 points)

Analysis of lib/src/languages.dart reported 3 hints:

line 15 col 16: Use = to separate a named parameter from its default value.

line 16 col 14: Use = to separate a named parameter from its default value.

line 17 col 18: Use = to separate a named parameter from its default value.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0

Admin