NothingBox
NothingBox

Reputation: 403

flutter_i18n localizationsDelegates setup

I am exploring Flutter Internalization and I decided to use flutter_i18n library. In the official doc, it mentions about configuration of the localizationsDelegates. I am looking for any examples on how to setup this for flutter_i18n but can't find any. The closest I got is this tutorial but it is using a different library and I am getting error on this import part:

import 'package:flutter_i18n_json/constant.dart' show languages;

How can I configure delegates on flutter_i18n library?

Upvotes: 0

Views: 883

Answers (1)

Santiago M
Santiago M

Reputation: 56

Set delegates in MaterialApp this way:

MaterialApp(
  // Localization
  localizationsDelegates: [
    FlutterI18nDelegate(
      translationLoader: FileTranslationLoader(...parameters...),
      missingTranslationHandler: (key, locale) {
        print("--- Missing Key: $key, languageCode: ${locale.languageCode}");
      },
    ),
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
    S.delegate, // Other delegate
  ],
  supportedLocales: S.delegate.supportedLocales, // List of lang codes.
  // End Localization
  debugShowCheckedModeBanner: false
)

https://api.flutter.dev/flutter/material/MaterialApp/localizationsDelegates.html

Upvotes: 1

Related Questions