flutter_translaty 1.0.1 copy "flutter_translaty: ^1.0.1" to clipboard
flutter_translaty: ^1.0.1 copied to clipboard

outdated

Manage your translations easily with translaty.io. Built on top of easy_localization

example/lib/main.dart

import 'package:flutter_translaty/flutter_translaty.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import 'generated/locale_keys.g.dart';
import 'lang_view.dart';

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

  runApp(EasyLocalization(
    supportedLocales: [
      Locale('en', 'US'),
      Locale('de'),
      Locale('ru'),
    ],
    path: 'assets/translations',
    child: MyApp(),
    // fallbackLocale: Locale('en', 'US'),
    startLocale: Locale('de'),
    saveLocale: false,
    // useOnlyLangCode: true,

    // optional assetLoader default used is RootBundleAssetLoader which uses flutter's assetloader
    // install easy_localization_loader for enable custom loaders
    // assetLoader: RootBundleAssetLoader()
    // assetLoader: HttpAssetLoader()
    // assetLoader: FileAssetLoader()
    // assetLoader: CsvAssetLoader()
    // assetLoader: YamlAssetLoader() //multiple files
    // assetLoader: YamlSingleAssetLoader() //single file
    // assetLoader: XmlAssetLoader() //multiple files
    // assetLoader: XmlSingleAssetLoader() //single file
    // assetLoader: CodegenLoader()
  ));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: context.localizationDelegates,
      supportedLocales: context.supportedLocales,
      locale: context.locale,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Easy localization'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int counter = 0;
  bool _gender = true;

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

  void _decreaseCounter() {
    setState(() {
      counter--;
    });
  }

  void _switchGender(bool val) {
    setState(() {
      _gender = val;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Title"),
        actions: <Widget>[
          TextButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (_) => LanguageView(),
                  fullscreenDialog: true,
                ),
              );
            },
            child: Icon(
              Icons.language,
              color: Colors.white,
            ),
          ),
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Spacer(
              flex: 1,
            ),
            // Text(
            //   LocaleKeys.gender_with_arg,
            //   style: TextStyle(
            //       color: Colors.grey.shade600,
            //       fontSize: 19,
            //       fontWeight: FontWeight.bold),
            // ).tr(args: ['aissat'], gender: _gender ? 'female' : 'male'),
            // Text(
            //   tr(LocaleKeys.gender, gender: _gender ? 'female' : 'male'),
            //   style: TextStyle(
            //       color: Colors.grey.shade600,
            //       fontSize: 15,
            //       fontWeight: FontWeight.bold),
            // ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                FaIcon(FontAwesomeIcons.male),
                Switch(value: _gender, onChanged: _switchGender),
                FaIcon(FontAwesomeIcons.female),
              ],
            ),
            Spacer(flex: 1),
            // Text(LocaleKeys.msg).tr(args: ['aissat', 'Flutter']),
            // Text(LocaleKeys.msg_named)
            //     .tr(namedArgs: {'lang': 'Dart'}, args: ['Easy localization']),
            // Text(LocaleKeys.clicked).plural(counter),
            TextButton(
              onPressed: () => _incrementCounter(),
              child: Text("Increase counter"),
            ),
            TextButton(
              onPressed: () => _decreaseCounter(),
              child: Text("Decrease counter"),
            ),
            SizedBox(
              height: 15,
            ),
            Text(
              plural(
                LocaleKeys.plural_key,
                counter,
                namedArgs: {
                  "count": counter.toString(),
                },
              ),
            ),
            // Text(
            //   plural(LocaleKeys.amount, counter,
            //       format: NumberFormat.currency(
            //           locale: Intl.defaultLocale, symbol: '€')),
            //   style: TextStyle(
            //       color: Colors.grey.shade900,
            //       fontSize: 18,
            //       fontWeight: FontWeight.bold),
            // ),
            SizedBox(
              height: 20,
            ),
            ElevatedButton(
              onPressed: () {
                context.resetLocale();
              },
              child: Text("Reset locale"),
              // child: Text(LocaleKeys.reset_locale).tr(),
            ),
            Spacer(
              flex: 1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        child: Text('+1'),
      ),
    );
  }
}
1
likes
0
points
199
downloads

Publisher

unverified uploader

Weekly Downloads

Manage your translations easily with translaty.io. Built on top of easy_localization

Homepage
View/report issues

License

unknown (license)

Dependencies

args, easy_logger, flutter, flutter_localizations, intl, path, pubspec_yaml, shared_preferences, translaty_fetcher, yaml

More

Packages that depend on flutter_translaty