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:
blumia committed 2026-11-26 09:04:25 +08:00
1 parent da4bfb6826
commit 7b5bccf28f
42 files changed
+1943 -735

No files matched your search

+16 -6
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'appearance_prefs.dart';
import 'l10n.dart';
import 'pets/pet_library.dart';
import 'screens/home_screen.dart';
import 'screens/servers_screen.dart';
@@ -11,8 +12,10 @@ import 'version.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// The version goes into every connection's handshake; read it once here so
// nothing waits for it later.
// nothing waits for it later. The language is read before the first frame
// for the same reason: a saved choice should never flash the other one.
await loadAppVersion();
await L10n.instance.ensureLoaded();
runApp(const OpenChamberApp());
}
@@ -41,6 +44,12 @@ class _OpenChamberAppState extends State<OpenChamberApp>
super.dispose();
}
@override
void didChangeLocales(List<Locale>? locales) {
// "Follow the system" has to redraw when the system language changes.
L10n.instance.systemLocaleChanged();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
// The socket often dies while the app sits in the background; nothing
@@ -52,17 +61,18 @@ class _OpenChamberAppState extends State<OpenChamberApp>
Widget build(BuildContext context) {
final look = AppearancePrefs.instance;
return ListenableBuilder(
listenable: Listenable.merge([app, look]),
listenable: Listenable.merge([app, look, L10n.instance]),
builder: (context, _) {
final home = app.client == null
? ServersScreen(app: app)
: HomeScreen(app: app);
return MaterialApp(
title: 'OpenChamber',
// The app speaks Chinese only; this also puts the built-in pieces
// (date and time pickers, text selection menu) in Chinese.
locale: const Locale('zh', 'CN'),
supportedLocales: const [Locale('zh', 'CN'), Locale('en')],
// Chinese and English, picked in 设置 → 常规 → 语言 or followed
// from the system. The built-in pieces (date and time pickers,
// text selection menu) follow the same choice.
locale: L10n.instance.locale,
supportedLocales: const [Locale('en'), Locale('zh', 'CN')],
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,