l10n_extensions.dart
8.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import 'dart:ui' show PlatformDispatcher;
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'app_locale_resolution.dart';
import 'gen/app_localizations.dart';
export 'app_locale_resolution.dart';
export 'gen/app_localizations.dart';
/// 在 Widget build() 中通过 context 访问:context.l10n.appName
extension AppLocalizationsX on BuildContext {
AppLocalizations get l10n =>
AppLocalizations.of(this) ?? currentAppLocalizations();
}
/// 在 Controller / 无 context 场景中全局访问:l10n.appName
AppLocalizations get l10n {
final context = _safeGetContext();
final localizations = context != null ? AppLocalizations.of(context) : null;
return localizations ?? currentAppLocalizations();
}
AppLocalizations currentAppLocalizations() {
final locale = resolveAppLocale(
Get.locale ?? PlatformDispatcher.instance.locale,
AppLocalizations.supportedLocales,
);
return lookupAppLocalizations(locale);
}
/// Explicit dialog-title vocabulary. Keeping this typed prevents individual
/// reports from drifting away from the interaction-scene table.
enum InteractionSceneTitle {
todayAverageHrv,
todayRestingHeartRate,
todaySleepStatus,
todayFitnessStatus,
weekStressTrend,
monthStressTrend,
stressTrend,
yearStressTrend,
todayActivityBurn,
weekActivityBurn,
monthActivityBurn,
activityBurn,
weekSleepTime,
monthSleepTime,
sleepTime,
pkSteps,
pkCalories,
pkStandTime,
pkMonthlyResult,
}
/// Temporary compatibility getters while the checked-in localization output is
/// regenerated. Once `flutter gen-l10n` runs, the generated instance members
/// take precedence over these extension members.
extension InteractionAppLocalizations on AppLocalizations {
String interactSceneTitle(InteractionSceneTitle title, {int? year}) {
final zhHans = switch (title) {
InteractionSceneTitle.todayAverageHrv => '今日平均HRV',
InteractionSceneTitle.todayRestingHeartRate => '今日静息心率',
InteractionSceneTitle.todaySleepStatus => '今日睡眠情况',
InteractionSceneTitle.todayFitnessStatus => '今日健身情况',
InteractionSceneTitle.weekStressTrend => '本周压力趋势',
InteractionSceneTitle.monthStressTrend => '本月压力趋势',
InteractionSceneTitle.stressTrend => '压力趋势',
InteractionSceneTitle.yearStressTrend =>
'${year ?? DateTime.now().year}年压力趋势',
InteractionSceneTitle.todayActivityBurn => '今日活动消耗',
InteractionSceneTitle.weekActivityBurn => '本周活动消耗',
InteractionSceneTitle.monthActivityBurn => '本月活动消耗',
InteractionSceneTitle.activityBurn => '活动消耗',
InteractionSceneTitle.weekSleepTime => '本周入睡时间',
InteractionSceneTitle.monthSleepTime => '本月入睡时间',
InteractionSceneTitle.sleepTime => '入睡时间',
InteractionSceneTitle.pkSteps => 'PK-今日步数',
InteractionSceneTitle.pkCalories => 'PK-活动记录',
InteractionSceneTitle.pkStandTime => 'PK-站立时间',
InteractionSceneTitle.pkMonthlyResult => 'PK-本月胜率',
};
final english = switch (title) {
InteractionSceneTitle.todayAverageHrv => 'Today’s average HRV',
InteractionSceneTitle.todayRestingHeartRate =>
'Today’s resting heart rate',
InteractionSceneTitle.todaySleepStatus => 'Today’s sleep',
InteractionSceneTitle.todayFitnessStatus => 'Today’s fitness',
InteractionSceneTitle.weekStressTrend => 'Weekly stress trend',
InteractionSceneTitle.monthStressTrend => 'Monthly stress trend',
InteractionSceneTitle.stressTrend => 'Stress trend',
InteractionSceneTitle.yearStressTrend =>
'${year ?? DateTime.now().year} stress trend',
InteractionSceneTitle.todayActivityBurn => 'Today’s activity burn',
InteractionSceneTitle.weekActivityBurn => 'Weekly activity burn',
InteractionSceneTitle.monthActivityBurn => 'Monthly activity burn',
InteractionSceneTitle.activityBurn => 'Activity burn',
InteractionSceneTitle.weekSleepTime => 'Weekly sleep time',
InteractionSceneTitle.monthSleepTime => 'Monthly sleep time',
InteractionSceneTitle.sleepTime => 'Sleep time',
InteractionSceneTitle.pkSteps => 'PK - today’s steps',
InteractionSceneTitle.pkCalories => 'PK - activity record',
InteractionSceneTitle.pkStandTime => 'PK - standing time',
InteractionSceneTitle.pkMonthlyResult => 'PK - monthly win rate',
};
return switch (localeName) {
'zh' || 'zh_Hans' => zhHans,
'zh_Hant' =>
zhHans
.replaceAll('压力', '壓力')
.replaceAll('静息', '靜息')
.replaceAll('情况', '情況')
.replaceAll('活动', '活動')
.replaceAll('站立', '站立')
.replaceAll('胜率', '勝率'),
_ => english,
};
}
String get interactActionSheetInvitation => _interactionStrings.$1;
String get interactTodaySteps => _interactionStrings.$2;
String get interactStepsUnit => _interactionStrings.$3;
String get interactActionMiss => _interactionStrings.$4;
String get interactActionStick => _interactionStrings.$5;
String get interactActionPunch => _interactionStrings.$6;
String get interactThisWeek => switch (localeName) {
'zh' || 'zh_Hans' => '本周',
'zh_Hant' => '本週',
_ => 'This week',
};
String get interactThisMonth => switch (localeName) {
'zh' || 'zh_Hans' => '本月',
'zh_Hant' => '本月',
_ => 'This month',
};
(String, String, String, String, String, String) get _interactionStrings =>
switch (localeName) {
'zh' || 'zh_Hans' => ('快来和我互动吧~', '今日步数', '步', '想你', '戳一戳', '打一拳'),
'zh_Hant' => ('快來和我互動吧~', '今日步數', '步', '想你', '戳一戳', '打一拳'),
'ja' => ('一緒に交流しよう~', '今日の歩数', '歩', '会いたい', 'つんつん', 'パンチ'),
'ko' => ('나와 함께 소통해요~', '오늘의 걸음 수', '걸음', '보고 싶어', '콕 찌르기', '주먹'),
'de' => (
'Lass uns interagieren~',
'Heutige Schritte',
'Schritte',
'Vermisse dich',
'Anstupsen',
'Boxen',
),
'es' => (
'¡Ven a interactuar conmigo!',
'Pasos de hoy',
'pasos',
'Te extraño',
'Toquecito',
'Puñetazo',
),
'fil' => (
'Makipag-ugnayan tayo~',
'Mga hakbang ngayon',
'hakbang',
'Miss kita',
'Tapikin',
'Suntok',
),
'fr' => (
'Viens interagir avec moi~',
'Pas du jour',
'pas',
'Tu me manques',
'Taquiner',
'Coup de poing',
),
'hi' => (
'मेरे साथ इंटरैक्ट करें~',
'आज के कदम',
'कदम',
'तुम्हारी याद आती है',
'हल्का धक्का',
'मुक्का',
),
'it' => (
'Vieni a interagire con me~',
'Passi di oggi',
'passi',
'Mi manchi',
'Stuzzica',
'Pugno',
),
'nl' => (
'Kom met me interacteren~',
'Stappen van vandaag',
'stappen',
'Ik mis je',
'Prikje',
'Stoot',
),
'pt' || 'pt_BR' => (
'Venha interagir comigo~',
'Passos de hoje',
'passos',
'Sinto sua falta',
'Cutucar',
'Soco',
),
'pt_PT' => (
'Vem interagir comigo~',
'Passos de hoje',
'passos',
'Tenho saudades tuas',
'Picar',
'Soco',
),
'ru' => (
'Давай пообщаемся~',
'Шаги за сегодня',
'шагов',
'Скучаю по тебе',
'Тыкнуть',
'Ударить',
),
'tr' => (
'Benimle etkileşime geç~',
'Bugünün adımları',
'adım',
'Seni özledim',
'Dürt',
'Yumruk',
),
_ => (
'Come interact with me~',
"Today's steps",
'steps',
'Miss you',
'Poke',
'Punch',
),
};
}
BuildContext? _safeGetContext() {
try {
return Get.context;
} catch (_) {
return null;
}
}