feat: setup intl

closes #29
This commit is contained in:
2025-05-20 15:48:51 +01:00
parent 182f34ff71
commit a0b2275bea
24 changed files with 955 additions and 270 deletions

View File

@ -1,6 +1,9 @@
import 'package:collection/collection.dart';
import 'package:duration/duration.dart';
import 'package:flutter/widgets.dart';
import 'package:ndk/ndk.dart';
import 'package:zap_stream_flutter/i18n/strings.g.dart';
import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
@ -11,32 +14,43 @@ class ChatTimeoutWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final pTags = timeout.pTags;
final duration =
double.parse(timeout.getFirstTag("expiration")!) - timeout.createdAt;
return Container(
padding: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
child: RichText(
text: TextSpan(
style: TextStyle(color: LAYER_5),
children: [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: ProfileNameWidget.pubkey(timeout.pubKey),
),
TextSpan(text: " timed out "),
...pTags.map(
(p) => WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: ProfileNameWidget.pubkey(p),
child: FutureBuilder(
future: ndk.metadata.loadMetadatas([
timeout.pubKey,
...timeout.pTags,
], null),
builder: (context, state) {
final modProfile =
state.data?.firstWhereOrNull((p) => p.pubKey == timeout.pubKey) ??
Metadata(pubKey: timeout.pubKey);
final userProfiles = timeout.pTags.map(
(p) =>
state.data?.firstWhereOrNull((x) => x.pubKey == p) ??
Metadata(pubKey: p),
);
return Text.rich(
style: TextStyle(color: LAYER_5),
t.stream.chat.timeout(
mod: TextSpan(
text: ProfileNameWidget.nameFromProfile(modProfile),
),
user: TextSpan(
text: userProfiles
.map((p) => ProfileNameWidget.nameFromProfile(p))
.join(", "),
),
time: TextSpan(
text: Duration(seconds: duration.floor()).pretty(),
),
),
TextSpan(
text: " for ${Duration(seconds: duration.toInt()).pretty()}",
),
],
),
);
},
),
);
}