Skip to content

Commit 09e98fb

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 9c112bd commit 09e98fb

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
@@ -223,6 +223,7 @@ class _ZulipAppState extends State<ZulipApp> with WidgetsBindingObserver {
223223
onGenerateTitle: (BuildContext context) {
224224
return ZulipLocalizations.of(context).zulipAppTitle;
225225
},
226+
locale: GlobalStoreWidget.settingsOf(context).language,
226227
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
227228
supportedLocales: ZulipLocalizations.supportedLocales,
228229
// 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)