aws_translate 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

aws_translate #

AWS Translate plugin to translate a text / paragraph with translating status.

DISCLAIMER: This is not an AWS officially released plugin but this plugin uses AWS official Android native and IOS native AWS plugins (So nothing to be worried). Check the package implementation on github: https://github.com/Blasanka/aws_translate_plugin

All the support translate languages by AWS official Android and IOS libraries are supported in this plugin also with auto.

Available languages:

Please refer this for support languages and their codes: https://docs.aws.amazon.com/translate/latest/dg/translate-dg.pdf

Example:

AwsTranslate awsTranslate = AwsTranslate(
    poolId: poolId, // your pool id here
    region: Regions.AP_NORTHEAST_2); // your region here

// from parameter is default to ``auto``
String textToTranslate = 'If you press on this text, I can translate this text for you.';
String translated = await awsTranslate.translateText(textToTranslate, to: 'es');
if (!mounted) return;
print(textToTranslate);
setState(() => textToTranslate = translated);

A complete example can be found in the example directory.

All available regions for Android are support for this Flutter plugin.

/// Enumeration of region names
enum Regions {
  GovCloud,
  US_GOV_EAST_1,
  US_EAST_1,
  US_EAST_2,
  US_WEST_1,
  US_WEST_2, ///Default: The default region of AWS Android SDK
  EU_WEST_1,
  EU_WEST_2,
  EU_WEST_3,
  EU_CENTRAL_1,
  EU_NORTH_1,
  AP_EAST_1,
  AP_SOUTH_1,
  AP_SOUTHEAST_1,
  AP_SOUTHEAST_2,
  AP_NORTHEAST_1,
  AP_NORTHEAST_2,
  SA_EAST_1,
  CA_CENTRAL_1,
  CN_NORTH_1,
  CN_NORTHWEST_1,
  ME_SOUTH_1
}

For to show something while translate, use getTranslateStatus and below are supported translate types:

enum TranslateStatus {
  NONE,
  ERROR,
  TRANSLATING,
  COMPLETED
}

Contributes and issues are welcome!

0.1.1 #

  • IOS support for text / paragraph translate.

0.1.0 #

  • Android support for text / paragraph translate.
  • Translate status using an enum TranslateStatus.

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:flutter/services.dart';
import 'package:aws_translate/aws_translate.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String poolId;
  String textToTranslate = 'If you press on this text, I can translate this text for you.';
  AwsTranslate awsTranslate;

  bool isToggle = false;

  @override
  void initState() {
    super.initState();
    awsTranslate = AwsTranslate();
    readEnv();
  }

  void readEnv() async {
    final str = await rootBundle.loadString(".env");
    if (str.isNotEmpty) {
      final decoded = jsonDecode(str);
      poolId = decoded["poolId"];
    }
    awsTranslate = AwsTranslate(
        poolId: poolId,
        region: Regions.US_WEST_2);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: StreamBuilder(
            stream: awsTranslate.getTranslateStatus,
            builder: (context, snapshot) {
              if (snapshot == null || snapshot.hasError) return Text("error");
              return InkWell(
                onTap: tapToTranslate,
                child: snapshot.data == TranslateStatus.TRANSLATING
                    ? CupertinoActivityIndicator()
                    : Padding(padding: EdgeInsets.all(10), child: Text(textToTranslate)),
              );
            }
          ),
        ),
      ),
    );
  }


//   with from and to optional params
//   onTap: () async => await AwsTranslate.translateText(textToTranslate, from: 'en', to: 'hi'),
  void tapToTranslate() async {

    // if you need to change the translating language when tap once use below
    // or just use your lang translate code directly to translateText function
    String translateTo = toggleTranslatingLangWhenOnTap();

    String translated = await awsTranslate.translateText(textToTranslate, to: translateTo);
    if (!mounted) return;
    print(textToTranslate);
    setState(() => textToTranslate = translated);
  }

  String toggleTranslatingLangWhenOnTap() {
    String translateTo = "es";
    if (isToggle) translateTo = "en";
    isToggle = !isToggle;
    return translateTo;
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  aws_translate: ^0.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:aws_translate/aws_translate.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
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]
77
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:aws_translate/aws_translate.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:aws_translate/aws_translate.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:aws_translate/aws_translate.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:aws_translate/aws_translate.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [aws_translate] that is in a package requiring null.

Health suggestions

Format lib/aws_translate.dart.

Run flutter format to format lib/aws_translate.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test