From b48450657de4f897314e8b0907f1c808adf313ef Mon Sep 17 00:00:00 2001 From: Yannick Mauray Date: Thu, 11 Nov 2021 09:59:57 +0100 Subject: [PATCH] Fixed i18n stuff before merging PR #13 --- lib/src/app.dart | 23 ++++++++++++++++--- .../i18n/quickgui_localizations_delegate.dart | 8 +++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index eacf44f..c5800a5 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -31,9 +31,26 @@ class _AppState extends State with PreferencesMixin { themeMode: appTheme.themeMode, home: const MainPage(title: 'Quickgui - A Flutter frontend for Quickget and Quickemu'), supportedLocales: const [ - /// List of locales we have translations for. - Locale('en', ''), - Locale('fr', ''), + /* + * List of locales (language + country) we have translations for. + * + * If there is a file for the tuple (langue, country) in assets/lib/i18n, then this + * will be used for translation. + * + * If there is not, then we'll look for a file for the language only. + * + * If there is no file for the language code, we'll fallback to the english file. + * + * Example : let's say the locale is fr_CH. We will look for "assets/lib/i18n/fr_CH.po", + * "assets/lib/i18n/fr.po", and "assets/lib/i18n/en.po", stopping at the first file we + * find. + * + * Translation files are not merged, meaning if some translations are missing in fr_CH.po + * but are present in fr.po, the missing translations will not be picked up from fr.po, + * and thus will show up in english. + */ + Locale('en'), + Locale('fr'), Locale('fr', 'CH'), ], localizationsDelegates: [ diff --git a/lib/src/i18n/quickgui_localizations_delegate.dart b/lib/src/i18n/quickgui_localizations_delegate.dart index b5bdded..85f2a14 100644 --- a/lib/src/i18n/quickgui_localizations_delegate.dart +++ b/lib/src/i18n/quickgui_localizations_delegate.dart @@ -4,7 +4,7 @@ import 'package:quickgui/src/i18n/quickgui_localizations.dart'; class QuickguiLocalizationsDelegate extends LocalizationsDelegate { @override - bool isSupported(Locale locale) => ['fr', 'en'].contains(locale.languageCode); + bool isSupported(Locale locale) => true; @override Future load(Locale locale) async { @@ -12,7 +12,11 @@ class QuickguiLocalizationsDelegate extends LocalizationsDelegate