From 4212aaaae90dc878ce6aec525588a0b7e1840296 Mon Sep 17 00:00:00 2001 From: Liplum Date: Fri, 22 Mar 2024 09:34:04 +0800 Subject: [PATCH] [minesweeper] i18n of game over --- assets/l10n/en.yaml | 12 ++++-------- assets/l10n/zh-Hans.yaml | 12 ++++-------- assets/l10n/zh-Hant.yaml | 12 ++++-------- lib/game/2048/i18n.dart | 11 ++--------- lib/game/i18n.dart | 17 +++++++++++++---- lib/game/minesweeper/i18n.dart | 9 +++------ lib/game/minesweeper/widget/info.dart | 10 +++++++--- 7 files changed, 37 insertions(+), 46 deletions(-) diff --git a/assets/l10n/en.yaml b/assets/l10n/en.yaml index 9ef275e79..a4f738492 100644 --- a/assets/l10n/en.yaml +++ b/assets/l10n/en.yaml @@ -755,22 +755,18 @@ game: navigation: Game newGame: New game continueGame: Continue + tryAgain: Try again + youWin: You win + gameOver: Game over 2048: title: 2048 score: Score best: Best - newGame: New game - tryAgain: Try again - youWin: You win - gameOver: Game over minesweeper: title: Minesweeper + timeSpent: "You spent {}" gameMode: easy: Easy - gameOver: - failed: Failed - won: Won - restart: Restart dormitoryRoom: "Building {building} #{room}" open: Open delete: Delete diff --git a/assets/l10n/zh-Hans.yaml b/assets/l10n/zh-Hans.yaml index e8c33f77b..ff815972a 100644 --- a/assets/l10n/zh-Hans.yaml +++ b/assets/l10n/zh-Hans.yaml @@ -755,22 +755,18 @@ game: navigation: 游戏 newGame: 新游戏 continueGame: 继续游戏 + tryAgain: 再试一次 + youWin: 你赢了! + gameOver: 游戏结束 2048: title: 2048 score: 分数 best: 最佳 - newGame: 新游戏 - tryAgain: 再试一次 - youWin: 你赢了! - gameOver: 游戏结束 minesweeper: title: 扫雷 + timeSpent: "用时 {}" gameMode: easy: 简单 - gameOver: - failed: 失败 - won: 获胜 - restart: 再试一次 dormitoryRoom: "{building}号楼 #{room}" open: 打开 delete: 删除 diff --git a/assets/l10n/zh-Hant.yaml b/assets/l10n/zh-Hant.yaml index 19c8e25d9..6229e8cc7 100644 --- a/assets/l10n/zh-Hant.yaml +++ b/assets/l10n/zh-Hant.yaml @@ -755,22 +755,18 @@ game: navigation: 電玩 newGame: 新遊戲 continueGame: 繼續 + tryAgain: 再試一次 + youWin: 你獲勝了! + gameOver: Game over 2048: title: 2048 score: 分數 best: 最佳 - newGame: 新遊戲 - tryAgain: 再試一次 - youWin: 你獲勝了! - gameOver: Game over minesweeper: title: 掃雷 + timeSpent: "用時 {}" gameMode: easy: 簡單 - gameOver: - failed: 失敗 - won: 勝利 - restart: 再玩一次 dormitoryRoom: "{building}號樓 #{room}" open: 打開 delete: 刪除 diff --git a/lib/game/2048/i18n.dart b/lib/game/2048/i18n.dart index d3e808241..e552e4f1d 100644 --- a/lib/game/2048/i18n.dart +++ b/lib/game/2048/i18n.dart @@ -1,9 +1,10 @@ import 'package:easy_localization/easy_localization.dart'; +import 'package:sit/game/i18n.dart'; import 'package:sit/l10n/common.dart'; const i18n = _I18n(); -class _I18n with CommonI18nMixin { +class _I18n with CommonI18nMixin, CommonGameI18nMixin { const _I18n(); static const ns = "game.2048"; @@ -13,12 +14,4 @@ class _I18n with CommonI18nMixin { String get score => "$ns.score".tr(); String get best => "$ns.best".tr(); - - String get newGame => "$ns.newGame".tr(); - - String get tryAgain => "$ns.tryAgain".tr(); - - String get youWin => "$ns.youWin".tr(); - - String get gameOver => "$ns.gameOver".tr(); } diff --git a/lib/game/i18n.dart b/lib/game/i18n.dart index 76a093e12..96d52e1c6 100644 --- a/lib/game/i18n.dart +++ b/lib/game/i18n.dart @@ -2,15 +2,24 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:sit/l10n/common.dart'; const i18n = _I18n(); +const _ns = "game"; class _I18n with CommonI18nMixin { const _I18n(); - static const ns = "game"; + String get navigation => "$_ns.navigation".tr(); - String get navigation => "$ns.navigation".tr(); + String get newGame => "$_ns.newGame".tr(); - String get newGame => "$ns.newGame".tr(); + String get continueGame => "$_ns.continueGame".tr(); +} + +mixin class CommonGameI18nMixin { + String get newGame => "$_ns.newGame".tr(); + + String get tryAgain => "$_ns.tryAgain".tr(); + + String get youWin => "$_ns.youWin".tr(); - String get continueGame => "$ns.continueGame".tr(); + String get gameOver => "$_ns.gameOver".tr(); } diff --git a/lib/game/minesweeper/i18n.dart b/lib/game/minesweeper/i18n.dart index bd61d9613..41e9fbde3 100644 --- a/lib/game/minesweeper/i18n.dart +++ b/lib/game/minesweeper/i18n.dart @@ -1,21 +1,18 @@ import 'package:easy_localization/easy_localization.dart'; +import 'package:sit/game/i18n.dart'; import 'package:sit/game/minesweeper/model/mode.dart'; import 'package:sit/l10n/common.dart'; const i18n = _I18n(); -class _I18n with CommonI18nMixin { +class _I18n with CommonI18nMixin, CommonGameI18nMixin { const _I18n(); static const ns = "game.minesweeper"; String get title => "$ns.title".tr(); - String get gameOverFailed => "$ns.gameOver.failed".tr(); - - String get gameOverWon => "$ns.gameOver.won".tr(); - - String get restart => "$ns.restart".tr(); + String timeSpent(String time) => "$ns.timeSpent".tr(args: [time]); } extension GameModeI18nX on GameMode { diff --git a/lib/game/minesweeper/widget/info.dart b/lib/game/minesweeper/widget/info.dart index 1cfb3acde..61bda3b78 100644 --- a/lib/game/minesweeper/widget/info.dart +++ b/lib/game/minesweeper/widget/info.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import '../manager/logic.dart'; import '../manager/timer.dart'; import '../theme.dart'; +import '../i18n.dart'; class GameOverModal extends ConsumerWidget { const GameOverModal({ @@ -38,8 +39,11 @@ class GameOverModal extends ConsumerWidget { resetGame(); }, child: Text( - "Game Over!\n Click To Restart", - style: TextStyle(color: gameOverTextColor, fontSize: textSize), + i18n.gameOver, + style: TextStyle( + color: gameOverTextColor, + fontSize: textSize, + ), ), ), ), @@ -65,7 +69,7 @@ class GameOverModal extends ConsumerWidget { resetGame(); }, child: Text( - " You Win!\n Time: $costTime \n Click To Play Again", + "${i18n.youWin}\n${i18n.timeSpent(costTime)}", style: TextStyle(color: goodGameTextColor, fontSize: textSize), ), ),