From 800baec9323c5679a53077739ac03c046ce32038 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 28 Jul 2021 17:20:14 +0200 Subject: [PATCH 1/6] docs(localization): add localization docs --- .../docs/Flutter/basics/introduction.mdx | 1 + .../guides/adding_custom_attachments.mdx | 2 +- .../Flutter/guides/adding_localization.mdx | 97 +++++++++++++++++++ .../Flutter/guides/migration_guide_2_0.mdx | 2 +- .../test/src/core/models/user_test.dart | 2 - packages/stream_chat_localizations/README.md | 9 +- 6 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 docusaurus/docs/Flutter/guides/adding_localization.mdx diff --git a/docusaurus/docs/Flutter/basics/introduction.mdx b/docusaurus/docs/Flutter/basics/introduction.mdx index 32e80899..756bd33f 100644 --- a/docusaurus/docs/Flutter/basics/introduction.mdx +++ b/docusaurus/docs/Flutter/basics/introduction.mdx @@ -28,6 +28,7 @@ The core package allows more customisation and hence provides business logic but reusable and customisable UI components. 4. Persistence (stream_chat_persistence): provides a persistence client for fetching and saving chat data locally. +5. Localizations (stream_chat_localizations): provides a set of localizations for the SDK. 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) diff --git a/docusaurus/docs/Flutter/guides/adding_custom_attachments.mdx b/docusaurus/docs/Flutter/guides/adding_custom_attachments.mdx index 945fd3d7..fb1f7bbe 100644 --- a/docusaurus/docs/Flutter/guides/adding_custom_attachments.mdx +++ b/docusaurus/docs/Flutter/guides/adding_custom_attachments.mdx @@ -1,6 +1,6 @@ --- id: adding_custom_attachments -sidebar_position: 2 +sidebar_position: 3 title: Adding Custom Attachments --- diff --git a/docusaurus/docs/Flutter/guides/adding_localization.mdx b/docusaurus/docs/Flutter/guides/adding_localization.mdx new file mode 100644 index 00000000..678a7d4d --- /dev/null +++ b/docusaurus/docs/Flutter/guides/adding_localization.mdx @@ -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 +CFBundleLocalizations + + en + nb + fr + it + +``` diff --git a/docusaurus/docs/Flutter/guides/migration_guide_2_0.mdx b/docusaurus/docs/Flutter/guides/migration_guide_2_0.mdx index 8f5a6864..89b6dacc 100644 --- a/docusaurus/docs/Flutter/guides/migration_guide_2_0.mdx +++ b/docusaurus/docs/Flutter/guides/migration_guide_2_0.mdx @@ -1,6 +1,6 @@ --- id: mig_guide_2_0 -sidebar_position: 3 +sidebar_position: 4 title: Migrating to 2.0 (Null-safety) --- diff --git a/packages/stream_chat/test/src/core/models/user_test.dart b/packages/stream_chat/test/src/core/models/user_test.dart index 5319c02b..ce488cab 100644 --- a/packages/stream_chat/test/src/core/models/user_test.dart +++ b/packages/stream_chat/test/src/core/models/user_test.dart @@ -29,7 +29,6 @@ void main() { expect(newUser.id, user.id); expect(newUser.role, user.role); expect(newUser.name, user.name); - expect(newUser.language, user.language); newUser = user.copyWith( id: 'test', @@ -42,7 +41,6 @@ void main() { expect(newUser.id, 'test'); expect(newUser.role, 'test'); expect(newUser.name, 'test'); - expect(newUser.language, 'en'); }); }); } diff --git a/packages/stream_chat_localizations/README.md b/packages/stream_chat_localizations/README.md index 49fd4442..15f7cabc 100644 --- a/packages/stream_chat_localizations/README.md +++ b/packages/stream_chat_localizations/README.md @@ -13,6 +13,7 @@ - [Register](https://getstream.io/chat/trial/) to get an API key for Stream Chat - [Flutter Chat Tutorial](https://getstream.io/chat/flutter/tutorial/) - [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. @@ -23,10 +24,10 @@ Check out the [changelog on pub.dev](https://pub.dev/packages/stream_chat_locali ## Supported languages At the moment we support the following languages: -- [English](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsEn-class.html) -- [Hindi](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsHi-class.html) -- [Italian](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsIt-class.html) -- [French](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsFr-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_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. From 18d49dd5711f5847b2aecd8394fef733f3abea02 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 28 Jul 2021 17:40:16 +0200 Subject: [PATCH 2/6] Update docusaurus/docs/Flutter/guides/adding_localization.mdx Co-authored-by: Gordon Hayes --- docusaurus/docs/Flutter/guides/adding_localization.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/Flutter/guides/adding_localization.mdx b/docusaurus/docs/Flutter/guides/adding_localization.mdx index 678a7d4d..1ae2efc0 100644 --- a/docusaurus/docs/Flutter/guides/adding_localization.mdx +++ b/docusaurus/docs/Flutter/guides/adding_localization.mdx @@ -75,7 +75,7 @@ Checkout [this example](https://github.com/GetStream/stream-chat-flutter/blob/ma ### 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. +To override an existing language, 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. From 00e3f58258b36ed436937cde7f668ddcb6573f3f Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 28 Jul 2021 17:40:44 +0200 Subject: [PATCH 3/6] Update docusaurus/docs/Flutter/guides/adding_localization.mdx Co-authored-by: Gordon Hayes --- docusaurus/docs/Flutter/guides/adding_localization.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/Flutter/guides/adding_localization.mdx b/docusaurus/docs/Flutter/guides/adding_localization.mdx index 1ae2efc0..68e37464 100644 --- a/docusaurus/docs/Flutter/guides/adding_localization.mdx +++ b/docusaurus/docs/Flutter/guides/adding_localization.mdx @@ -69,7 +69,7 @@ class MyApp extends StatelessWidget { ### 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. +To add a new language, 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. From 236a32403ec0a0215344d05b92b70498dbfde64e Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 28 Jul 2021 21:18:43 +0530 Subject: [PATCH 4/6] fix(localizations): minor fixes Signed-off-by: xsahil03x --- packages/stream_chat_localizations/CHANGELOG.md | 4 ++++ .../lib/src/stream_chat_localizations.dart | 4 +--- .../lib/stream_chat_localizations.dart | 2 +- packages/stream_chat_localizations/pubspec.yaml | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/stream_chat_localizations/CHANGELOG.md b/packages/stream_chat_localizations/CHANGELOG.md index 5ca6d89e..772ae6d0 100644 --- a/packages/stream_chat_localizations/CHANGELOG.md +++ b/packages/stream_chat_localizations/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.1 + +* Minor Fixes + ## 1.0.0 * First release diff --git a/packages/stream_chat_localizations/lib/src/stream_chat_localizations.dart b/packages/stream_chat_localizations/lib/src/stream_chat_localizations.dart index bb2d791f..f98932b5 100644 --- a/packages/stream_chat_localizations/lib/src/stream_chat_localizations.dart +++ b/packages/stream_chat_localizations/lib/src/stream_chat_localizations.dart @@ -1,9 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; -import 'package:jiffy/jiffy.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart' - show StreamChatLocalizations, User; +import 'package:stream_chat_flutter/stream_chat_flutter.dart'; part 'stream_chat_localizations_en.dart'; diff --git a/packages/stream_chat_localizations/lib/stream_chat_localizations.dart b/packages/stream_chat_localizations/lib/stream_chat_localizations.dart index 0cfb60ba..27c01880 100644 --- a/packages/stream_chat_localizations/lib/stream_chat_localizations.dart +++ b/packages/stream_chat_localizations/lib/stream_chat_localizations.dart @@ -1,5 +1,5 @@ /// Localizations for the StreamChat Flutter library. -library stream_chat_localization; +library stream_chat_localizations; export 'package:flutter_localizations/flutter_localizations.dart' show diff --git a/packages/stream_chat_localizations/pubspec.yaml b/packages/stream_chat_localizations/pubspec.yaml index 01b027a5..445c06ae 100644 --- a/packages/stream_chat_localizations/pubspec.yaml +++ b/packages/stream_chat_localizations/pubspec.yaml @@ -1,6 +1,6 @@ name: stream_chat_localizations description: The Official localizations for Stream Chat Flutter, a service for building chat applications -version: 1.0.0 +version: 1.0.1 homepage: https://github.com/GetStream/stream-chat-flutter repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues From 587fc473162a16c42953cabedd24ba171cb0a9ac Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 28 Jul 2021 17:49:27 +0200 Subject: [PATCH 5/6] fix links --- docusaurus/docs/Flutter/guides/adding_localization.mdx | 8 ++++---- packages/stream_chat_localizations/README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docusaurus/docs/Flutter/guides/adding_localization.mdx b/docusaurus/docs/Flutter/guides/adding_localization.mdx index 68e37464..b48f355c 100644 --- a/docusaurus/docs/Flutter/guides/adding_localization.mdx +++ b/docusaurus/docs/Flutter/guides/adding_localization.mdx @@ -13,10 +13,10 @@ We have a dedicated package for adding localization to our UI widgets. It's call ### 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) +- [English](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsEn-class.html) +- [Hindi](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsHi-class.html) +- [Italian](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsIt-class.html) +- [French](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/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. diff --git a/packages/stream_chat_localizations/README.md b/packages/stream_chat_localizations/README.md index 15f7cabc..c96ec8af 100644 --- a/packages/stream_chat_localizations/README.md +++ b/packages/stream_chat_localizations/README.md @@ -24,10 +24,10 @@ Check out the [changelog on pub.dev](https://pub.dev/packages/stream_chat_locali ## 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) +- [English](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsEn-class.html) +- [Hindi](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsHi-class.html) +- [Italian](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/StreamChatLocalizationsIt-class.html) +- [French](https://pub.dev/documentation/stream_chat_localizations/latest/stream_chat_localizations/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. From 3c48e70108b90d8ca7bb12978ec8afa5726ae4bc Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 29 Jul 2021 11:14:21 +0200 Subject: [PATCH 6/6] fix(ui): jiffy use app level locale --- packages/stream_chat_flutter/lib/src/stream_chat.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/stream_chat.dart b/packages/stream_chat_flutter/lib/src/stream_chat.dart index 6eae0fcc..b3654a31 100644 --- a/packages/stream_chat_flutter/lib/src/stream_chat.dart +++ b/packages/stream_chat_flutter/lib/src/stream_chat.dart @@ -148,8 +148,8 @@ class StreamChatState extends State { @override void didChangeDependencies() { - final locale = ui.window.locale; - final languageCode = locale.languageCode; + final currentLocale = Localizations.localeOf(context); + final languageCode = currentLocale.languageCode; final availableLocales = Jiffy.getAllAvailableLocales(); if (availableLocales.contains(languageCode)) { Jiffy.locale(languageCode);