mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
fix(mobile): fixes on language change (#14089)
* fix(mobile): make widgets rebuild on locale changes This will make the make the pages to instantly refresh the correct translated string, without the need to pop and push the settings page. * fix(mobile): set the default intl locale This is needed because across the app, you don't pass the context.locale to DateFormat, so by default it uses the system's locale. This will fix the issue without the need to refactor a lot of code. * feat(mobile): create localeProvider This provider can be used to refresh providers that provide UI elements and get cached. * fix(mobile): refresh asset providers on locale change This is necessary to update the locale on the already evaluated DateFormat. --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
53940f7d42
commit
3a2e30e30e
4 changed files with 34 additions and 17 deletions
|
@ -192,6 +192,12 @@ class ImmichAppState extends ConsumerState<ImmichApp>
|
||||||
await ref.read(localNotificationService).setup();
|
await ref.read(localNotificationService).setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
Intl.defaultLocale = context.locale.toLanguageTag();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
initState() {
|
initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
|
@ -46,6 +46,7 @@ class SettingsPage extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
context.locale;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
|
@ -129,6 +130,7 @@ class SettingsSubPage extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
context.locale;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
|
|
|
@ -23,6 +23,7 @@ class LibraryPage extends ConsumerWidget {
|
||||||
const LibraryPage({super.key});
|
const LibraryPage({super.key});
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
context.locale;
|
||||||
final trashEnabled =
|
final trashEnabled =
|
||||||
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
|
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/providers/locale_provider.dart';
|
||||||
import 'package:immich_mobile/providers/memory.provider.dart';
|
import 'package:immich_mobile/providers/memory.provider.dart';
|
||||||
import 'package:immich_mobile/repositories/asset_media.repository.dart';
|
import 'package:immich_mobile/repositories/asset_media.repository.dart';
|
||||||
import 'package:immich_mobile/services/album.service.dart';
|
import 'package:immich_mobile/services/album.service.dart';
|
||||||
|
@ -328,24 +329,31 @@ final assetWatcher =
|
||||||
return db.assets.watchObject(asset.id, fireImmediately: true);
|
return db.assets.watchObject(asset.id, fireImmediately: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
final assetsProvider = StreamProvider.family<RenderList, int?>((ref, userId) {
|
final assetsProvider = StreamProvider.family<RenderList, int?>(
|
||||||
|
(ref, userId) {
|
||||||
if (userId == null) return const Stream.empty();
|
if (userId == null) return const Stream.empty();
|
||||||
|
ref.watch(localeProvider);
|
||||||
final query = _commonFilterAndSort(
|
final query = _commonFilterAndSort(
|
||||||
_assets(ref).where().ownerIdEqualToAnyChecksum(userId),
|
_assets(ref).where().ownerIdEqualToAnyChecksum(userId),
|
||||||
);
|
);
|
||||||
return renderListGenerator(query, ref);
|
return renderListGenerator(query, ref);
|
||||||
});
|
},
|
||||||
|
dependencies: [localeProvider],
|
||||||
|
);
|
||||||
|
|
||||||
final multiUserAssetsProvider =
|
final multiUserAssetsProvider = StreamProvider.family<RenderList, List<int>>(
|
||||||
StreamProvider.family<RenderList, List<int>>((ref, userIds) {
|
(ref, userIds) {
|
||||||
if (userIds.isEmpty) return const Stream.empty();
|
if (userIds.isEmpty) return const Stream.empty();
|
||||||
|
ref.watch(localeProvider);
|
||||||
final query = _commonFilterAndSort(
|
final query = _commonFilterAndSort(
|
||||||
_assets(ref)
|
_assets(ref)
|
||||||
.where()
|
.where()
|
||||||
.anyOf(userIds, (q, u) => q.ownerIdEqualToAnyChecksum(u)),
|
.anyOf(userIds, (q, u) => q.ownerIdEqualToAnyChecksum(u)),
|
||||||
);
|
);
|
||||||
return renderListGenerator(query, ref);
|
return renderListGenerator(query, ref);
|
||||||
});
|
},
|
||||||
|
dependencies: [localeProvider],
|
||||||
|
);
|
||||||
|
|
||||||
QueryBuilder<Asset, Asset, QAfterSortBy>? getRemoteAssetQuery(WidgetRef ref) {
|
QueryBuilder<Asset, Asset, QAfterSortBy>? getRemoteAssetQuery(WidgetRef ref) {
|
||||||
final userId = ref.watch(currentUserProvider)?.isarId;
|
final userId = ref.watch(currentUserProvider)?.isarId;
|
||||||
|
|
Loading…
Reference in a new issue