feat: write the UI in English, select only conversation content

- source strings are English again; Chinese comes from lib/l10n/zh.dart
  through tr()/trArgs() and AppText, and a language without a table
  (Spanish, ...) reads English instead of Chinese
- server and user data (titles, messages, file names, notes, task names)
  is drawn with plain Text, so it is never looked up in the table
- SelectionArea moved from the whole message list to the messages, the
  answer text, an opened tool call's details and the turn footer; status
  lines and folded tool rows no longer start a selection
- a message the transcript does not know (its start event was lost while
  the stream was down) fetches the tail once, so a turn continued from
  another client comes in with its prompt
- bump to 0.5.3
This commit is contained in:
blumia committed 2026-11-26 11:48:16 +08:00
1 parent 7b5bccf28f
commit 511c3b006b
43 files changed
+1620 -1791

No files matched your search

+23 -41
View File
@@ -1,44 +1,17 @@
// The app speaks Chinese and English. Our own text is written in Chinese and
// translated by lookup: `tr('保存')` in code that builds strings, `AppText`
// for the many Text leaves. `设置 → 常规 → 语言` chooses between the system
// language, Chinese and English; Chinese is the fallback for a missing entry,
// so a new string never disappears.
// The app speaks English and Chinese. Code writes English; Chinese comes from
// the table in l10n/zh.dart through tr()/trArgs(), and AppText for the many
// Text leaves. 设置 → 常规 → 语言 chooses between the system language, Chinese
// and English; a language we have no table for reads English, and a missing
// entry falls back to the English source, so text never disappears.
import 'dart:async';
import 'dart:ui' show PlatformDispatcher;
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'l10n/en_chat.dart';
import 'l10n/en_core.dart';
import 'l10n/en_servers.dart';
import 'l10n/en_sessions.dart';
import 'l10n/en_settings.dart';
import 'l10n/en_tools.dart';
import 'l10n/zh.dart';
/// Every English string, keyed by the Chinese text it replaces.
final Map<String, String> englishStrings = <String, String>{
...enCore,
...enChat,
...enSessions,
...enSettings,
...enTools,
...enServers,
};
enum AppLanguage {
system('跟随系统', 'System'),
zh('中文', '中文'),
en('English', 'English');
/// What the choice reads as, in each language.
final String zhLabel;
final String enLabel;
const AppLanguage(this.zhLabel, this.enLabel);
String labelFor(bool english) => english ? enLabel : zhLabel;
}
enum AppLanguage { system, zh, en }
/// The language the UI is drawn in, and the lookup behind [tr] and [AppText].
class L10n extends ChangeNotifier {
@@ -92,6 +65,8 @@ class L10n extends ChangeNotifier {
Locale get locale => switch (_choice) {
AppLanguage.zh => const Locale('zh', 'CN'),
AppLanguage.en => const Locale('en'),
// Only Chinese is translated; every other system language reads
// English.
AppLanguage.system =>
_systemIsChinese ? const Locale('zh', 'CN') : const Locale('en'),
};
@@ -106,14 +81,21 @@ class L10n extends ChangeNotifier {
bool get isEnglish => locale.languageCode == 'en';
/// The English text for [zh], or [zh] when none is written yet.
String tr(String zh) => isEnglish ? (englishStrings[zh] ?? zh) : zh;
/// What a language choice reads as: a language names itself.
String languageLabel(AppLanguage choice) => switch (choice) {
AppLanguage.system => tr('System'),
AppLanguage.zh => '中文',
AppLanguage.en => 'English',
};
/// Same, for text built from parts: `trArgs('{0} 个子代理', [n])`. The
/// Chinese template is filled as written; English entries use the same
/// The Chinese text for [en], or [en] when there is none.
String tr(String en) => isEnglish ? en : (chineseStrings[en] ?? en);
/// Same, for text built from parts: `trArgs('{0} subagents', [n])`. The
/// English template is filled as written; Chinese entries use the same
/// `{0}`, `{1}` placeholders.
String trArgs(String template, [List<Object?> args = const []]) {
var out = isEnglish ? (englishStrings[template] ?? template) : template;
var out = isEnglish ? template : (chineseStrings[template] ?? template);
for (var i = 0; i < args.length; i++) {
out = out.replaceAll('{$i}', '${args[i] ?? ''}');
}
@@ -127,7 +109,7 @@ class L10n extends ChangeNotifier {
}
}
String tr(String zh) => L10n.instance.tr(zh);
String tr(String en) => L10n.instance.tr(en);
String trArgs(String template, [List<Object?> args = const []]) =>
L10n.instance.trArgs(template, args);
@@ -135,7 +117,7 @@ String trArgs(String template, [List<Object?> args = const []]) =>
/// [Text] that goes through the same lookup. It is const-constructible, so a
/// tree does not have to give up `const` to be translated. Content that comes
/// from the server (message text, titles) is drawn with plain [Text]: only
/// our own strings are keys.
/// our own source strings are keys.
class AppText extends StatelessWidget {
final String data;
final TextStyle? style;