feat: add localisation

This commit is contained in:
2026-07-31 21:46:05 +02:00
parent b58c9a8722
commit f5b2041612
30 changed files with 4099 additions and 326 deletions
+35 -26
View File
@@ -3,6 +3,8 @@ import 'package:go_router/go_router.dart';
import '../utils/app_update_util.dart';
import '../viewmodels/update_progress_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
class UpdateProgressView extends StatefulWidget {
final UpdateInfo update;
@@ -46,28 +48,27 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
}
void _showRestartDialog() {
final l10n = AppLocalizations.of(context);
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: const Text('Update ready'),
content: const Text(
'The update has been downloaded and installed. '
'Restart the app now to apply the changes.',
),
title: Text(l10n.updateReady),
content: Text(l10n.updateReadyDescription),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
this.context.go('/bar');
},
child: const Text('Later'),
child: Text(l10n.later),
),
FilledButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Restart app'),
child: Text(l10n.restartApp),
),
],
),
@@ -75,12 +76,14 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
}
void _showErrorSnackBar() {
final l10n = AppLocalizations.of(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(_vm.errorMessage ?? 'Update failed'),
content: Text(l10n.updateError(_vm.errorMessage)),
backgroundColor: Theme.of(context).colorScheme.error,
action: SnackBarAction(
label: 'Retry',
label: l10n.retry,
onPressed: () {
_vm.cancel();
_vm.start();
@@ -99,13 +102,15 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: () => _showCancelDialog(),
),
title: const Text('Updating'),
title: Text(l10n.updating),
centerTitle: true,
automaticallyImplyLeading: false,
),
@@ -138,6 +143,8 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
}
Widget _buildHeader() {
final l10n = AppLocalizations.of(context);
return Column(
children: [
Container(
@@ -153,13 +160,10 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
),
),
const SizedBox(height: 24),
Text(
'KoolTab',
style: Theme.of(context).textTheme.headlineMedium,
),
Text('KoolTab', style: Theme.of(context).textTheme.headlineMedium),
const SizedBox(height: 8),
Text(
'Version ${widget.update.version}',
l10n.version(widget.update.version),
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.primary,
),
@@ -170,6 +174,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
Widget _buildProgress(UpdateProgressViewModel vm) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return Column(
children: [
@@ -211,7 +216,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
),
const SizedBox(height: 4),
Text(
vm.phase == OtaPhase.installing ? 'Installing' : '',
vm.phase == OtaPhase.installing ? l10n.installing : '',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: scheme.onSurface.withValues(alpha: 0.6),
),
@@ -234,6 +239,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
Widget _buildStatus(UpdateProgressViewModel vm) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
final color = switch (vm.phase) {
OtaPhase.error => scheme.error,
@@ -242,13 +248,15 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
};
return Text(
vm.statusText,
l10n.updateStatus(vm.statusText),
style: Theme.of(context).textTheme.titleMedium?.copyWith(color: color),
textAlign: TextAlign.center,
);
}
Widget _buildVersionInfo(UpdateProgressViewModel vm) {
final l10n = AppLocalizations.of(context);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
@@ -259,9 +267,11 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
),
const SizedBox(width: 6),
Text(
'Do not close the app during the update',
l10n.doNotCloseDuringUpdate,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.4),
color: Theme.of(
context,
).colorScheme.onSurface.withValues(alpha: 0.4),
),
),
],
@@ -269,18 +279,17 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
}
void _showCancelDialog() {
final l10n = AppLocalizations.of(context);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Cancel update?'),
content: const Text(
'The update is in progress. If you leave now, '
'the app may become unstable.',
),
title: Text(l10n.cancelUpdate),
content: Text(l10n.cancelUpdateDescription),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Continue update'),
child: Text(l10n.continueUpdate),
),
FilledButton(
style: FilledButton.styleFrom(
@@ -291,7 +300,7 @@ class _UpdateProgressViewState extends State<UpdateProgressView> {
_vm.cancel();
this.context.go('/bar');
},
child: const Text('Cancel update'),
child: Text(l10n.cancelUpdateAction),
),
],
),