feat(locale): 实现 App 启动时语言和时区自动设置
- 新增系统语言/时区读取工具函数 - SessionStore 扩展支持时区存储 - 启动流程自动检测并保存系统语言/时区 - 注册时传递语言/时区到后端 - 登录后从服务器同步语言/时区
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import 'dart:ui';
|
||||
|
||||
Locale? resolveSystemLocale(Locale systemLocale) {
|
||||
final lang = systemLocale.languageCode.toLowerCase();
|
||||
final script = systemLocale.scriptCode;
|
||||
final country = systemLocale.countryCode;
|
||||
|
||||
if (lang == 'en') {
|
||||
return const Locale('en');
|
||||
}
|
||||
|
||||
if (lang == 'zh') {
|
||||
if (script == 'Hant' ||
|
||||
country == 'TW' ||
|
||||
country == 'HK' ||
|
||||
country == 'MO') {
|
||||
return const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant');
|
||||
}
|
||||
return const Locale('zh');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Locale getSystemLocale() {
|
||||
return PlatformDispatcher.instance.locale;
|
||||
}
|
||||
Reference in New Issue
Block a user