google_translation 0.1.5
google_translation: ^0.1.5 copied to clipboard
Package to provide support for google translator API in Dart works for multiplatform
Google translation #
Google Translation for using Google API key easily.
First announcement #
Google Translation package currently only support for basic addition of Google Translation API.
Advanced addition will be supported later.
Learn more about Google Translation and the different between basic and advanced addition here.
Get started #
Setup API Key #
When using Google Translation API, you need to setup Google Translation API key.
Install #
Add google_translation to your pubspec dependencies.
Usage #
Configuration
Setup Google Translation API for once.
final googleTranslation = GoogleTranslation();
googleTranslation.setupAPIKey("YOUR_GOOGLE_API_KEY");
Google Translation API can update or overwrite when call function anytime.
Simple Translation
For translate text
final result = await googleTranslation.simpleTextTranslate(
inputText: "TEXT_NEED_TRANSLATE",
sourceLanguage: "en", // optional
targetLanguage: "vi",
googleAPIKey: "YOUR_GOOGLE_API_KEY", // optional. If already setup above then doesn't need
);
print("Result: $result"); // output value
Langauge Detection
For language detection, get list detect languages
final listDetectLanguages = await googleTranslation.simpleTextDetectLanguages(
inputText: "TEXT_NEED_TO_DETECT_LANGUAGE",
googleAPIKey: "YOUR_GOOGLE_API_KEY", // optional. If already setup above then doesn't need
);
print("List detect langauges: $listDetectLanguages"); // output value
Get Langauge Supported
There are two methods support
- Get Supported langauge at default
final supportLanguages = await googleTranslation.getListSupportLanguages(
googleAPIKey: "YOUR_GOOGLE_API_KEY", // optional. If already setup above then doesn't need
);
print("List support langauges: $supportLanguages"); // output value
- Get Supported langauge at specific target localization
final supportLanguages = await googleTranslation.getListSupportLanguages(
targetLanguage: "en", // Define this
googleAPIKey: "YOUR_GOOGLE_API_KEY", // optional. If already setup above then doesn't need
);
print("List support langauges: $supportLanguages"); // output value