localize_and_translate 6.0.0-dev.5 copy "localize_and_translate: ^6.0.0-dev.5" to clipboard
localize_and_translate: ^6.0.0-dev.5 copied to clipboard

Flutter localization in easy steps, simple ways to localize and translate your app

example/lib/main.dart

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

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

  await LocalizeAndTranslate.init(
    assetLoader: const AssetLoaderRootBundleJson('assets/lang'),
    supportedLanguageCodes: const <String>['ar', 'en'],
  );

  runApp(
    const MyApp(),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return LocalizedApp(
      child: MaterialApp(
        localizationsDelegates: context.delegates,
        supportedLocales: context.supportedLocales,
        locale: context.locale,
        builder: (BuildContext context, Widget? child) {
          child = LocalizeAndTranslate.directionBuilder(context, child);

          return child;
        },
        theme: ThemeData(
          primarySwatch: Colors.indigo,
        ),
        home: const MyHomePage(),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('name'.tr()),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            if (LocalizeAndTranslate.getLanguageCode() == 'ar') {
              LocalizeAndTranslate.setLanguageCode('en');
              debugPrint('new lang: en -- context.locale: ${context.locale}');
            } else {
              LocalizeAndTranslate.setLanguageCode('ar');
              debugPrint('new lang: ar -- context.locale: ${context.locale}');
            }
          },
          child: Text('change'.tr()),
        ),
      ),
    );
  }
}
132
likes
0
points
1.28k
downloads

Publisher

verified publishermsayed.net

Weekly Downloads

Flutter localization in easy steps, simple ways to localize and translate your app

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, flutter, flutter_localizations, hive, hive_flutter

More

Packages that depend on localize_and_translate