google_translation 1.0.0
google_translation: ^1.0.0 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");
copied to clipboard
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
copied to clipboard
Language 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 languages: $listDetectLanguages"); // output value
copied to clipboard
Get Language Supported
There are two methods support
- Get Supported language at default
final supportLanguages = await googleTranslation.getListSupportLanguages(
googleAPIKey: "YOUR_GOOGLE_API_KEY", // optional. If already setup above then doesn't need
);
print("List support languages: $supportLanguages"); // output value
copied to clipboard
- Get Supported language 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 languages: $supportLanguages"); // output value
copied to clipboard