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

outdated

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 MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  @override
  void reassemble() {
    // usefull for adding new translations while hot reloading
    Tr.to.reloadFiles();
    super.reassemble();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: context.localizationsDelegates,
      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('helloWorld'.tr),
            ElevatedButton(
                onPressed: () {
                  final locale = Tr.to.locale == const Locale('pt', 'BR')
                      ? const Locale('en', 'US')
                      : const Locale('pt', 'BR');

                  Tr.to.changeLanguage(locale);
                },
                child: Text('changeLanguage'.tr))
          ],
        ),
      ),
    );
  }
}
3
likes
0
points
213
downloads

Publisher

verified publisherbranvier.com

Weekly Downloads

A smart and lightweight string translation through extension.

Homepage

License

unknown (license)

Dependencies

flutter, flutter_localizations

More

Packages that depend on tr_extension