feat: English and Chinese, and selectable chat text
- settings → general → language picks system, Chinese or English; the choice is stored on the device and read before the first frame - our Chinese strings are translated through tr()/trArgs() and AppText, with the English in lib/l10n/en_*.dart; a missing entry falls back to Chinese and a test checks that every literal in lib has one - AppText rebuilds on a language change (it depends on the resolved locale), so const text and whole pages switch at once; the built-in date/time pickers and selection menu follow the same language - server and user data (titles, messages, prompts, paths) is never translated - the chat list sits in a SelectionArea: long-press selects message text and shows the copy/select-all menu - bump to 0.5.2
This commit is contained in:
1 parent
da4bfb6826
commit
7b5bccf28f
42 files changed
+1943
-735
No files matched your search
@@ -10,6 +10,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../l10n.dart';
|
||||
import 'pet_pack.dart';
|
||||
|
||||
class PetImportException implements Exception {
|
||||
@@ -110,16 +111,16 @@ class PetLibrary extends ChangeNotifier {
|
||||
/// Unpacks and activates a pet package. [root] is for tests; the app uses
|
||||
/// the documents directory.
|
||||
Future<PetPack> importZip(List<int> bytes, {Directory? root}) async {
|
||||
if (bytes.isEmpty) throw const PetImportException('文件为空');
|
||||
if (bytes.isEmpty) throw PetImportException(tr('文件为空'));
|
||||
if (bytes.length > 40 * 1024 * 1024) {
|
||||
throw const PetImportException('宠物包不能超过 40MB');
|
||||
throw PetImportException(tr('宠物包不能超过 40MB'));
|
||||
}
|
||||
|
||||
final Archive archive;
|
||||
try {
|
||||
archive = ZipDecoder().decodeBytes(bytes, verify: true);
|
||||
} catch (_) {
|
||||
throw const PetImportException('不是有效的 zip 文件');
|
||||
throw PetImportException(tr('不是有效的 zip 文件'));
|
||||
}
|
||||
|
||||
ArchiveFile? manifest;
|
||||
@@ -133,7 +134,7 @@ class PetLibrary extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
if (manifest == null) {
|
||||
throw const PetImportException('压缩包里没有 pack.json');
|
||||
throw PetImportException(tr('压缩包里没有 pack.json'));
|
||||
}
|
||||
|
||||
final manifestName = manifest.name.replaceAll('\\', '/');
|
||||
@@ -148,10 +149,10 @@ class PetLibrary extends ChangeNotifier {
|
||||
if (json is! Map<String, dynamic>) throw const FormatException();
|
||||
parsed = PetPack.fromJson(json);
|
||||
} catch (_) {
|
||||
throw const PetImportException('pack.json 不是有效的宠物包');
|
||||
throw PetImportException(tr('pack.json 不是有效的宠物包'));
|
||||
}
|
||||
if (!parsed.isValid) {
|
||||
throw const PetImportException('pack.json 缺少动画或状态');
|
||||
throw PetImportException(tr('pack.json 缺少动画或状态'));
|
||||
}
|
||||
|
||||
final id = _safeId(parsed.id.isNotEmpty ? parsed.id : parsed.name);
|
||||
@@ -174,7 +175,7 @@ class PetLibrary extends ChangeNotifier {
|
||||
final content = _content(file);
|
||||
extracted += content.length;
|
||||
if (extracted > 60 * 1024 * 1024) {
|
||||
throw const PetImportException('解压后超过 60MB');
|
||||
throw PetImportException(tr('解压后超过 60MB'));
|
||||
}
|
||||
final target = File('${staging.path}/$rel');
|
||||
await target.parent.create(recursive: true);
|
||||
@@ -183,11 +184,11 @@ class PetLibrary extends ChangeNotifier {
|
||||
|
||||
for (final animation in parsed.animations.values) {
|
||||
if (animation.sheet.isEmpty) {
|
||||
throw PetImportException('动画 ${animation.name} 没有精灵图');
|
||||
throw PetImportException(trArgs('动画 {0} 没有精灵图', [animation.name]));
|
||||
}
|
||||
final sheet = File('${staging.path}/${animation.sheet}');
|
||||
if (!await sheet.exists()) {
|
||||
throw PetImportException('缺少精灵图 ${animation.sheet}');
|
||||
throw PetImportException(trArgs('缺少精灵图 {0}', [animation.sheet]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user