language_helper 0.0.1 icon indicating copy to clipboard operation
language_helper: ^0.0.1 copied to clipboard

Make it easier for you to implement multiple languages into your app.

Language Helper #

Make it easier for you to implement multiple languages into your app.

Usage #

Create the data:

LanguageData data = {
  LanguageCodes.en: {
    'Hello': 'Hello',
    'Change language': 'Change language',
  },
  LanguageCodes.vi: {
    'Hello': 'Xin Chào',
    'Change language': 'Thay đổi ngôn ngữ',
  }
};

Initialize the data:

LanguageHelper.instance.initial(
    data: data,
    defaultCode: LanguageCodes.en, // Optional. Default is set to the first language of [data]
    isDebug: true, // Print debug log. Default is set to false
);

Translate text:

final text = LanguageHelper.instance.translate('Hello');

Use extension:

final text = 'Hello'.tr;

Use builder to rebuild the widgets automatically on change:

  • For all widget in your app:
  @override
  Widget build(BuildContext context) {
    return LanguageNotifier(builder: (context) {
      return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text(LanguageHelper.instance.translate('Hello')),
          ),
          body: Center(
            child: Column(
              children: [
                Text('Hello'.tr),
                ElevatedButton(
                  onPressed: () {
                    LanguageHelper.instance.change(LanguageCodes.vi);
                  },
                  child: Text('Change language'.tr),
                ),
              ],
            ),
          ),
        ),
      );
    });
  }
  • For specific widget:
LanguageNotifier(
    builder: (context) {
        return Text('Hello'.tr);
    },
),

Additional Information #

  • All the widgets that you wrapped with LanguageNotifier will be rebuilt at the same time.
  • The LanguageCodes contains all the languages with additional information like name in English and name in native language.
  • This is the very first state so it may contain issues.
3
likes
120
pub points
67%
popularity

Publisher

verified publisher iconlamthanhnhan.com

Make it easier for you to implement multiple languages into your app.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on language_helper