fix can't use context for easy_localization
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:immich_mobile/utils/translation.dart';
|
||||||
|
import 'package:intl/message_format.dart';
|
||||||
|
|
||||||
extension ContextHelper on BuildContext {
|
extension ContextHelper on BuildContext {
|
||||||
// Returns the current padding from MediaQuery
|
// Returns the current padding from MediaQuery
|
||||||
@@ -58,4 +61,17 @@ extension ContextHelper on BuildContext {
|
|||||||
// Show SnackBars from the current context
|
// Show SnackBars from the current context
|
||||||
void showSnackBar(SnackBar snackBar) =>
|
void showSnackBar(SnackBar snackBar) =>
|
||||||
ScaffoldMessenger.of(this).showSnackBar(snackBar);
|
ScaffoldMessenger.of(this).showSnackBar(snackBar);
|
||||||
|
|
||||||
|
String t(String key, [Map<String, Object>? args]) {
|
||||||
|
try {
|
||||||
|
String message = this.tr(key);
|
||||||
|
if (args != null) {
|
||||||
|
return MessageFormat(message, locale: Intl.defaultLocale ?? 'en')
|
||||||
|
.format(args);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
} catch (e) {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,14 +205,12 @@ class ImmichAppState extends ConsumerState<ImmichApp>
|
|||||||
overrides: [
|
overrides: [
|
||||||
localeProvider.overrideWithValue(context.locale),
|
localeProvider.overrideWithValue(context.locale),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp.router(
|
||||||
|
title: 'Immich',
|
||||||
|
debugShowCheckedModeBanner: true,
|
||||||
localizationsDelegates: context.localizationDelegates,
|
localizationsDelegates: context.localizationDelegates,
|
||||||
supportedLocales: context.supportedLocales,
|
supportedLocales: context.supportedLocales,
|
||||||
locale: context.locale,
|
locale: context.locale,
|
||||||
debugShowCheckedModeBanner: true,
|
|
||||||
home: MaterialApp.router(
|
|
||||||
title: 'Immich',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
themeMode: ref.watch(immichThemeModeProvider),
|
themeMode: ref.watch(immichThemeModeProvider),
|
||||||
darkTheme: getThemeData(
|
darkTheme: getThemeData(
|
||||||
colorScheme: immichTheme.dark,
|
colorScheme: immichTheme.dark,
|
||||||
@@ -227,7 +225,6 @@ class ImmichAppState extends ConsumerState<ImmichApp>
|
|||||||
navigatorObservers: () => [AppNavigationObserver(ref: ref)],
|
navigatorObservers: () => [AppNavigationObserver(ref: ref)],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ class _LanguageSearchBar extends StatelessWidget {
|
|||||||
child: SearchField(
|
child: SearchField(
|
||||||
autofocus: false,
|
autofocus: false,
|
||||||
contentPadding: const EdgeInsets.all(12),
|
contentPadding: const EdgeInsets.all(12),
|
||||||
hintText: 'language_search_hint'.tr(),
|
hintText: context.t('language_search_hint'),
|
||||||
prefixIcon: const Icon(Icons.search_rounded),
|
prefixIcon: const Icon(Icons.search_rounded),
|
||||||
suffixIcon: controller.text.isNotEmpty
|
suffixIcon: controller.text.isNotEmpty
|
||||||
? IconButton(
|
? IconButton(
|
||||||
@@ -196,14 +196,14 @@ class _LanguageNotFound extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'language_no_results_title'.tr(),
|
context.t('language_no_results_title'),
|
||||||
style: context.textTheme.titleMedium?.copyWith(
|
style: context.textTheme.titleMedium?.copyWith(
|
||||||
color: context.colorScheme.onSurface,
|
color: context.colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
'language_no_results_subtitle'.tr(),
|
context.t('language_no_results_subtitle'),
|
||||||
style: context.textTheme.bodyMedium?.copyWith(
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
color: context.colorScheme.onSurface.withValues(alpha: 0.8),
|
color: context.colorScheme.onSurface.withValues(alpha: 0.8),
|
||||||
),
|
),
|
||||||
@@ -246,7 +246,7 @@ class _LanguageApplyButton extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: Text(
|
: Text(
|
||||||
'setting_languages_apply'.tr(),
|
context.t('setting_languages_apply'),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
fontSize: 16.0,
|
fontSize: 16.0,
|
||||||
|
|||||||
Reference in New Issue
Block a user