From 29bdc5afed3bd1b7169bdd309b2b46f234ddf5da Mon Sep 17 00:00:00 2001 From: Sandip Pramanik Date: Thu, 8 Aug 2024 09:28:21 +0530 Subject: [PATCH] fix: replace hard-coded strings with l10n (#10) --- lib/home/widgets/player_info.dart | 26 ++++++++++++++------------ lib/l10n/arb/app_en.arb | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/home/widgets/player_info.dart b/lib/home/widgets/player_info.dart index 549bfb7..0b2ddeb 100644 --- a/lib/home/widgets/player_info.dart +++ b/lib/home/widgets/player_info.dart @@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:sudoku/assets/assets.dart'; import 'package:sudoku/colors/colors.dart'; import 'package:sudoku/home/home.dart'; +import 'package:sudoku/l10n/l10n.dart'; import 'package:sudoku/layout/layout.dart'; import 'package:sudoku/typography/typography.dart'; import 'package:sudoku/widgets/widgets.dart'; @@ -12,6 +13,7 @@ class PlayerInfoWidget extends StatelessWidget { @override Widget build(BuildContext context) { + final l10n = context.l10n; final player = context.select((HomeBloc bloc) => bloc.state.player); return ResponsiveLayoutBuilder( @@ -47,7 +49,7 @@ class PlayerInfoWidget extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.end, children: [ Text( - 'Player Stats', + l10n.playerStatsTitle, style: SudokuTextStyle.bodyText1.copyWith( fontWeight: SudokuFontWeight.bold, color: Colors.white, @@ -55,7 +57,7 @@ class PlayerInfoWidget extends StatelessWidget { maxLines: 1, ), Text( - 'Solved / Attempted', + l10n.solvedVsAttemptedText, style: SudokuTextStyle.bodyText1.copyWith( fontWeight: SudokuFontWeight.medium, fontSize: 12, @@ -68,7 +70,7 @@ class PlayerInfoWidget extends StatelessWidget { children: [ Expanded( child: AttemptedVsSolved( - label: 'Easy', + label: l10n.statsPerDifficulty('easy'), attempted: player.easyAttempted, solved: player.easySolved, ), @@ -76,7 +78,7 @@ class PlayerInfoWidget extends StatelessWidget { const SizedBox(width: 32), Expanded( child: AttemptedVsSolved( - label: 'Medium', + label: l10n.statsPerDifficulty('medium'), attempted: player.mediumAttempted, solved: player.mediumSolved, ), @@ -88,7 +90,7 @@ class PlayerInfoWidget extends StatelessWidget { children: [ Expanded( child: AttemptedVsSolved( - label: 'Difficult', + label: l10n.statsPerDifficulty('difficult'), attempted: player.difficultAttempted, solved: player.difficultSolved, ), @@ -96,7 +98,7 @@ class PlayerInfoWidget extends StatelessWidget { const SizedBox(width: 32), Expanded( child: AttemptedVsSolved( - label: 'Expert', + label: l10n.statsPerDifficulty('expert'), attempted: player.expertAttempted, solved: player.expertSolved, ), @@ -160,7 +162,7 @@ class PlayerInfoWidget extends StatelessWidget { ), const SizedBox(height: 16), Text( - 'Player Stats', + l10n.playerStatsTitle, style: titleTextStyle.copyWith( fontWeight: SudokuFontWeight.bold, color: Colors.white, @@ -168,7 +170,7 @@ class PlayerInfoWidget extends StatelessWidget { maxLines: 1, ), Text( - 'Solved / Attempted', + l10n.solvedVsAttemptedText, style: titleTextStyle.copyWith( fontWeight: SudokuFontWeight.medium, fontSize: 12, @@ -178,25 +180,25 @@ class PlayerInfoWidget extends StatelessWidget { ), const SizedBox(height: 8), AttemptedVsSolved( - label: 'Easy', + label: l10n.statsPerDifficulty('easy'), attempted: player.easyAttempted, solved: player.easySolved, ), const SizedBox(height: 2), AttemptedVsSolved( - label: 'Medium', + label: l10n.statsPerDifficulty('medium'), attempted: player.mediumAttempted, solved: player.mediumSolved, ), const SizedBox(height: 2), AttemptedVsSolved( - label: 'Difficult', + label: l10n.statsPerDifficulty('difficult'), attempted: player.difficultAttempted, solved: player.difficultSolved, ), const SizedBox(height: 2), AttemptedVsSolved( - label: 'Expert', + label: l10n.statsPerDifficulty('expert'), attempted: player.expertAttempted, solved: player.expertSolved, ), diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index cc2eafb..588e970 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -161,5 +161,22 @@ "competitionBannerCta": "Read More -->", "@competitionBannerCta": { "description": "Text shown as the CTA for Competition Banner in the Home Page" + }, + "playerStatsTitle": "Player Stats", + "@playerStatsTitle": { + "description": "Text shown in the Player Stats card in home page" + }, + "solvedVsAttemptedText": "Solved / Attempted", + "@solvedVsAttemptedText": { + "description": "Text shown as a caption in Player Stats card in Home Page" + }, + "statsPerDifficulty": "{difficulty, select, easy{Easy} medium{Medium} difficult{Difficult} expert{Expert} other{Others}}", + "@statsPerDifficulty": { + "description": "Text shown in the Player Stats card in home page", + "placeholders": { + "difficulty": { + "type": "String" + } + } } } \ No newline at end of file