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
+18 -13
View File
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../viewmodels/pin_lock_view_model.dart';
import '../l10n/app_localizations.dart';
import '../l10n/app_localizations_helpers.dart';
enum PinEntryMode { unlock, create }
@@ -30,16 +32,14 @@ class _PinEntryViewState extends State<PinEntryView> {
bool get _isCreateFlow => widget.mode == PinEntryMode.create;
String get _title {
if (!_isCreateFlow) return 'Enter PIN';
return _isConfirmStep ? 'Confirm PIN' : 'Create a PIN';
String _title(AppLocalizations l10n) {
if (!_isCreateFlow) return l10n.enterPin;
return _isConfirmStep ? l10n.confirmPin : l10n.createPin;
}
String? get _subtitle {
String? _subtitle(AppLocalizations l10n) {
if (!_isCreateFlow) return null;
return _isConfirmStep
? 'Enter the same PIN again'
: 'Youʼll use this to unlock the app';
return _isConfirmStep ? l10n.confirmPinSubtitle : l10n.enterPinSubtitle;
}
void _onDigitPressed(String digit) {
@@ -65,6 +65,7 @@ class _PinEntryViewState extends State<PinEntryView> {
Future<void> _handleComplete() async {
final viewModel = context.read<PinLockViewModel>();
final l10n = AppLocalizations.of(context);
if (_isCreateFlow && !_isConfirmStep) {
// First entry of a new PIN — stash it, then ask for confirmation.
@@ -84,7 +85,7 @@ class _PinEntryViewState extends State<PinEntryView> {
_firstEntry = null;
_isConfirmStep = false;
});
_fail('PINs didnʼt match. Try again.');
_fail(l10n.pinsDidNotMatch);
return;
}
@@ -100,7 +101,7 @@ class _PinEntryViewState extends State<PinEntryView> {
_firstEntry = null;
_isConfirmStep = false;
});
_fail(viewModel.errorMessage ?? 'Something went wrong.');
_fail(l10n.localizedError(viewModel.errorMessage));
}
return;
}
@@ -114,7 +115,7 @@ class _PinEntryViewState extends State<PinEntryView> {
if (ok) {
widget.onSuccess?.call();
} else {
_fail(viewModel.errorMessage ?? 'Incorrect PIN.');
_fail(l10n.localizedError(viewModel.errorMessage));
}
}
@@ -133,6 +134,7 @@ class _PinEntryViewState extends State<PinEntryView> {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final l10n = AppLocalizations.of(context);
return Scaffold(
body: SafeArea(
@@ -143,11 +145,14 @@ class _PinEntryViewState extends State<PinEntryView> {
const Spacer(flex: 2),
Icon(Icons.lock_outline_rounded, size: 36, color: scheme.primary),
const SizedBox(height: 16),
Text(_title, style: Theme.of(context).textTheme.headlineMedium),
if (_subtitle != null) ...[
Text(
_title(l10n),
style: Theme.of(context).textTheme.headlineMedium,
),
if (_subtitle(l10n) != null) ...[
const SizedBox(height: 6),
Text(
_subtitle!,
_subtitle(l10n)!,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium,
),