|
|
@ -7,10 +7,10 @@ import 'package:intl/intl.dart' as intl; |
|
|
|
|
|
|
|
|
|
|
|
import 'localizations_en.dart'; |
|
|
|
import 'localizations_en.dart'; |
|
|
|
|
|
|
|
|
|
|
|
/// Callers can lookup localized strings with an instance of AppLocalizations |
|
|
|
/// Callers can lookup localized strings with an instance of DashboardLocalizations |
|
|
|
/// returned by `AppLocalizations.of(context)`. |
|
|
|
/// returned by `DashboardLocalizations.of(context)`. |
|
|
|
/// |
|
|
|
/// |
|
|
|
/// Applications need to include `AppLocalizations.delegate()` in their app's |
|
|
|
/// Applications need to include `DashboardLocalizations.delegate()` in their app's |
|
|
|
/// `localizationDelegates` list, and the locales they support in the app's |
|
|
|
/// `localizationDelegates` list, and the locales they support in the app's |
|
|
|
/// `supportedLocales` list. For example: |
|
|
|
/// `supportedLocales` list. For example: |
|
|
|
/// |
|
|
|
/// |
|
|
@ -18,8 +18,8 @@ import 'localizations_en.dart'; |
|
|
|
/// import 'l10n/localizations.dart'; |
|
|
|
/// import 'l10n/localizations.dart'; |
|
|
|
/// |
|
|
|
/// |
|
|
|
/// return MaterialApp( |
|
|
|
/// return MaterialApp( |
|
|
|
/// localizationsDelegates: AppLocalizations.localizationsDelegates, |
|
|
|
/// localizationsDelegates: DashboardLocalizations.localizationsDelegates, |
|
|
|
/// supportedLocales: AppLocalizations.supportedLocales, |
|
|
|
/// supportedLocales: DashboardLocalizations.supportedLocales, |
|
|
|
/// home: MyApplicationHome(), |
|
|
|
/// home: MyApplicationHome(), |
|
|
|
/// ); |
|
|
|
/// ); |
|
|
|
/// ``` |
|
|
|
/// ``` |
|
|
@ -56,18 +56,18 @@ import 'localizations_en.dart'; |
|
|
|
/// Select and expand the newly-created Localizations item then, for each |
|
|
|
/// Select and expand the newly-created Localizations item then, for each |
|
|
|
/// locale your application supports, add a new item and select the locale |
|
|
|
/// locale your application supports, add a new item and select the locale |
|
|
|
/// you wish to add from the pop-up menu in the Value field. This list should |
|
|
|
/// you wish to add from the pop-up menu in the Value field. This list should |
|
|
|
/// be consistent with the languages listed in the AppLocalizations.supportedLocales |
|
|
|
/// be consistent with the languages listed in the DashboardLocalizations.supportedLocales |
|
|
|
/// property. |
|
|
|
/// property. |
|
|
|
abstract class AppLocalizations { |
|
|
|
abstract class DashboardLocalizations { |
|
|
|
AppLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString()); |
|
|
|
DashboardLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString()); |
|
|
|
|
|
|
|
|
|
|
|
final String localeName; |
|
|
|
final String localeName; |
|
|
|
|
|
|
|
|
|
|
|
static AppLocalizations of(BuildContext context) { |
|
|
|
static DashboardLocalizations of(BuildContext context) { |
|
|
|
return Localizations.of<AppLocalizations>(context, AppLocalizations)!; |
|
|
|
return Localizations.of<DashboardLocalizations>(context, DashboardLocalizations)!; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static const LocalizationsDelegate<AppLocalizations> delegate = _AppLocalizationsDelegate(); |
|
|
|
static const LocalizationsDelegate<DashboardLocalizations> delegate = _DashboardLocalizationsDelegate(); |
|
|
|
|
|
|
|
|
|
|
|
/// A list of this localizations delegate along with the default localizations |
|
|
|
/// A list of this localizations delegate along with the default localizations |
|
|
|
/// delegates. |
|
|
|
/// delegates. |
|
|
@ -96,29 +96,29 @@ abstract class AppLocalizations { |
|
|
|
String get noEntries; |
|
|
|
String get noEntries; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> { |
|
|
|
class _DashboardLocalizationsDelegate extends LocalizationsDelegate<DashboardLocalizations> { |
|
|
|
const _AppLocalizationsDelegate(); |
|
|
|
const _DashboardLocalizationsDelegate(); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Future<AppLocalizations> load(Locale locale) { |
|
|
|
Future<DashboardLocalizations> load(Locale locale) { |
|
|
|
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale)); |
|
|
|
return SynchronousFuture<DashboardLocalizations>(lookupDashboardLocalizations(locale)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
bool isSupported(Locale locale) => <String>['en'].contains(locale.languageCode); |
|
|
|
bool isSupported(Locale locale) => <String>['en'].contains(locale.languageCode); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
bool shouldReload(_AppLocalizationsDelegate old) => false; |
|
|
|
bool shouldReload(_DashboardLocalizationsDelegate old) => false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AppLocalizations lookupAppLocalizations(Locale locale) { |
|
|
|
DashboardLocalizations lookupDashboardLocalizations(Locale locale) { |
|
|
|
// Lookup logic when only language code is specified. |
|
|
|
// Lookup logic when only language code is specified. |
|
|
|
switch (locale.languageCode) { |
|
|
|
switch (locale.languageCode) { |
|
|
|
case 'en': |
|
|
|
case 'en': |
|
|
|
return AppLocalizationsEn(); |
|
|
|
return DashboardLocalizationsEn(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw FlutterError('AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely ' |
|
|
|
throw FlutterError('DashboardLocalizations.delegate failed to load unsupported locale "$locale". This is likely ' |
|
|
|
'an issue with the localizations generation tool. Please file an issue ' |
|
|
|
'an issue with the localizations generation tool. Please file an issue ' |
|
|
|
'on GitHub with a reproducible sample app and the gen-l10n configuration ' |
|
|
|
'on GitHub with a reproducible sample app and the gen-l10n configuration ' |
|
|
|
'that was used.'); |
|
|
|
'that was used.'); |
|
|
|