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
@@ -7,6 +7,7 @@ import '../api/models.dart';
|
||||
import '../api/scheduled_tasks.dart';
|
||||
import '../state.dart';
|
||||
import 'model_picker.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
class ScheduledTaskEditor extends StatefulWidget {
|
||||
final AppState app;
|
||||
@@ -120,7 +121,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
child: AppText(
|
||||
widget.initial == null ? '新建计划任务' : '编辑计划任务',
|
||||
style: const TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.w600),
|
||||
@@ -128,7 +129,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _saving ? null : _save,
|
||||
child: Text(_saving ? '保存中…' : '保存'),
|
||||
child: AppText(_saving ? '保存中…' : '保存'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -137,16 +138,16 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 32),
|
||||
children: [
|
||||
Text('运行位置:${widget.scopeLabel}',
|
||||
AppText(trArgs('运行位置:{0}', [widget.scopeLabel]),
|
||||
style: TextStyle(fontSize: 12.5, color: theme.hintColor)),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _name,
|
||||
maxLength: 80,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '任务名称',
|
||||
hintText: '每日同步',
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
labelText: tr('任务名称'),
|
||||
hintText: tr('每日同步'),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -154,10 +155,10 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
controller: _prompt,
|
||||
minLines: 4,
|
||||
maxLines: 10,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '提示词',
|
||||
hintText: '总结未完成任务并给出下一步建议',
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
labelText: tr('提示词'),
|
||||
hintText: tr('总结未完成任务并给出下一步建议'),
|
||||
border: const OutlineInputBorder(),
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
),
|
||||
@@ -169,7 +170,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
children: [
|
||||
for (final entry in scheduledTaskKindLabels.entries)
|
||||
ChoiceChip(
|
||||
label: Text(entry.value),
|
||||
label: AppText(entry.value),
|
||||
selected: _kind == entry.key,
|
||||
onSelected: (_) => setState(() => _kind = entry.key),
|
||||
),
|
||||
@@ -180,23 +181,23 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('使用默认模型与智能体'),
|
||||
subtitle: const Text('关闭后可固定这次运行使用的模型和智能体。'),
|
||||
title: const AppText('使用默认模型与智能体'),
|
||||
subtitle: const AppText('关闭后可固定这次运行使用的模型和智能体。'),
|
||||
value: _useDefaults,
|
||||
onChanged: (v) => setState(() => _useDefaults = v),
|
||||
),
|
||||
if (!_useDefaults) ..._executionFields(theme),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('已启用'),
|
||||
subtitle: const Text('暂停的任务不会按计划运行,但可以手动运行。'),
|
||||
title: const AppText('已启用'),
|
||||
subtitle: const AppText('暂停的任务不会按计划运行,但可以手动运行。'),
|
||||
value: _enabled,
|
||||
onChanged: (v) => setState(() => _enabled = v),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
FilledButton(
|
||||
onPressed: _saving ? null : _save,
|
||||
child: Text(_saving ? '保存中…' : '保存'),
|
||||
child: AppText(_saving ? '保存中…' : '保存'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -219,7 +220,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
children: [
|
||||
for (var day = 0; day < scheduledWeekdays.length; day++)
|
||||
FilterChip(
|
||||
label: Text(scheduledWeekdays[day]),
|
||||
label: AppText(scheduledWeekdays[day]),
|
||||
selected: _weekdays.contains(day),
|
||||
onSelected: (selected) => setState(() {
|
||||
if (selected) {
|
||||
@@ -238,14 +239,14 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
return [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('日期'),
|
||||
trailing: Text(_dateText(_date)),
|
||||
title: const AppText('日期'),
|
||||
trailing: AppText(_dateText(_date)),
|
||||
onTap: _pickDate,
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('时间'),
|
||||
trailing: Text(_time),
|
||||
title: const AppText('时间'),
|
||||
trailing: AppText(_time),
|
||||
onTap: () async {
|
||||
final picked = await _pickTime(_time);
|
||||
if (picked != null) setState(() => _time = picked);
|
||||
@@ -256,10 +257,10 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
return [
|
||||
TextField(
|
||||
controller: _cron,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Cron 表达式',
|
||||
decoration: InputDecoration(
|
||||
labelText: tr('Cron 表达式'),
|
||||
hintText: '*/5 * * * *',
|
||||
border: OutlineInputBorder(),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -275,7 +276,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
('每月 1 日', '0 9 1 * *'),
|
||||
])
|
||||
ActionChip(
|
||||
label: Text(example.$1),
|
||||
label: AppText(example.$1),
|
||||
onPressed: () =>
|
||||
setState(() => _cron.text = example.$2),
|
||||
),
|
||||
@@ -302,12 +303,12 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
final picked = await _pickTime(_times[i]);
|
||||
if (picked != null) setState(() => _times[i] = picked);
|
||||
},
|
||||
child: Text(_times[i]),
|
||||
child: AppText(_times[i]),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove_circle_outline, size: 20),
|
||||
tooltip: '移除时间',
|
||||
tooltip: tr('移除时间'),
|
||||
onPressed: _times.length <= 1
|
||||
? null
|
||||
: () => setState(() => _times.removeAt(i)),
|
||||
@@ -321,9 +322,9 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
if (picked != null) setState(() => _times.add(picked));
|
||||
},
|
||||
icon: const Icon(Icons.add, size: 18),
|
||||
label: const Text('添加时间'),
|
||||
label: const AppText('添加时间'),
|
||||
),
|
||||
Text('时间按服务器所在时区。', style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
AppText('时间按服务器所在时区。', style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -337,15 +338,15 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.memory, size: 20),
|
||||
title: const Text('模型'),
|
||||
trailing: Text(model, overflow: TextOverflow.ellipsis),
|
||||
title: const AppText('模型'),
|
||||
trailing: AppText(model, overflow: TextOverflow.ellipsis),
|
||||
onTap: _pickModel,
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.smart_toy_outlined, size: 20),
|
||||
title: const Text('智能体'),
|
||||
trailing: Text(agent, overflow: TextOverflow.ellipsis),
|
||||
title: const AppText('智能体'),
|
||||
trailing: AppText(agent, overflow: TextOverflow.ellipsis),
|
||||
onTap: _pickAgent,
|
||||
),
|
||||
];
|
||||
@@ -403,13 +404,13 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
ListTile(
|
||||
title: const Text('默认智能体'),
|
||||
title: const AppText('默认智能体'),
|
||||
trailing: _agent.isEmpty ? const Icon(Icons.check, size: 20) : null,
|
||||
onTap: () => Navigator.pop(sheet, ''),
|
||||
),
|
||||
for (final agent in widget.app.agentList)
|
||||
ListTile(
|
||||
title: Text(agent.name.isEmpty ? agent.id : agent.name),
|
||||
title: AppText(agent.name.isEmpty ? agent.id : agent.name),
|
||||
trailing: _agent == agent.id
|
||||
? const Icon(Icons.check, size: 20)
|
||||
: null,
|
||||
@@ -446,7 +447,7 @@ class _ScheduledTaskEditorState extends State<ScheduledTaskEditor> {
|
||||
problem = '请选择模型,或改回使用默认模型';
|
||||
}
|
||||
if (problem != null) {
|
||||
messenger.showSnackBar(SnackBar(content: Text(problem)));
|
||||
messenger.showSnackBar(SnackBar(content: AppText(problem)));
|
||||
return;
|
||||
}
|
||||
setState(() => _saving = true);
|
||||
@@ -487,8 +488,8 @@ class _FieldLabel extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Text(text,
|
||||
child: AppText(text,
|
||||
style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user