Ensure fallback to English for unsupported locales in Scribe
- Implement locale validation with fallback to 'en' - Disable automatic default locale setting
This commit is contained in:
@@ -4,16 +4,21 @@ import 'package:multiple_localization/multiple_localization.dart';
|
|||||||
import 'package:scribe/scribe/ai/l10n/messages_all.dart';
|
import 'package:scribe/scribe/ai/l10n/messages_all.dart';
|
||||||
|
|
||||||
class ScribeLocalizations {
|
class ScribeLocalizations {
|
||||||
|
static const List<String> _supportedLanguageCodes = ['en', 'fr', 'ru', 'vi'];
|
||||||
|
|
||||||
static ScribeLocalizations of(BuildContext context) {
|
static ScribeLocalizations of(BuildContext context) {
|
||||||
return Localizations.of<ScribeLocalizations>(context, ScribeLocalizations)!;
|
return Localizations.of<ScribeLocalizations>(context, ScribeLocalizations)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<ScribeLocalizations> load(Locale locale) {
|
static Future<ScribeLocalizations> load(Locale locale) {
|
||||||
|
final effectiveLocale = _supportedLanguageCodes.contains(locale.languageCode)
|
||||||
|
? locale
|
||||||
|
: const Locale('en');
|
||||||
return MultipleLocalizations.load(
|
return MultipleLocalizations.load(
|
||||||
initializeMessages,
|
initializeMessages,
|
||||||
locale,
|
effectiveLocale,
|
||||||
(locale) => ScribeLocalizations(),
|
(locale) => ScribeLocalizations(),
|
||||||
setDefaultLocale: true,
|
setDefaultLocale: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,8 +184,7 @@ class _ScribeLocalizationsDelegate
|
|||||||
const _ScribeLocalizationsDelegate();
|
const _ScribeLocalizationsDelegate();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool isSupported(Locale locale) =>
|
bool isSupported(Locale locale) => true;
|
||||||
['en', 'fr', 'ru', 'vi'].contains(locale.languageCode);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<ScribeLocalizations> load(Locale locale) =>
|
Future<ScribeLocalizations> load(Locale locale) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user