docs(localization): add Changing the default language section

This commit is contained in:
Salvatore Giordano
2021-07-29 11:22:27 +02:00
parent 993cd4ad6c
commit 87dcaa3bf0
@@ -32,6 +32,8 @@ You should then run `flutter packages get`
### Usage
Flutter generally and the Stream Chat SDK will use the system locale of the users device, if that locale is supported (see below), if the locale is not supported we will default to `en`
```dart
import 'package:flutter/material.dart';
import 'package:stream_chat_localizations/stream_chat_localizations.dart';
@@ -79,6 +81,43 @@ To override an existing language, create a new class extending that particular l
Checkout [this example](https://github.com/GetStream/stream-chat-flutter/blob/master/packages/stream_chat_localizations/example/lib/override_lang.dart) to see how to override an existing language.
### Changing the default language
To change the default language you can use the `MaterialApp.localeListResolutionCallback` property.
Here is an example of how that would look like:
```dart
MaterialApp(
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
// Add all the supported locales
supportedLocales: const [
Locale('en'),
Locale('hi'),
Locale('fr'),
Locale('it'),
],
localeListResolutionCallback: (locales, supportedLocales) {
final supportedLanguageCodes =
supportedLocales.map((e) => e.languageCode);
if (locales != null) {
for (final locale in locales) {
if (supportedLanguageCodes.contains(locale.languageCode)) {
return locale;
}
}
}
return const Locale('it');
},
// Add GlobalStreamChatLocalizations.delegates
localizationsDelegates: GlobalStreamChatLocalizations.delegates,
...
```
In this case we're using Italian as the default language.
### ⚠️ Note on **iOS**
For translation to work on **iOS** you need to add supported locales to