Files
BadNote/test/l10n_test.dart
Akiba So a7d71e7cfd
Some checks failed
CI / Windows build (push) Has been cancelled
feat(i18n): localize settings + search screens
Extend the en/zh localization to the two screens reached from the home
app bar (the "全都用 + 多语言" ask):
- settings: title, theme-mode segments (System/Light/Dark), seed-color
  description, color-picker + clear-data dialogs.
- search: hint, error, empty/no-results states, Notes/Documents section
  headers, page label.

New ARB keys regenerated; l10n_test now asserts the new keys resolve in
both English and Chinese.

flutter analyze: 0 issues. l10n_test: 3/3.
2026-06-23 10:03:02 +08:00

62 lines
2.0 KiB
Dart

// Proves i18n is real, not just wired: the SAME widget resolves English under
// Locale('en') and Chinese under Locale('zh'), through the generated
// AppLocalizations delegates. Guards against ARB keys drifting out of sync.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:badnote/l10n/app_localizations.dart';
class _Probe extends StatelessWidget {
const _Probe();
@override
Widget build(BuildContext context) {
final l = AppLocalizations.of(context);
return Directionality(
textDirection: TextDirection.ltr,
child: Column(children: [
Text(l.settings),
Text(l.toolEraser),
Text(l.importPdf),
Text(l.themeSystem),
Text(l.searchHint),
]),
);
}
}
Future<void> _pump(WidgetTester tester, Locale locale) {
return tester.pumpWidget(MaterialApp(
locale: locale,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const _Probe(),
));
}
void main() {
testWidgets('English locale resolves English strings', (tester) async {
await _pump(tester, const Locale('en'));
expect(find.text('Settings'), findsOneWidget);
expect(find.text('Eraser'), findsOneWidget);
expect(find.text('Import PDF'), findsOneWidget);
expect(find.text('System'), findsOneWidget);
expect(find.text('Search notes and documents...'), findsOneWidget);
});
testWidgets('Chinese locale resolves Chinese strings', (tester) async {
await _pump(tester, const Locale('zh'));
expect(find.text('设置'), findsOneWidget);
expect(find.text('橡皮擦'), findsOneWidget);
expect(find.text('导入 PDF'), findsOneWidget);
expect(find.text('跟随系统'), findsOneWidget);
expect(find.text('搜索笔记和文档…'), findsOneWidget);
});
test('both locales are supported', () {
final langs =
AppLocalizations.supportedLocales.map((l) => l.languageCode).toSet();
expect(langs.containsAll({'en', 'zh'}), isTrue);
});
}