docs(localization): add localization docs

This commit is contained in:
Salvatore Giordano
2021-07-28 17:20:14 +02:00
parent fd38c25684
commit 800baec932
6 changed files with 105 additions and 8 deletions
@@ -28,6 +28,7 @@ The core package allows more customisation and hence provides business logic but
reusable and customisable UI components. reusable and customisable UI components.
4. <b>Persistence (stream_chat_persistence)</b>: provides a persistence client for fetching and 4. <b>Persistence (stream_chat_persistence)</b>: provides a persistence client for fetching and
saving chat data locally. saving chat data locally.
5. <b>Localizations (stream_chat_localizations)</b>: provides a set of localizations for the SDK.
We recommend building prototypes using the full UI package since it contains UI widgets already We recommend building prototypes using the full UI package since it contains UI widgets already
integrated with Stream's API. [stream_chat_flutter](https://pub.dev/packages/stream_chat_flutter) integrated with Stream's API. [stream_chat_flutter](https://pub.dev/packages/stream_chat_flutter)
@@ -1,6 +1,6 @@
--- ---
id: adding_custom_attachments id: adding_custom_attachments
sidebar_position: 2 sidebar_position: 3
title: Adding Custom Attachments title: Adding Custom Attachments
--- ---
@@ -0,0 +1,97 @@
---
id: adding_localization
sidebar_position: 2
title: Adding Localization
---
Adding Localization To UI Widgets
### Introduction
We have a dedicated package for adding localization to our UI widgets. It's called `stream_chat_localizations` and you can find it [here](https://pub.dev/packages/stream_chat_localizations).
### Supported languages
At the moment we support the following languages:
- [English](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localization/StreamChatLocalizationsEn-class.html)
- [Hindi](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localization/StreamChatLocalizationsHi-class.html)
- [Italian](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localization/StreamChatLocalizationsIt-class.html)
- [French](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localization/StreamChatLocalizationsFr-class.html)
More languages will be added in the future. Feel free to [contribute](https://github.com/GetStream/stream-chat-flutter/blob/master/CONTRIBUTING.md) to add more languages.
### Add dependency
Add this to your package's pubspec.yaml file, use the latest version [![Pub](https://img.shields.io/pub/v/stream_chat_localizations.svg)](https://pub.dartlang.org/packages/stream_chat_localizations)
```yaml
dependencies:
stream_chat_localizations: ^latest_version
```
You should then run `flutter packages get`
### Usage
```dart
import 'package:flutter/material.dart';
import 'package:stream_chat_localizations/stream_chat_localizations.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Add all the supported locales
supportedLocales: const [
Locale('en'),
Locale('hi'),
Locale('fr'),
Locale('it'),
],
// Add GlobalStreamChatLocalizations.delegates
localizationsDelegates: GlobalStreamChatLocalizations.delegates,
builder: (context, widget) => StreamChat(
client: client,
child: widget,
),
home: StreamChannel(
channel: channel,
child: const ChannelPage(),
),
);
}
}
```
### Adding a new language
To add a new language, you need to create a new class extending `GlobalStreamChatLocalizations` and create a delegate for it adding it to the `delegates` array.
Checkout [this example](https://github.com/GetStream/stream-chat-flutter/blob/master/packages/stream_chat_localizations/example/lib/add_new_lang.dart) to see how to add a new language.
### Override exisiting languages
To override an existing language, you need to create a new class extending that particular language class and create a delegate for it adding it to the `delegates` array.
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.
### ⚠️ Note on **iOS**
For translation to work on **iOS** you need to add supported locales to
`ios/Runner/Info.plist` as described [here](https://flutter.dev/docs/development/accessibility-and-localization/internationalization#specifying-supportedlocales).
Example:
```xml
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>nb</string>
<string>fr</string>
<string>it</string>
</array>
```
@@ -1,6 +1,6 @@
--- ---
id: mig_guide_2_0 id: mig_guide_2_0
sidebar_position: 3 sidebar_position: 4
title: Migrating to 2.0 (Null-safety) title: Migrating to 2.0 (Null-safety)
--- ---
@@ -29,7 +29,6 @@ void main() {
expect(newUser.id, user.id); expect(newUser.id, user.id);
expect(newUser.role, user.role); expect(newUser.role, user.role);
expect(newUser.name, user.name); expect(newUser.name, user.name);
expect(newUser.language, user.language);
newUser = user.copyWith( newUser = user.copyWith(
id: 'test', id: 'test',
@@ -42,7 +41,6 @@ void main() {
expect(newUser.id, 'test'); expect(newUser.id, 'test');
expect(newUser.role, 'test'); expect(newUser.role, 'test');
expect(newUser.name, 'test'); expect(newUser.name, 'test');
expect(newUser.language, 'en');
}); });
}); });
} }
+5 -4
View File
@@ -13,6 +13,7 @@
- [Register](https://getstream.io/chat/trial/) to get an API key for Stream Chat - [Register](https://getstream.io/chat/trial/) to get an API key for Stream Chat
- [Flutter Chat Tutorial](https://getstream.io/chat/flutter/tutorial/) - [Flutter Chat Tutorial](https://getstream.io/chat/flutter/tutorial/)
- [Chat UI Kit](https://getstream.io/chat/ui-kit/) - [Chat UI Kit](https://getstream.io/chat/ui-kit/)
- [UI Docs](https://getstream.io/chat/docs/sdk/flutter/stream_chat_flutter/introduction/)
This package provides localized strings for the stream chat widgets for many languages. This package provides localized strings for the stream chat widgets for many languages.
@@ -23,10 +24,10 @@ Check out the [changelog on pub.dev](https://pub.dev/packages/stream_chat_locali
## Supported languages ## Supported languages
At the moment we support the following languages: At the moment we support the following languages:
- [English](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsEn-class.html) - [English](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localization/StreamChatLocalizationsEn-class.html)
- [Hindi](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsHi-class.html) - [Hindi](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localization/StreamChatLocalizationsHi-class.html)
- [Italian](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsIt-class.html) - [Italian](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localization/StreamChatLocalizationsIt-class.html)
- [French](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsFr-class.html) - [French](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localization/StreamChatLocalizationsFr-class.html)
More languages will be added in the future. Feel free to [contribute](https://github.com/GetStream/stream-chat-flutter/blob/master/CONTRIBUTING.md) to add more languages. More languages will be added in the future. Feel free to [contribute](https://github.com/GetStream/stream-chat-flutter/blob/master/CONTRIBUTING.md) to add more languages.