simple_aws_translate 0.0.7
simple_aws_translate: ^0.0.7 copied to clipboard
A simple implementation of the AWS Translation plugin for testing purposes only. NOT for production use as it requires embedding AWS credentials. Developed by Afandi Yusuf.
simple_aws_translate #
A simple implementation of the AWS Translate plugin for Flutter. This plugin allows you to easily integrate AWS Translate services into your Flutter application.
DISCLAIMER: This is not the officially released AWS plugin.
⚠️ FOR TESTING PURPOSES ONLY ⚠️ #
DO NOT USE THIS PLUGIN IN PRODUCTION #
CRITICAL SECURITY WARNING: This plugin requires you to embed AWS credentials (access key and secret key) directly in your application, which means:
- YOUR AWS CREDENTIALS WILL BE EXPOSED in your application package
- Anyone with access to your application can potentially extract your AWS credentials
- This could lead to unauthorized use of your AWS services and SIGNIFICANT FINANCIAL COSTS
- Your AWS account could be compromised, leading to security breaches
This plugin is STRICTLY FOR TESTING AND DEVELOPMENT ENVIRONMENTS ONLY. For production applications, you should:
- Use a secure backend service to handle AWS API calls
- Implement proper authentication mechanisms
- Consider using AWS Cognito or other secure authentication services
- Never embed AWS credentials in client-side code
By using this plugin, you acknowledge that you understand these risks and that you will only use it for testing purposes.
Features #
- Simple API to translate text using AWS Translate
- Support for all AWS regions
- Improved error handling with detailed error messages
- Configurable source and target languages
Getting Started #
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
simple_aws_translate: ^0.0.7
Initialization #
To use this plugin, call the init function with your AWS credentials. You should initialize the plugin only once, typically at app startup.
// Initialize with default region (Singapore)
SimpleAwsTranslate.instance.init(
accessKey: "your_access_key", // Store securely, do not hardcode
secretKey: "your_secret_key" // Store securely, do not hardcode
);
// Or specify a custom region
SimpleAwsTranslate.instance.init(
accessKey: "your_access_key",
secretKey: "your_secret_key",
region: AwsRegion.usEast1 // Use US East (N. Virginia) region
);
Translating Text #
After initialization, you can use the translateText method to translate text:
try {
// Translate from auto-detected language to English
String result = await SimpleAwsTranslate.instance.translateText(
text: "Hallo bang!",
to: "en"
);
print("Translated result: $result");
// Or specify the source language
String result2 = await SimpleAwsTranslate.instance.translateText(
text: "Hallo bang!",
from: "id", // Indonesian
to: "en" // English
);
print("Translated result: $result2");
} on AwsTranslationException catch (e) {
print("Translation error: ${e.message}");
}
Available Regions #
The plugin supports all AWS regions. You can specify the region during initialization:
SimpleAwsTranslate.instance.init(
accessKey: "your_access_key",
secretKey: "your_secret_key",
region: AwsRegion.euWest1 // Europe (Ireland)
);
Available regions:
AwsRegion.apNortheast1- Asia Pacific (Tokyo)AwsRegion.apNortheast2- Asia Pacific (Seoul)AwsRegion.apSouth1- Asia Pacific (Mumbai)AwsRegion.apSoutheast1- Asia Pacific (Singapore) [Default]AwsRegion.apSoutheast2- Asia Pacific (Sydney)AwsRegion.caCentral1- Canada (Central)AwsRegion.euCentral1- Europe (Frankfurt)AwsRegion.euWest1- Europe (Ireland)AwsRegion.euWest2- Europe (London)AwsRegion.euWest3- Europe (Paris)AwsRegion.saEast1- South America (São Paulo)AwsRegion.usEast1- US East (N. Virginia)AwsRegion.usEast2- US East (Ohio)AwsRegion.usWest1- US West (N. California)AwsRegion.usWest2- US West (Oregon)
Error Handling #
The plugin provides detailed error information through the AwsTranslationException class:
try {
String result = await SimpleAwsTranslate.instance.translateText(
text: "Hello world",
to: "fr"
);
print("Translated result: $result");
} on AwsTranslationException catch (e) {
print("Error code: ${e.code}");
print("Error message: ${e.message}");
}
Testing and Development #
For testing and development purposes only, you can create temporary AWS credentials with limited permissions. See the AWS documentation for more information on creating temporary security credentials.
Complete Example #
A complete example can be found in the example directory.
License #
This plugin is available under the MIT License.
Contributions #
Contributions and bug reports are welcome! Please feel free to submit a pull request or open an issue on GitHub.