mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
chore: Implement translation callbacks to flutter
This commit is contained in:
parent
e902e2034a
commit
29917bb59f
16 changed files with 681 additions and 43 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
|
@ -100,6 +102,7 @@ Future<void> _playVideo(
|
|||
}
|
||||
|
||||
if (context.mounted) {
|
||||
log("Finished refreshing");
|
||||
await context.refreshData();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||
|
||||
import 'package:fladder/l10n/generated/app_localizations.dart';
|
||||
import 'package:fladder/providers/sync/background_download_provider.dart';
|
||||
import 'package:fladder/src/translations_pigeon.g.dart' as messenger;
|
||||
|
||||
///Only use for base translations, under normal circumstances ALWAYS use the widgets provided context
|
||||
final localizationContextProvider = StateProvider<BuildContext?>((ref) => null);
|
||||
|
|
@ -26,6 +27,7 @@ class LocalizationContextWrapper extends ConsumerStatefulWidget {
|
|||
}
|
||||
|
||||
class _LocalizationContextWrapperState extends ConsumerState<LocalizationContextWrapper> {
|
||||
_TranslationsMessgener? _messenger;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
|
@ -41,6 +43,11 @@ class _LocalizationContextWrapperState extends ConsumerState<LocalizationContext
|
|||
}
|
||||
|
||||
void updateLanguageContext() {
|
||||
if (_messenger == null) {
|
||||
_messenger = _TranslationsMessgener(context: context);
|
||||
messenger.TranslationsPigeon.setUp(_messenger);
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((value) {
|
||||
ref.read(localizationContextProvider.notifier).update((cb) => context);
|
||||
ref.read(backgroundDownloaderProvider.notifier).updateTranslations(context);
|
||||
|
|
@ -58,3 +65,36 @@ extension LocaleDisplayCodeExtension on Locale {
|
|||
: languageCode.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
class _TranslationsMessgener extends messenger.TranslationsPigeon {
|
||||
_TranslationsMessgener({required this.context});
|
||||
|
||||
final BuildContext context;
|
||||
|
||||
@override
|
||||
String chapters(int count) => context.localized.chapter(count);
|
||||
|
||||
@override
|
||||
String close() => context.localized.close;
|
||||
|
||||
@override
|
||||
String endsAt(String time) => context.localized.endsAt(DateTime.parse(time));
|
||||
|
||||
@override
|
||||
String next() => context.localized.nextVideo;
|
||||
|
||||
@override
|
||||
String nextUpInSeconds(int seconds) => context.localized.nextUpInCount(seconds);
|
||||
|
||||
@override
|
||||
String nextVideo() => context.localized.nextVideo;
|
||||
|
||||
@override
|
||||
String off() => context.localized.off;
|
||||
|
||||
@override
|
||||
String skip(String name) => context.localized.skipButtonLabel(name);
|
||||
|
||||
@override
|
||||
String subtitles() => context.localized.subtitles;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue