feat(frontend): add multi-language support (en, zh-Hans, zh-Hant, ja)
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../providers/auth_provider.dart';
|
||||
import '../providers/settings_provider.dart';
|
||||
import '../services/api_service.dart';
|
||||
@@ -22,6 +23,7 @@ class _HomePageState extends State<HomePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool isWide = MediaQuery.of(context).size.width > 600;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
final List<Widget> pages = [
|
||||
_ExploreView(onGoLive: () => setState(() => _selectedIndex = 1)),
|
||||
@@ -38,18 +40,18 @@ class _HomePageState extends State<HomePage> {
|
||||
onDestinationSelected: (int index) =>
|
||||
setState(() => _selectedIndex = index),
|
||||
labelType: NavigationRailLabelType.all,
|
||||
destinations: const [
|
||||
destinations: [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.explore),
|
||||
label: Text('Explore'),
|
||||
icon: const Icon(Icons.explore),
|
||||
label: Text(l10n.explore),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.videocam),
|
||||
label: Text('Console'),
|
||||
icon: const Icon(Icons.videocam),
|
||||
label: Text(l10n.console),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.settings),
|
||||
label: Text('Settings'),
|
||||
icon: const Icon(Icons.settings),
|
||||
label: Text(l10n.settings),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -61,18 +63,18 @@ class _HomePageState extends State<HomePage> {
|
||||
selectedIndex: _selectedIndex,
|
||||
onDestinationSelected: (int index) =>
|
||||
setState(() => _selectedIndex = index),
|
||||
destinations: const [
|
||||
destinations: [
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.explore),
|
||||
label: 'Explore',
|
||||
icon: const Icon(Icons.explore),
|
||||
label: l10n.explore,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.videocam),
|
||||
label: 'Console',
|
||||
icon: const Icon(Icons.videocam),
|
||||
label: l10n.console,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.settings),
|
||||
label: 'Settings',
|
||||
icon: const Icon(Icons.settings),
|
||||
label: l10n.settings,
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -131,9 +133,10 @@ class _ExploreViewState extends State<_ExploreView> {
|
||||
}
|
||||
} catch (e) {
|
||||
if (!isAuto && mounted) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text("Failed to load rooms")));
|
||||
).showSnackBar(SnackBar(content: Text(l10n?.failedToLoadRooms ?? "Failed to load rooms")));
|
||||
}
|
||||
} finally {
|
||||
if (!isAuto && mounted) setState(() => _isLoading = false);
|
||||
@@ -141,20 +144,21 @@ class _ExploreViewState extends State<_ExploreView> {
|
||||
}
|
||||
|
||||
Future<void> _confirmLogout() async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Logout'),
|
||||
content: const Text('Are you sure you want to log out now?'),
|
||||
title: Text(l10n.confirmLogout),
|
||||
content: Text(l10n.confirmLogoutDesc),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Cancel'),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('Logout'),
|
||||
child: Text(l10n.logout),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -169,44 +173,45 @@ class _ExploreViewState extends State<_ExploreView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settings = context.watch<SettingsProvider>();
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Explore", style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
title: Text(l10n.explore, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.refresh),
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () => _refreshRooms(),
|
||||
),
|
||||
IconButton(icon: Icon(Icons.logout), onPressed: _confirmLogout),
|
||||
IconButton(icon: const Icon(Icons.logout), onPressed: _confirmLogout),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: widget.onGoLive,
|
||||
label: Text("Go Live"),
|
||||
icon: Icon(Icons.videocam),
|
||||
label: Text(l10n.goLive),
|
||||
icon: const Icon(Icons.videocam),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: _refreshRooms,
|
||||
child: _isLoading && _activeRooms.isEmpty
|
||||
? Center(child: CircularProgressIndicator())
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _activeRooms.isEmpty
|
||||
? ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 100),
|
||||
padding: const EdgeInsets.only(top: 100),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
const Icon(
|
||||
Icons.live_tv_outlined,
|
||||
size: 80,
|
||||
color: Colors.grey,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
"No active rooms. Be the first!",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 16),
|
||||
l10n.noActiveRooms,
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -214,8 +219,8 @@ class _ExploreViewState extends State<_ExploreView> {
|
||||
],
|
||||
)
|
||||
: GridView.builder(
|
||||
padding: EdgeInsets.all(12),
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
padding: const EdgeInsets.all(12),
|
||||
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 400,
|
||||
childAspectRatio: 1.2,
|
||||
crossAxisSpacing: 12,
|
||||
@@ -224,14 +229,14 @@ class _ExploreViewState extends State<_ExploreView> {
|
||||
itemCount: _activeRooms.length,
|
||||
itemBuilder: (context, index) {
|
||||
final room = _activeRooms[index];
|
||||
return _buildRoomCard(room, settings);
|
||||
return _buildRoomCard(room, settings, l10n);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRoomCard(dynamic room, SettingsProvider settings) {
|
||||
Widget _buildRoomCard(dynamic room, SettingsProvider settings, AppLocalizations l10n) {
|
||||
final roomId = room['room_id'].toString();
|
||||
return Card(
|
||||
elevation: 4,
|
||||
@@ -294,12 +299,12 @@ class _ExploreViewState extends State<_ExploreView> {
|
||||
top: 8,
|
||||
left: 8,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.circle, size: 8, color: Colors.white),
|
||||
SizedBox(width: 4),
|
||||
@@ -331,7 +336,7 @@ class _ExploreViewState extends State<_ExploreView> {
|
||||
radius: 16,
|
||||
child: Text(room['user_id'].toString().substring(0, 1)),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -341,14 +346,14 @@ class _ExploreViewState extends State<_ExploreView> {
|
||||
room['title'],
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"Host ID: ${room['user_id']}",
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
"${l10n.hostId}: ${room['user_id']}",
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user