@@ -32,28 +32,28 @@ class LocaleProvider with ChangeNotifier {
3232 if (systemLocales.isNotEmpty) {
3333 final systemLocale = systemLocales.first;
3434 final languageCode = systemLocale.languageCode;
35-
35+
3636 // 如果系统语言是中文
3737 if (languageCode == 'zh' ) {
38- // 如果是繁体中文地区,返回繁体中文
39- if (systemLocale.countryCode == 'TW' ||
40- systemLocale.countryCode == 'HK' ||
38+ // 如果是正體中文地区,返回正體中文
39+ if (systemLocale.countryCode == 'TW' ||
40+ systemLocale.countryCode == 'HK' ||
4141 systemLocale.countryCode == 'MO' ) {
42- return const Locale ('zh' , 'HK ' );
42+ return const Locale ('zh' , 'TW ' );
4343 }
4444 // 其他中文地区返回简体中文
4545 return const Locale ('zh' );
4646 }
47-
47+
4848 // 如果系统语言是日语
4949 if (languageCode == 'ja' ) {
5050 return const Locale ('ja' );
5151 }
52-
52+
5353 // 其他所有语言(非中文、非日文)默认返回英文
5454 return const Locale ('en' );
5555 }
56-
56+
5757 // 如果无法获取系统语言,默认返回英文
5858 return const Locale ('en' );
5959 }
@@ -63,11 +63,11 @@ class LocaleProvider with ChangeNotifier {
6363 // SharedPreferences 在 Web 上会自动处理 'flutter.' 前缀
6464 final followSystemSetting = prefs.getBool ('follow_system_locale' );
6565 final localeCode = prefs.getString ('locale' );
66-
66+
6767 if (followSystemSetting == false && localeCode != null ) {
6868 // 用户明确设置了语言
6969 _followSystem = false ;
70- // 解析语言代码(支持 zh_HK 格式)
70+ // 解析语言代码(支持 zh_TW 格式)
7171 final parts = localeCode.split ('_' );
7272 if (parts.length == 2 ) {
7373 _locale = Locale (parts[0 ], parts[1 ]);
@@ -85,22 +85,22 @@ class LocaleProvider with ChangeNotifier {
8585 /// 设置语言(传入null表示跟随系统)
8686 Future <void > setLocale (Locale ? locale) async {
8787 if (_locale == locale && _followSystem == (locale == null )) return ;
88-
88+
8989 _locale = locale;
9090 _followSystem = locale == null ;
91-
91+
9292 final prefs = await SharedPreferences .getInstance ();
9393 await prefs.setBool ('follow_system_locale' , _followSystem);
9494 if (locale != null ) {
95- // 保存完整的语言代码(包括国家代码,如 zh_HK )
96- final localeString = locale.countryCode != null
95+ // 保存完整的语言代码(包括国家代码,如 zh_TW )
96+ final localeString = locale.countryCode != null
9797 ? '${locale .languageCode }_${locale .countryCode }'
9898 : locale.languageCode;
9999 await prefs.setString ('locale' , localeString);
100100 } else {
101101 await prefs.remove ('locale' );
102102 }
103-
103+
104104 notifyListeners ();
105105 }
106106}
0 commit comments