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

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(
    localeType: LocalizationDefaultType.device,
    languagesList: <String>['ar', 'en'],
    assetsDirectory: 'assets/lang/',
  );

  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('appTitle'.tr()),
      ),
      body: Container(
        width: double.infinity,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            SizedBox(height: 50),
            Text(
              'textArea'.tr(),
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 35),
            ),
            Wrap(
              children: translator.locals().map((i) {
                return OutlinedButton(
                  onPressed: () {
                    translator.setNewLanguage(
                      context,
                      newLanguage: i.languageCode,
                      remember: true,
                      restart: true,
                    );
                  },
                  child: Text(i.languageCode),
                );
              }).toList(),
            ),
          ],
        ),
      ),
    );
  }
}
132
likes
110
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

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, flutter_localizations, http, shared_preferences

More

Packages that depend on localize_and_translate