feat(frontend): add multi-language support (en, zh-Hans, zh-Hant, ja)

This commit is contained in:
2026-05-25 11:49:53 +08:00
parent 1539e495e6
commit 261b1ab169
20 changed files with 1955 additions and 139 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../l10n/app_localizations.dart';
import '../providers/settings_provider.dart';
import '../services/api_service.dart';
@@ -15,8 +16,9 @@ class _RegisterPageState extends State<RegisterPage> {
bool _isLoading = false;
void _handleRegister() async {
final l10n = AppLocalizations.of(context)!;
if (_usernameController.text.isEmpty || _passwordController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Please fill in all fields")));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(l10n.fillAllFields)));
return;
}
@@ -27,14 +29,14 @@ class _RegisterPageState extends State<RegisterPage> {
try {
final response = await api.register(_usernameController.text, _passwordController.text);
if (response.statusCode == 201) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Account created! Please login.")));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(l10n.accountCreated)));
Navigator.pop(context);
} else {
final error = jsonDecode(response.body)['error'] ?? "Registration Failed";
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(error)));
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Network Error")));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(l10n.networkError)));
} finally {
if (mounted) setState(() => _isLoading = false);
}
@@ -42,42 +44,43 @@ class _RegisterPageState extends State<RegisterPage> {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
return Scaffold(
appBar: AppBar(title: Text("Create Account")),
appBar: AppBar(title: Text(l10n.createAccount)),
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 400),
constraints: const BoxConstraints(maxWidth: 400),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person_add_outlined, size: 64, color: Theme.of(context).colorScheme.primary),
SizedBox(height: 24),
const SizedBox(height: 24),
Text(
"Join Hightube",
l10n.joinHightube,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(fontWeight: FontWeight.bold),
),
SizedBox(height: 48),
const SizedBox(height: 48),
TextField(
controller: _usernameController,
decoration: InputDecoration(
labelText: "Desired Username",
prefixIcon: Icon(Icons.person),
labelText: l10n.desiredUsername,
prefixIcon: const Icon(Icons.person),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
),
),
SizedBox(height: 16),
const SizedBox(height: 16),
TextField(
controller: _passwordController,
obscureText: true,
decoration: InputDecoration(
labelText: "Password",
prefixIcon: Icon(Icons.lock),
labelText: l10n.password,
prefixIcon: const Icon(Icons.lock),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
),
),
SizedBox(height: 32),
const SizedBox(height: 32),
SizedBox(
width: double.infinity,
height: 50,
@@ -86,13 +89,13 @@ class _RegisterPageState extends State<RegisterPage> {
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
child: _isLoading ? CircularProgressIndicator() : Text("REGISTER", style: TextStyle(fontWeight: FontWeight.bold)),
child: _isLoading ? const CircularProgressIndicator() : Text(l10n.register, style: const TextStyle(fontWeight: FontWeight.bold)),
),
),
SizedBox(height: 16),
const SizedBox(height: 16),
TextButton(
onPressed: () => Navigator.pop(context),
child: Text("Already have an account? Login here"),
child: Text(l10n.alreadyHaveAccount),
),
],
),