Skip to content

Commit c979279

Browse files
committed
app: Override locale with language global setting
This doesn't really have user-facing changes yet, because they cannot set the language. In this case, ZulipApp.locale is null, and localization will follow system setting, like we did before this change. This behavior is an improvement compared to the legacy app, which just uses English (en) when language is not set.
1 parent c5787be commit c979279

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/widgets/app.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class _ZulipAppState extends State<ZulipApp> with WidgetsBindingObserver {
242242
onGenerateTitle: (BuildContext context) {
243243
return ZulipLocalizations.of(context).zulipAppTitle;
244244
},
245+
locale: GlobalStoreWidget.settingsOf(context).language,
245246
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
246247
supportedLocales: ZulipLocalizations.supportedLocales,
247248
// The context has to be taken from the [Builder] because

test/widgets/app_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ import 'test_app.dart';
2323
void main() {
2424
TestZulipBinding.ensureInitialized();
2525

26+
group('ZulipApp locale', () {
27+
Future<void> prepare(WidgetTester tester, {required Locale? locale}) async {
28+
addTearDown(testBinding.reset);
29+
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
30+
if (locale != null) {
31+
await testBinding.globalStore.settings.setLanguage(locale);
32+
}
33+
await tester.pumpWidget(ZulipApp());
34+
await tester.pump();
35+
await tester.pump();
36+
}
37+
38+
testWidgets('no language is set', (tester) async {
39+
await prepare(tester, locale: null);
40+
final element = tester.element(find.byType(HomePage));
41+
check(Localizations.localeOf(element)).equals(const Locale('en'));
42+
});
43+
44+
testWidgets('has language set', (tester) async {
45+
await prepare(tester, locale: const Locale('uk'));
46+
final element = tester.element(find.byType(HomePage));
47+
check(Localizations.localeOf(element)).equals(const Locale('uk'));
48+
});
49+
50+
testWidgets('has unsupported language set', (tester) async {
51+
await prepare(tester, locale: const Locale('zxx'));
52+
final element = tester.element(find.byType(HomePage));
53+
check(Localizations.localeOf(element)).equals(const Locale('en'));
54+
});
55+
});
56+
2657
group('ZulipApp initial navigation', () {
2758
late List<Route<dynamic>> pushedRoutes = [];
2859

test/widgets/test_app.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class TestZulipApp extends StatelessWidget {
7171

7272
return MaterialApp(
7373
title: 'Zulip',
74+
locale: GlobalStoreWidget.settingsOf(context).language,
7475
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
7576
supportedLocales: ZulipLocalizations.supportedLocales,
7677
// The context has to be taken from the [Builder] because

0 commit comments

Comments
 (0)