Skip to content

Commit 7d4ba6f

Browse files
committed
refactor(i18n): Simplify localization structure and implementation
Refactored the localization implementation by removing the custom `i18n` function in favor of the standard `.tr()` method from the `easy_localization` package. Key changes: - Simplified the `zh-CN.yaml` translation file by flattening the nested structure under the `action` key. - Updated `lib/core/i18n.dart` to use `key.tr()` for translations, streamlining the localization process. - Added a `loadVanilla()` call in `main.dart` during the app's initialization sequence.
1 parent a71ff16 commit 7d4ba6f

File tree

3 files changed

+15
-34
lines changed

3 files changed

+15
-34
lines changed

assets/l10n/zh-CN.yaml

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,42 +109,20 @@ attribute:
109109
energy: 体力
110110
action:
111111
# Move forward
112-
move:
113-
name: 移动 # no direction specified
114-
left: 向左移动
115-
right: 向右移动
116-
up: 向上移动
117-
down: 向下移动
118-
forward: 向前移动
119-
backward: 向后移动
112+
move: 移动
120113
# Explore the surroundings
121-
explore:
122-
name: 探索
123-
gather:
124-
name: 采集
125-
get-water: 取水
126-
get-wood: 伐木
127-
get-food: 觅食
128-
hunt:
129-
name: 打猎
130-
trap: 带上陷阱
131-
gun: 带上猎枪
132-
# Go fishing
133-
fish:
134-
name: 捕鱼
114+
explore: 探索
115+
gather: 采集
116+
get-water: 取水
117+
get-wood: 伐木
118+
get-food: 觅食
119+
hunt: 打猎
120+
fish: 捕鱼
135121
# When player win the game
136-
escape-wild:
137-
name: 逃离荒野
122+
escape-wild: 逃离荒野
138123
# When player lose the game
139-
stop-heartbeat:
140-
name: 将死之人
141-
shelter:
142-
name: 休息
143-
sleep-till-tomorrow: 睡到明天
144-
# Reinforce the shelter
145-
reinforce: 加固避难所
146-
# Have a rest
147-
rest: 休息
124+
stop-heartbeat: 将死之人
125+
shelter: 休息
148126
use-type:
149127
use: 使用
150128
eat: 食用

lib/core/i18n.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import 'package:easy_localization/easy_localization.dart';
2+
13
String i18n(String key) {
2-
return key;
4+
return key.tr();
35
// return I18n.get(i18nNamespace, key);
46
}

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void main() async {
1919
await Hive.initFlutter(R.hiveDir);
2020
}
2121
await DB.init();
22+
loadVanilla();
2223
registerConverter();
2324
initPreference();
2425
runApp(const EscapeWildApp().withEasyLocalization());

0 commit comments

Comments
 (0)