localize_and_translate 4.1.2-dev copy "localize_and_translate: ^4.1.2-dev" to clipboard
localize_and_translate: ^4.1.2-dev copied to clipboard

outdated

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

localize_and_translate #

Flutter localization in easy steps

Pub Example

Fork Star Watch

Screenshots #

screenshot 1 screenshot 2

Tutorial #

Video #

Methods #

Method Job
init() initialize things, before runApp()
'word'.tr() word translation - string extension
translate('word') word translation
translate('word',{"key":"value"}) word translation with replacement arguments
setNewLanguage(context,newLanguage:'en',restart: true, remember: true,) change language
isDirectionRTL() is Direction RTL check
currentLanguage Active language code
locale Active Locale
locals() Locales list
delegates Localization Delegates

Installation #

  • add .json translation files as assets
  • For example : 'assets/lang/ar.json' | 'assets/lang/en.json'
  • structure should look like
{
    "appTitle": "تطبيق تجريبى", 
    "buttonTitle": "English", 
    "textArea": "هذا مجرد نموذج للتأكد من اداء الأداة"
}
  • define them as assets in pubspec.yaml
flutter:
  assets:
    - assets/lang/

Initialization #

  • Add imports to main.dart
  • Make main() async and do the following
  • Ensure flutter activated WidgetsFlutterBinding.ensureInitialized()
  • Initialize await translator.init(); with neccassry parameters
  • Inside runApp() wrap entry class with LocalizedApp()
  • Note : make sure you define it's child into different place "NOT INSIDE"
import 'package:flutter/material.dart';
import 'package:localize_and_translate/localize_and_translate.dart';

main() async {
  // if your flutter > 1.7.8 :  ensure flutter activated
  WidgetsFlutterBinding.ensureInitialized();

  await translator.init(
    localeType: LocalizationDefaultType.device,
    languagesList: <String>['ar', 'en'],
    assetsDirectory: 'assets/lang/',
  );

  runApp(
    LocalizedApp(
      child: MyApp(),
    ),
  );
}
  • LocalizedApp() child example -> MaterialApp()
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
      localizationsDelegates: translator.delegates, // Android + iOS Delegates
      locale: translator.locale, // Active locale
      supportedLocales: translator.locals(), // Locals list
    );
  }
}

Usage #

  • use translate('appTitle')
  • use setNewLanguage(context, newLanguage: 'ar', remember: true, restart: true);

Example #

Example

Contributors #

Contributors List

131
likes
0
pub points
94%
popularity

Publisher

verified publishermsayed.net

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_localizations, shared_preferences

More

Packages that depend on localize_and_translate