easy_json_translate 1.0.0 copy "easy_json_translate: ^1.0.0" to clipboard
easy_json_translate: ^1.0.0 copied to clipboard

A pure Flutter widget-based package dynamically bridging localized JSON files into the app without generating Dart boilerplate.

example/lib/main.dart

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize translations and locale
  await EasyJsonTranslate.init();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: EasyJsonTranslate(), // Listen for locale changes natively
      builder: (context, child) {
        return MaterialApp(
          title: 'Easy JSON Translate Example',
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            useMaterial3: true,
          ),
          locale: EasyJsonTranslate().currentLocale,
          supportedLocales: EasyJsonTranslate().supportedLocales,
          localizationsDelegates: const [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          home: const MyHomePage(),
        );
      },
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('title'.trJson), // Basic extension translation
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'subtitle'.trJson,
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            const SizedBox(height: 20),
            Text(
              'greeting'.trParams({
                'name': 'John Doe',
              }), // Interpolated translation
              style: Theme.of(context).textTheme.titleLarge,
            ),
            const SizedBox(height: 40),
            ElevatedButton(
              onPressed: () {
                // Change language
                final current = EasyJsonTranslate().currentLocale;
                if (current.languageCode == 'es') {
                  EasyJsonTranslate().changeLocale(const Locale('en', 'US'));
                } else {
                  EasyJsonTranslate().changeLocale(const Locale('es', 'ES'));
                }
              },
              child: Text('change_language'.trJson),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
160
points
108
downloads

Documentation

API reference

Publisher

verified publishergrandezsoft.com

Weekly Downloads

A pure Flutter widget-based package dynamically bridging localized JSON files into the app without generating Dart boilerplate.

Repository (GitHub)
View/report issues

Topics

#i18n #localization #json #translation

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on easy_json_translate