gen_i18n 1.0.1 copy "gen_i18n: ^1.0.1" to clipboard
gen_i18n: ^1.0.1 copied to clipboard

outdated

Library to help you add internationalization in your project dart generating classes and translation files.

example/lib/main.dart

import 'package:example/i18n/i18n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

Future<void> main() async {
  /// This is required
  WidgetsFlutterBinding.ensureInitialized();

  /// Initial Locate is critical to initializing the internationalization feature
  await I18n.initialize(
      defaultLocale: Locale('en'), /// This is required
      supportLocales: [Locale('en'), Locale('es')] /// This is optional
      );

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      locale: I18n.currentLocate,
      supportedLocales: I18n.supportedLocales,
      localizationsDelegates: const [
        const I18nDelegate(),
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'lib'.translate),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'customMessage'.translate,
            ),
          ],
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
4
likes
0
points
40
downloads

Publisher

verified publisheredvaldomartins.dev

Weekly Downloads

Library to help you add internationalization in your project dart generating classes and translation files.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

colorize, path

More

Packages that depend on gen_i18n