You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-08-10 23:22:22 +02:00
handle context null
This commit is contained in:
@@ -3,13 +3,13 @@ import 'package:intl/message_format.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
extension StringTranslateExtension on String {
|
extension StringTranslateExtension on String {
|
||||||
String t(BuildContext context, [Map<String, Object>? args]) {
|
String t({BuildContext? context, Map<String, Object>? args}) {
|
||||||
return _translateHelper(context, this, args);
|
return _translateHelper(context, this, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TextTranslateExtension on Text {
|
extension TextTranslateExtension on Text {
|
||||||
Text t(BuildContext context, [Map<String, Object>? args]) {
|
Text t({BuildContext? context, Map<String, Object>? args}) {
|
||||||
return Text(
|
return Text(
|
||||||
_translateHelper(context, data ?? '', args),
|
_translateHelper(context, data ?? '', args),
|
||||||
key: key,
|
key: key,
|
||||||
@@ -30,7 +30,7 @@ extension TextTranslateExtension on Text {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _translateHelper(
|
String _translateHelper(
|
||||||
BuildContext context,
|
BuildContext? context,
|
||||||
String key, [
|
String key, [
|
||||||
Map<String, Object>? args,
|
Map<String, Object>? args,
|
||||||
]) {
|
]) {
|
||||||
@@ -38,7 +38,7 @@ String _translateHelper(
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final translatedMessage = context.tr(key);
|
final translatedMessage = context != null ? context.tr(key) : key.tr();
|
||||||
return args != null
|
return args != null
|
||||||
? MessageFormat(translatedMessage, locale: Intl.defaultLocale ?? 'en')
|
? MessageFormat(translatedMessage, locale: Intl.defaultLocale ?? 'en')
|
||||||
.format(args)
|
.format(args)
|
||||||
|
@@ -165,7 +165,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'.t(context),
|
hintText: 'language_search_hint'.t(context: context),
|
||||||
prefixIcon: const Icon(Icons.search_rounded),
|
prefixIcon: const Icon(Icons.search_rounded),
|
||||||
suffixIcon: controller.text.isNotEmpty
|
suffixIcon: controller.text.isNotEmpty
|
||||||
? IconButton(
|
? IconButton(
|
||||||
@@ -199,14 +199,14 @@ class _LanguageNotFound extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'language_no_results_title'.t(context),
|
'language_no_results_title'.t(context: context),
|
||||||
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'.t(context),
|
'language_no_results_subtitle'.t(context: context),
|
||||||
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),
|
||||||
),
|
),
|
||||||
@@ -254,7 +254,7 @@ class _LanguageApplyButton extends StatelessWidget {
|
|||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
fontSize: 16.0,
|
fontSize: 16.0,
|
||||||
),
|
),
|
||||||
).t(context),
|
).t(context: context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user