Skip to content

Commit

Permalink
fix l10n
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex committed May 19, 2024
1 parent 94e40a8 commit d57bac8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
5 changes: 4 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) => const MaterialApp(
home: ChatPage(),
home: Directionality(
textDirection: TextDirection.ltr,
child: ChatPage(),
),
);
}

Expand Down
65 changes: 61 additions & 4 deletions lib/src/chat_l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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 = 'الرسائل غير المقروءة',
});
Expand All @@ -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',
});
Expand All @@ -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',
});
Expand All @@ -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',
});
Expand All @@ -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 = 'پیام‌های خوانده نشده',
});
}
Expand All @@ -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',
});
Expand All @@ -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 = '읽지 않은 메시지',
});
Expand All @@ -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',
});
Expand All @@ -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',
});
Expand All @@ -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 = 'Непрочитанные сообщения',
});
Expand All @@ -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',
});
Expand All @@ -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',
});
Expand All @@ -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 повідомлення',
});
Expand All @@ -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 = '未读消息',
});
Expand All @@ -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 = '未讀訊息',
});
Expand Down
7 changes: 4 additions & 3 deletions lib/src/widgets/typing_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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}';
}
}

Expand Down

0 comments on commit d57bac8

Please sign in to comment.