feat(frontend): add multi-language support (en, zh-Hans, zh-Hant, ja)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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';
|
||||
@@ -29,10 +30,11 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
|
||||
void _handleLogin() 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")));
|
||||
).showSnackBar(SnackBar(content: Text(l10n.fillAllFields)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,7 +55,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
final error = jsonDecode(response.body)['error'] ?? "Login Failed";
|
||||
final error = jsonDecode(response.body)['error'] ?? l10n.loginFailed;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(error)));
|
||||
@@ -63,7 +65,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
return;
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Network Error: Could not connect to server")),
|
||||
SnackBar(content: Text(l10n.networkError)),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
@@ -72,11 +74,13 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.settings),
|
||||
icon: const Icon(Icons.settings),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const SettingsPage()),
|
||||
@@ -88,7 +92,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
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: [
|
||||
@@ -98,7 +102,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
size: 80,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
"HIGHTUBE",
|
||||
style: TextStyle(
|
||||
@@ -108,11 +112,11 @@ class _LoginPageState extends State<LoginPage> {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
const Text(
|
||||
"Open Source Live Platform",
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
SizedBox(height: 48),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
// Fields
|
||||
TextField(
|
||||
@@ -120,14 +124,14 @@ class _LoginPageState extends State<LoginPage> {
|
||||
textInputAction: TextInputAction.next,
|
||||
onSubmitted: (_) => _passwordFocusNode.requestFocus(),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Username",
|
||||
prefixIcon: Icon(Icons.person),
|
||||
labelText: l10n.username,
|
||||
prefixIcon: const Icon(Icons.person),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _passwordController,
|
||||
focusNode: _passwordFocusNode,
|
||||
@@ -139,14 +143,14 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
},
|
||||
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),
|
||||
|
||||
// Login Button
|
||||
SizedBox(
|
||||
@@ -160,14 +164,14 @@ class _LoginPageState extends State<LoginPage> {
|
||||
),
|
||||
),
|
||||
child: _isLoading
|
||||
? CircularProgressIndicator()
|
||||
? const CircularProgressIndicator()
|
||||
: Text(
|
||||
"LOGIN",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
l10n.login,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Register Link
|
||||
TextButton(
|
||||
@@ -175,7 +179,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => RegisterPage()),
|
||||
),
|
||||
child: Text("Don't have an account? Create one"),
|
||||
child: Text(l10n.dontHaveAccount),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user