Localization

The stream_video_flutter package with UI elements also includes some localizable strings. By default, these strings are in English. To use other available languages you need to add the corresponding localization delegates to your app. If you use MaterialApp that would look like this:

import 'package:stream_video_flutter/stream_video_flutter_l10n.dart';

//...

return MaterialApp.router(
  supportedLocales: const [Locale('en'), Locale('nl')],
  localizationsDelegates: StreamVideoFlutterLocalizations.localizationsDelegates,
);

In this example our app only supports English and Dutch and we add the localizationsDelegates from StreamVideo which are imported from stream_video_flutter_l10n.

The localizationsDelegates list includes StreamVideoFlutterLocalizations, as well as GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, and GlobalWidgetsLocalizations.delegate. If your app also has its own localizations, you only have to include StreamVideoFlutterLocalizations.delegate and your MaterialApp will look like this:

    return MaterialApp.router(
      supportedLocales: const [Locale('en'), Locale('nl')],
      localizationsDelegates: [
        StreamVideoFlutterLocalizations.delegate,
        ...MyAppLocalizations.localizationsDelegates,
      ],
    );

Customizing localizations

You can customize existing localizations by extending them. This way, you only change what you want while still benefiting from new sentences added to the Stream Video SDK.

You can do so by extending one of the existing localization files, such as StreamVideoFlutterLocalizationsNl. You can directly override one of the localizable strings.

class CustomVideoLocalizationsNL extends StreamVideoFlutterLocalizationsNl {
  @override
  String get desktopScreenShareEntireScreen => 'Scherm';
}

Localizations also require a delegate. We made this easy with a CustomVideoLocalizationsDelegate, which always supports only 1 language. You can add this as a static property in your custom localizations class:

class CustomVideoLocalizationsNL extends StreamVideoFlutterLocalizationsNl {
  static LocalizationsDelegate<StreamVideoFlutterLocalizations> get delegate =>
      CustomVideoLocalizationsDelegate('nl', CustomVideoLocalizationsNL());
//...
}

You can use this in your MaterialApp like this:

    return MaterialApp.router(
      localizationsDelegates: [
        CustomVideoLocalizationsNL.delegate,
        ...StreamVideoFlutterLocalizations.localizationsDelegates,
      ],
    );

Flutter checks a list of localizationDelegates from top to bottom. If you use a text from StreamVideoFlutterLocalizations in Dutch (nl), Flutter will go through each delegate to see if it matches the required type and supports the given language. The first delegate that matches both the type and the language will be returned. Therefore, you should always put your custom delegate before the StreamVideoFlutterLocalizations delegate.

Adding localizations

Adding a new language works similarly to customizing an existing one. You can choose to extend StreamVideoFlutterLocalizations directly, which requires you to define texts for all available keys. However, we recommend extending an existing language, so you are not forced to add localizations for features you might not use.

For example if you would add the language nn with fallbacks on English, you could do this:

class NewVideoLocalization extends StreamVideoFlutterLocalizationsEn {
  NewVideoLocalization() : super('nn');

  static LocalizationsDelegate<StreamVideoFlutterLocalizations> get delegate =>
      CustomVideoLocalizationsDelegate('nn', NewVideoLocalization());
}

Notice that in the CustomVideoLocalizationsNL where we extend an existing language we did not add a constructor, because the language was already set. In the case of NewVideoLocalization we want to override the language code in the super or parent constructor.

You can add the delegate to your MaterialApp in the same way as mentioned earlier.

Contributing localizations

Instead of adding a new language to your app you can also contribute by submitting a pull request to our repository and adding your language of preference. We will do our best to maintain it effectively. Our localizations are generated based on arb files using standard Flutter localizations.

Using melos run gen-l10n you can update localizations and directly format the resulting code.

© Getstream.io, Inc. All Rights Reserved.