localize_and_translate 3.0.2 copy "localize_and_translate: ^3.0.2" to clipboard
localize_and_translate: ^3.0.2 copied to clipboard

outdated

Flutter localization in easy steps, simple ways to localize and translate your app

example/lib/main.dart

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

main() async {
  // if your flutter > 1.7.8 :  ensure flutter activated
  WidgetsFlutterBinding.ensureInitialized();

  await translator.init(
    localeDefault: LocalizationDefaultType.device,
    languagesList: <String>['ar', 'en'],
    assetsDirectory: 'assets/langs/',
    apiKeyGoogle: '<Key>', // NOT YET TESTED
  ); // intialize

  runApp(LocalizedApp(child: MyApp()));
}

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
      localizationsDelegates: translator.delegates,
      locale: translator.locale,
      supportedLocales: translator.locals(),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: Drawer(),
      appBar: AppBar(
        title: Text(translator.translate('appTitle')),
        // centerTitle: true,
      ),
      body: Container(
        width: double.infinity,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            SizedBox(height: 50),
            Text(
              translator.translate('textArea'),
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 35),
            ),
            OutlineButton(
              onPressed: () {
                translator.setNewLanguage(
                  context,
                  newLanguage: translator.currentLanguage == 'ar' ? 'en' : 'ar',
                  remember: true,
                  restart: true,
                );
              },
              child: Text(translator.translate('buttonTitle')),
            ),
            OutlineButton(
              onPressed: () async {
                print(await translator.translateWithGoogle(
                  key: 'رجل',
                  from: 'ar',
                ));
              },
              child: Text(translator.translate('googleTest')),
            ),
          ],
        ),
      ),
    );
  }
}
132
likes
0
pub points
94%
popularity

Publisher

verified publishermsayed.net

Flutter localization in easy steps, simple ways to localize and translate your app

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

devicelocale, flutter, flutter_localizations, http, intl, shared_preferences

More

Packages that depend on localize_and_translate