json_intl_gen 3.0.0 copy "json_intl_gen: ^3.0.0" to clipboard
json_intl_gen: ^3.0.0 copied to clipboard

Flutter Internationalization library based on Json files and mustache replacement strings. Code generator library.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:json_intl/json_intl.dart';

import 'intl.dart';

// ignore_for_file: public_member_api_docs

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // This replaces your [title] attribute, as we need a context to get the
      // translations
      onGenerateTitle: (BuildContext context) =>
          JsonIntl.of(context).get(IntlKeys.appName),
      home: const MyHomePage(),
      localizationsDelegates: const [
        jsonIntlDelegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: supportedLocalesIntlKeys,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  MyHomePageState createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // A simple translated title
        title: Text(JsonIntl.of(context).get(IntlKeys.title)),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            // A string translated depending on a number to count something
            Text(JsonIntl.of(context).count(
              _counter,
              IntlKeys.pushed,
              strict: false,
            )),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        // We can use the BuildContext extension too:
        tooltip: context.tr(IntlKeys.increment),
        child: const Icon(Icons.add),
      ),
    );
  }
}
1
likes
160
points
49
downloads

Publisher

verified publishernfet.net

Weekly Downloads

Flutter Internationalization library based on Json files and mustache replacement strings. Code generator library.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

args, build, dart_style, glob, json_intl, logging, path, yaml

More

Packages that depend on json_intl_gen