mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-06 00:36:40 +10:00
Validate locale override and use preferred locale list for fallback
This commit is contained in:
@@ -57,6 +57,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
DateTime? _lastChannelSendAt;
|
DateTime? _lastChannelSendAt;
|
||||||
bool _channelSkipNextBottomSnap = false;
|
bool _channelSkipNextBottomSnap = false;
|
||||||
|
|
||||||
|
String? _cachedFormatLocale;
|
||||||
|
late DateFormat _hmFormat;
|
||||||
|
late DateFormat _mdFormat;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -1232,10 +1236,15 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final diff = now.difference(time);
|
final diff = now.difference(time);
|
||||||
final locale = Localizations.localeOf(context).toString();
|
final locale = Localizations.localeOf(context).toString();
|
||||||
final hm = DateFormat.Hm(locale).format(time);
|
if (locale != _cachedFormatLocale) {
|
||||||
|
_cachedFormatLocale = locale;
|
||||||
|
_hmFormat = DateFormat.Hm(locale);
|
||||||
|
_mdFormat = DateFormat.Md(locale);
|
||||||
|
}
|
||||||
|
final hm = _hmFormat.format(time);
|
||||||
|
|
||||||
if (diff.inDays > 0) {
|
if (diff.inDays > 0) {
|
||||||
return '${DateFormat.Md(locale).format(time)} $hm';
|
return '${_mdFormat.format(time)} $hm';
|
||||||
} else {
|
} else {
|
||||||
return hm;
|
return hm;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,14 +57,17 @@ class BackgroundService {
|
|||||||
final supported = AppLocalizations.supportedLocales;
|
final supported = AppLocalizations.supportedLocales;
|
||||||
final override = _languageOverrideProvider?.call();
|
final override = _languageOverrideProvider?.call();
|
||||||
if (override != null && override.isNotEmpty) {
|
if (override != null && override.isNotEmpty) {
|
||||||
return AppLocalizations.delegate.load(Locale(override));
|
final overrideLocale = Locale(override);
|
||||||
|
final isSupported = supported.any(
|
||||||
|
(l) => l.languageCode == overrideLocale.languageCode,
|
||||||
|
);
|
||||||
|
if (isSupported) {
|
||||||
|
return AppLocalizations.delegate.load(overrideLocale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final system =
|
final preferred =
|
||||||
WidgetsBinding.instance.platformDispatcher.locale;
|
WidgetsBinding.instance.platformDispatcher.locales;
|
||||||
final match = basicLocaleListResolution(
|
final match = basicLocaleListResolution(preferred, supported);
|
||||||
<Locale>[system],
|
|
||||||
supported,
|
|
||||||
);
|
|
||||||
return AppLocalizations.delegate.load(match);
|
return AppLocalizations.delegate.load(match);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user