tr_extension 0.9.2 copy "tr_extension: ^0.9.2" to clipboard
tr_extension: ^0.9.2 copied to clipboard

A smart and lightweight string translation through extension.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: TrDelegate().toList(),
      locale: context.locale,
      supportedLocales: const [
        Locale('en', 'US'),
        Locale('pt', 'BR'),
      ],
      home: const Home(),
    );
  }
}

var locale = const Locale('en', 'US');

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            /// these keys are located at:
            /// - assets/translations/en_US.json
            /// - assets/translations/pt_BR.json
            Text('hello_world'.tr),
            Text(DateTime.now().jms()),
            Text('1200000000.4'.compactSimpleCurrency()),
            Text('1200000000.4'.compactCurrency()),
            ElevatedButton(
                onPressed: () {
                  final locale = context.locale == const Locale('pt', 'BR')
                      ? const Locale('en', 'US')
                      : const Locale('pt', 'BR');

                  context.setLocale(locale);
                },
                child: Text('change_language'.tr))
          ],
        ),
      ),
    );
  }
}
3
likes
160
points
114
downloads

Publisher

verified publisherbranvier.com

Weekly Downloads

A smart and lightweight string translation through extension.

Homepage
Repository (GitHub)

Topics

#smart #string #extension #translation

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_localizations, intl

More

Packages that depend on tr_extension