flutter: intl: Fix string tapBackAgainToLeave when locale is not en

This commit is contained in:
Calcitem 2021-05-25 22:47:06 +08:00
parent 4f625bc850
commit 4c54ace4c0
2 changed files with 65 additions and 2 deletions

View File

@ -0,0 +1,62 @@
/*
This file is part of Sanmill.
Copyright (C) 2019-2021 The Sanmill developers (see AUTHORS file)
Sanmill is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Sanmill is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:io';
/// Interface strings
abstract class Strings {
String get tapBackAgainToLeave;
}
/// English strings
class EnglishStrings extends Strings {
@override
String get tapBackAgainToLeave => 'Tap back again to leave.';
}
/// German strings
class GermanStrings extends Strings {
@override
String get tapBackAgainToLeave => 'Nochmal drücken um zu Beenden.';
}
/// Chinese strings
class ChineseStrings extends Strings {
@override
String get tapBackAgainToLeave => '再次按返回键退出应用';
}
class Resources {
Resources();
Strings get strings {
String deviceLanguage = Platform.localeName.substring(0, 2);
switch (deviceLanguage) {
case 'de':
return GermanStrings();
case 'zh':
return ChineseStrings();
default:
return EnglishStrings();
}
}
static Resources of() {
return Resources();
}
}

View File

@ -26,6 +26,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/services/audios.dart';
import 'package:sanmill/style/app_theme.dart';
import 'package:sanmill/widgets/navigation_home_screen.dart';
@ -146,8 +147,8 @@ class _SanmillAppState extends State<SanmillApp> {
home: Scaffold(
body: DoubleBackToCloseApp(
child: NavigationHomeScreen(),
snackBar: const SnackBar(
content: Text('Tap back again to leave.'),
snackBar: SnackBar(
content: Text(Resources.of().strings.tapBackAgainToLeave),
),
),
),