Skip to content

Commit 1035a30

Browse files
committed
fix: 修复语言
1 parent 8017144 commit 1035a30

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

lib/main.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,41 @@ class _StartupRecoveryResult {
245245
});
246246
}
247247

248+
/// Provides Material localizations for the [och] language code by proxying
249+
/// to Simplified Chinese, since [GlobalMaterialLocalizations] does not support
250+
/// ISO 639-3 codes like [och].
251+
class _OchMaterialLocalizationsDelegate
252+
extends LocalizationsDelegate<MaterialLocalizations> {
253+
const _OchMaterialLocalizationsDelegate();
254+
255+
@override
256+
bool isSupported(Locale locale) => locale.languageCode == 'och';
257+
258+
@override
259+
Future<MaterialLocalizations> load(Locale locale) =>
260+
GlobalMaterialLocalizations.delegate.load(const Locale('zh'));
261+
262+
@override
263+
bool shouldReload(_OchMaterialLocalizationsDelegate old) => false;
264+
}
265+
266+
/// Provides Cupertino localizations for the [och] language code by proxying
267+
/// to Simplified Chinese, for the same reason as [_OchMaterialLocalizationsDelegate].
268+
class _OchCupertinoLocalizationsDelegate
269+
extends LocalizationsDelegate<CupertinoLocalizations> {
270+
const _OchCupertinoLocalizationsDelegate();
271+
272+
@override
273+
bool isSupported(Locale locale) => locale.languageCode == 'och';
274+
275+
@override
276+
Future<CupertinoLocalizations> load(Locale locale) =>
277+
GlobalCupertinoLocalizations.delegate.load(const Locale('zh'));
278+
279+
@override
280+
bool shouldReload(_OchCupertinoLocalizationsDelegate old) => false;
281+
}
282+
248283
class TouchFishApp extends StatefulWidget {
249284
final bool isFirstLaunch;
250285
final bool hasSavedSession;
@@ -499,10 +534,12 @@ class _TouchFishAppState extends State<TouchFishApp> {
499534

500535
return MaterialApp.router(
501536
routerConfig: _router,
502-
onGenerateTitle: (context) => AppLocalizations.of(context)!.appName,
537+
onGenerateTitle: (context) => AppLocalizations.of(context)?.appName ?? '',
503538
debugShowCheckedModeBanner: false,
504539
localizationsDelegates: const [
505540
AppLocalizations.delegate,
541+
_OchMaterialLocalizationsDelegate(),
542+
_OchCupertinoLocalizationsDelegate(),
506543
GlobalMaterialLocalizations.delegate,
507544
GlobalWidgetsLocalizations.delegate,
508545
GlobalCupertinoLocalizations.delegate,

lib/screens/settings_screen.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,8 @@ class _SettingsScreenState extends State<SettingsScreen>
10061006
return l10n.settingsLanguageZh;
10071007
case 'settingsLanguageEn':
10081008
return l10n.settingsLanguageEn;
1009+
case 'settingsLanguageCc':
1010+
return l10n.settingsLanguageCc;
10091011
case 'settingsThemeTitle':
10101012
return l10n.settingsThemeTitle;
10111013
case 'settingsThemeDesc':

0 commit comments

Comments
 (0)