l10n_extensions.dart
3.74 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
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);
}
/// 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 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, 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;
}
}