google_translator

Last updated:

0 purchases

google_translator Image
google_translator Images
Add to Cart

Description:

google translator

google_translator #

A flutter plugin for adapting screen and font size.Let your UI display a reasonable layout on different screen sizes!
Usage: #
Get the Google Translation Api key: #


First you will need to start a project in Google Cloud Platform


Then Enable Google Cloud Translation API



Create a credentials key for your account..
Navigate to the API Manager section of your project dashboard,

In the drop down menu, select API key:



Add dependency: #
Please check the latest version before installation.
If there is any problem with the new version, please use the previous version
dependencies:
# Functionalities
google_translator: ^{latest version}
..
flutter:
sdk: flutter
copied to clipboard
Add the following imports to your Dart code: #
import 'package:google_translator/google_translator.dart';
copied to clipboard
Getting Started #
First, you will need to send the API Key, allong with a few default parameters described bellow, before the calling of the translate function (we recomend to do as in the example):
void main() {
/// Required to make the `GoogleTranslatorInit` call before the `MaterialApp`
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}

class MyApp extends StatelessWidget {

final String apiKey = "YOUR_GCP_API_KEY";

@override
Widget build(BuildContext context) {
return GoogleTranslatorInit(apiKey,
translateFrom: Locale('pt-br'),
translateTo: Locale('en'),
// automaticDetection: , In case you don't know the user language will want to traslate,
// cacheDuration: Duration(days: 13), The duration of the cache translation.
builder: () => MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Página inicial de demonstração do Flutter'),
),
);
}
}
copied to clipboard
Note: If will want to make the call before the MaterialApp, will have to add the WidgetsFlutterBinding.ensureInitialized(); before the runApp function.

Basic Usage #
Now, all you'll have to make is add the .translate() to all the Text you want to translate.
Scaffold(
appBar: AppBar(
title: Text(widget.title ?? "").translate(),
),
body: Column(
children: [
Text("Meu texto traduzido").translate(),
Text("Este texto mostra um placeholder diferente").translate("Place to Holder")
]
),
);
copied to clipboard
Todo: #

❌ Add extension to RichText;
❌ Add extension to CupertinoTextField;
❌ Add extension to CupertinoSearchTextField;
❌ Add extension to CupertinoSearchTextField;
❌ Add extension to TextField;
❌ Add extension to Tooltip;
✅ Add extension to SelectableText.
❌ Migrate dio_http_cache dependency to a safer one (expecting creators to add null-safety on https://pub.dev/)

Disclaimer #
This package works with cache data dio_http_cache, that, by default last's 7 days, but can be change in the GoogleTranslatorInit > cacheDuration parameter.
Issues #
Please if you see any issues, bugs, or feature requests, send to me in: GitHub issue.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.