Merge branch 'docs/addingLocalization' of github.com:GetStream/stream-chat-flutter into docs/addingLocalization
This commit is contained in:
@@ -32,7 +32,8 @@ You should then run `flutter packages get`
|
|||||||
|
|
||||||
### Usage
|
### 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`
|
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`.
|
||||||
|
Make sure to read more about localization in the [official Flutter docs](https://flutter.dev/docs/development/accessibility-and-localization/internationalization).
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -97,17 +98,23 @@ Here is an example of how that would look like:
|
|||||||
Locale('fr'),
|
Locale('fr'),
|
||||||
Locale('it'),
|
Locale('it'),
|
||||||
],
|
],
|
||||||
|
// locales are the locales of the device
|
||||||
|
// supportedLocales are the app supported locales
|
||||||
localeListResolutionCallback: (locales, supportedLocales) {
|
localeListResolutionCallback: (locales, supportedLocales) {
|
||||||
|
// We map the supported locales to language codes
|
||||||
|
// note that this is completely optional and this logic can be changed as you like
|
||||||
final supportedLanguageCodes =
|
final supportedLanguageCodes =
|
||||||
supportedLocales.map((e) => e.languageCode);
|
supportedLocales.map((e) => e.languageCode);
|
||||||
if (locales != null) {
|
if (locales != null) {
|
||||||
for (final locale in locales) {
|
// we iterate over the locales and find the first one that is supported
|
||||||
if (supportedLanguageCodes.contains(locale.languageCode)) {
|
for (final locale in locales) {
|
||||||
return locale;
|
if (supportedLanguageCodes.contains(locale.languageCode)) {
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// if we didn't find a supported language, we return the italian language
|
||||||
return const Locale('it');
|
return const Locale('it');
|
||||||
},
|
},
|
||||||
// Add GlobalStreamChatLocalizations.delegates
|
// Add GlobalStreamChatLocalizations.delegates
|
||||||
@@ -116,7 +123,7 @@ Here is an example of how that would look like:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
In this case we're using Italian as the default language.
|
In this case we're using italian as the default language.
|
||||||
|
|
||||||
### ⚠️ Note on **iOS**
|
### ⚠️ Note on **iOS**
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:ui' as ui;
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user