tr_extension 0.10.0 copy "tr_extension: ^0.10.0" to clipboard
tr_extension: ^0.10.0 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(),
      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
150
points
213
downloads

Publisher

verified publisherbranvier.com

Weekly Downloads

A smart and lightweight string translation through extension.

Homepage
Repository (GitHub)
View/report issues

Topics

#smart #string #extension #translation

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_localizations, intl

More

Packages that depend on tr_extension