Skip to content

Commit 609f3d0

Browse files
committed
fix: 修复语言
1 parent 8017144 commit 609f3d0

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

lib/main.dart

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22
import 'dart:convert';
33
import 'dart:io';
44
import 'dart:ui' show FlutterView;
5+
import 'package:flutter/cupertino.dart' show CupertinoLocalizations;
56
import 'package:flutter/foundation.dart' show kIsWeb;
67
import 'package:flutter/material.dart';
78
import 'package:flutter_localizations/flutter_localizations.dart';
@@ -245,6 +246,41 @@ class _StartupRecoveryResult {
245246
});
246247
}
247248

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

500536
return MaterialApp.router(
501537
routerConfig: _router,
502-
onGenerateTitle: (context) => AppLocalizations.of(context)!.appName,
538+
onGenerateTitle: (context) => AppLocalizations.of(context)?.appName ?? '',
503539
debugShowCheckedModeBanner: false,
504540
localizationsDelegates: const [
505541
AppLocalizations.delegate,
542+
_OchMaterialLocalizationsDelegate(),
543+
_OchCupertinoLocalizationsDelegate(),
506544
GlobalMaterialLocalizations.delegate,
507545
GlobalWidgetsLocalizations.delegate,
508546
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)