From d57bac8d470705c74cb8ba2ca9d415e1f4d93cb4 Mon Sep 17 00:00:00 2001 From: Alex Demchenko Date: Sun, 19 May 2024 11:04:48 +0200 Subject: [PATCH] fix l10n --- example/lib/main.dart | 5 ++- lib/src/chat_l10n.dart | 65 +++++++++++++++++++++++++-- lib/src/widgets/typing_indicator.dart | 7 +-- 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 1266aceab..b634147f9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -23,7 +23,10 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) => const MaterialApp( - home: ChatPage(), + home: Directionality( + textDirection: TextDirection.ltr, + child: ChatPage(), + ), ); } diff --git a/lib/src/chat_l10n.dart b/lib/src/chat_l10n.dart index 548b6cf0e..a75663ad8 100644 --- a/lib/src/chat_l10n.dart +++ b/lib/src/chat_l10n.dart @@ -6,14 +6,20 @@ import 'package:flutter/material.dart'; abstract class ChatL10n { /// Creates a new chat l10n based on provided copy. const ChatL10n({ + required this.and, required this.attachmentButtonAccessibilityLabel, required this.emptyChatPlaceholder, required this.fileButtonAccessibilityLabel, required this.inputPlaceholder, + required this.isTyping, + required this.others, required this.sendButtonAccessibilityLabel, required this.unreadMessagesLabel, }); + /// Word 'and', currently part of the typing indicator. + final String and; + /// Accessibility label (hint) for the attachment button. final String attachmentButtonAccessibilityLabel; @@ -26,6 +32,12 @@ abstract class ChatL10n { /// Placeholder for the text field. final String inputPlaceholder; + /// Label for the typing indicator. + final String isTyping; + + /// Word 'others', currently part of the typing indicator. + final String others; + /// Accessibility label (hint) for the send button. final String sendButtonAccessibilityLabel; @@ -40,10 +52,13 @@ class ChatL10nAr extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nAr({ + super.and = 'و', super.attachmentButtonAccessibilityLabel = 'إرسال الوسائط', super.emptyChatPlaceholder = 'لا يوجد رسائل هنا بعد', super.fileButtonAccessibilityLabel = 'ملف', super.inputPlaceholder = 'الرسالة', + super.isTyping = 'يكتب…', + super.others = 'آخرون', super.sendButtonAccessibilityLabel = 'إرسال', super.unreadMessagesLabel = 'الرسائل غير المقروءة', }); @@ -56,10 +71,13 @@ class ChatL10nDe extends ChatL10n { /// override only a couple of variables, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nDe({ + super.and = 'und', super.attachmentButtonAccessibilityLabel = 'Medien senden', super.emptyChatPlaceholder = 'Noch keine Nachrichten', super.fileButtonAccessibilityLabel = 'Datei', super.inputPlaceholder = 'Nachricht', + super.isTyping = 'tippt...', + super.others = 'andere', super.sendButtonAccessibilityLabel = 'Senden', super.unreadMessagesLabel = 'Ungelesene Nachrichten', }); @@ -72,10 +90,13 @@ class ChatL10nEn extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nEn({ + super.and = 'and', super.attachmentButtonAccessibilityLabel = 'Send media', super.emptyChatPlaceholder = 'No messages here yet', super.fileButtonAccessibilityLabel = 'File', super.inputPlaceholder = 'Message', + super.isTyping = 'is typing...', + super.others = 'others', super.sendButtonAccessibilityLabel = 'Send', super.unreadMessagesLabel = 'Unread messages', }); @@ -88,10 +109,13 @@ class ChatL10nEs extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nEs({ + super.and = 'y', super.attachmentButtonAccessibilityLabel = 'Enviar multimedia', super.emptyChatPlaceholder = 'Aún no hay mensajes', super.fileButtonAccessibilityLabel = 'Archivo', super.inputPlaceholder = 'Mensaje', + super.isTyping = 'está escribiendo...', + super.others = 'otros', super.sendButtonAccessibilityLabel = 'Enviar', super.unreadMessagesLabel = 'Mensajes no leídos', }); @@ -101,11 +125,14 @@ class ChatL10nEs extends ChatL10n { @immutable class ChatL10nFa extends ChatL10n { const ChatL10nFa({ - super.attachmentButtonAccessibilityLabel = 'فرستادن رسانه', - super.emptyChatPlaceholder = 'هنوز پیامی وجود ندارد', + super.and = 'و', + super.attachmentButtonAccessibilityLabel = 'ارسال رسانه', + super.emptyChatPlaceholder = 'هنوز پیامی در اینجا وجود ندارد', super.fileButtonAccessibilityLabel = 'فایل', - super.inputPlaceholder = 'متن پیام', - super.sendButtonAccessibilityLabel = 'بفرست', + super.inputPlaceholder = 'پیام', + super.isTyping = 'در حال نوشتن است...', + super.others = 'نفر دیگر', + super.sendButtonAccessibilityLabel = 'ارسال', super.unreadMessagesLabel = 'پیام‌های خوانده نشده', }); } @@ -117,10 +144,13 @@ class ChatL10nFi extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nFi({ + super.and = 'ja', super.attachmentButtonAccessibilityLabel = 'Lähetä media', super.emptyChatPlaceholder = 'Täällä ei ole vielä viestejä', super.fileButtonAccessibilityLabel = 'Tiedosto', super.inputPlaceholder = 'Viesti', + super.isTyping = 'kirjoittaa...', + super.others = 'muuta', super.sendButtonAccessibilityLabel = 'Lähetä', super.unreadMessagesLabel = 'Lukemattomat viestit', }); @@ -133,10 +163,13 @@ class ChatL10nKo extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nKo({ + super.and = '및', super.attachmentButtonAccessibilityLabel = '미디어 보내기', super.emptyChatPlaceholder = '주고받은 메시지가 없습니다', super.fileButtonAccessibilityLabel = '파일', super.inputPlaceholder = '메시지', + super.isTyping = '님이 입력 중...', + super.others = '개', super.sendButtonAccessibilityLabel = '보내기', super.unreadMessagesLabel = '읽지 않은 메시지', }); @@ -149,10 +182,13 @@ class ChatL10nPl extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nPl({ + super.and = 'i', super.attachmentButtonAccessibilityLabel = 'Wyślij multimedia', super.emptyChatPlaceholder = 'Tu jeszcze nie ma wiadomości', super.fileButtonAccessibilityLabel = 'Plik', super.inputPlaceholder = 'Napisz wiadomość', + super.isTyping = 'pisze...', + super.others = 'innych', super.sendButtonAccessibilityLabel = 'Wyślij', super.unreadMessagesLabel = 'Nieprzeczytane wiadomości', }); @@ -165,10 +201,13 @@ class ChatL10nPt extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nPt({ + super.and = 'e', super.attachmentButtonAccessibilityLabel = 'Envia mídia', super.emptyChatPlaceholder = 'Ainda não há mensagens aqui', super.fileButtonAccessibilityLabel = 'Arquivo', super.inputPlaceholder = 'Mensagem', + super.isTyping = 'está a escrever...', + super.others = 'outros', super.sendButtonAccessibilityLabel = 'Enviar', super.unreadMessagesLabel = 'Mensagens não lidas', }); @@ -181,10 +220,13 @@ class ChatL10nRu extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nRu({ + super.and = 'и', super.attachmentButtonAccessibilityLabel = 'Отправить медиа', super.emptyChatPlaceholder = 'Пока что у вас нет сообщений', super.fileButtonAccessibilityLabel = 'Файл', super.inputPlaceholder = 'Сообщение', + super.isTyping = 'печатает…', + super.others = 'другиx', super.sendButtonAccessibilityLabel = 'Отправить', super.unreadMessagesLabel = 'Непрочитанные сообщения', }); @@ -197,10 +239,13 @@ class ChatL10nSe extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nSe({ + super.and = 'och', super.attachmentButtonAccessibilityLabel = 'Skicka media', super.emptyChatPlaceholder = 'Inga meddelanden än', super.fileButtonAccessibilityLabel = 'Fil', super.inputPlaceholder = 'Meddelande', + super.isTyping = 'skriver...', + super.others = 'andra', super.sendButtonAccessibilityLabel = 'Skicka', super.unreadMessagesLabel = 'Olästa meddelanden', }); @@ -213,10 +258,13 @@ class ChatL10nTr extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nTr({ + super.and = 've', super.attachmentButtonAccessibilityLabel = 'Medya gönder', super.emptyChatPlaceholder = 'Henüz mesaj yok', super.fileButtonAccessibilityLabel = 'Dosya', super.inputPlaceholder = 'Mesaj yazın', + super.isTyping = 'yazıyor…', + super.others = 'diğer kişi', super.sendButtonAccessibilityLabel = 'Gönder', super.unreadMessagesLabel = 'Okunmamış Mesajlar', }); @@ -229,10 +277,13 @@ class ChatL10nUk extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nUk({ + super.and = 'та ще', super.attachmentButtonAccessibilityLabel = 'Надіслати медіа', super.emptyChatPlaceholder = 'Повідомлень ще немає', super.fileButtonAccessibilityLabel = 'Файл', super.inputPlaceholder = 'Повідомлення', + super.isTyping = 'пише...', + super.others = 'інших', super.sendButtonAccessibilityLabel = 'Надіслати', super.unreadMessagesLabel = 'Непрочитанi повідомлення', }); @@ -245,10 +296,13 @@ class ChatL10nZhCN extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nZhCN({ + super.and = '和其他', super.attachmentButtonAccessibilityLabel = '发送媒体文件', super.emptyChatPlaceholder = '暂无消息', super.fileButtonAccessibilityLabel = '文件', super.inputPlaceholder = '输入消息', + super.isTyping = '正在输入…', + super.others = '人', super.sendButtonAccessibilityLabel = '发送', super.unreadMessagesLabel = '未读消息', }); @@ -261,10 +315,13 @@ class ChatL10nZhTW extends ChatL10n { /// override only a couple of properties, otherwise create a new class /// which extends [ChatL10n]. const ChatL10nZhTW({ + super.and = '和另外', super.attachmentButtonAccessibilityLabel = '傳送媒體', super.emptyChatPlaceholder = '還沒有訊息在這裡', super.fileButtonAccessibilityLabel = '檔案', super.inputPlaceholder = '輸入訊息', + super.isTyping = '正在輸入…', + super.others = '人', super.sendButtonAccessibilityLabel = '傳送', super.unreadMessagesLabel = '未讀訊息', }); diff --git a/lib/src/widgets/typing_indicator.dart b/lib/src/widgets/typing_indicator.dart index 31388aca4..c970e87d3 100644 --- a/lib/src/widgets/typing_indicator.dart +++ b/lib/src/widgets/typing_indicator.dart @@ -3,6 +3,7 @@ import 'package:flutter_chat_types/flutter_chat_types.dart' as types; import '../../flutter_chat_ui.dart'; import '../util.dart'; import 'state/inherited_chat_theme.dart'; +import 'state/inherited_l10n.dart'; class TypingIndicator extends StatefulWidget { const TypingIndicator({ @@ -239,11 +240,11 @@ class TypingWidget extends StatelessWidget { if (author.isEmpty) { return ''; } else if (author.length == 1) { - return '${author.first.firstName} is typing'; + return '${author.first.firstName} ${InheritedL10n.of(context).l10n.isTyping}'; } else if (author.length == 2) { - return '${author.first.firstName} and ${author[1].firstName}'; + return '${author.first.firstName} ${InheritedL10n.of(context).l10n.and} ${author.last.firstName}'; } else { - return '${author.first.firstName} and ${author.length - 1} others'; + return '${author.first.firstName} ${InheritedL10n.of(context).l10n.and} ${author.length - 1} ${InheritedL10n.of(context).l10n.others}'; } }