i18n.dart 848 B

1234567891011121314151617181920212223242526272829303132333435
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/foundation.dart';
  3. class I18n {
  4. I18n(this.locale);
  5. final Locale locale;
  6. static I18n? of(BuildContext context) {
  7. return Localizations.of<I18n>(context, I18n);
  8. }
  9. Map<String, String>? getDic(
  10. Map<String, Map<String, Map<String, String>>> fullDic, String module) {
  11. return fullDic[locale.languageCode]![module];
  12. }
  13. }
  14. class AppLocalizationsDelegate extends LocalizationsDelegate<I18n> {
  15. const AppLocalizationsDelegate(this.overriddenLocale);
  16. final Locale overriddenLocale;
  17. @override
  18. bool isSupported(Locale locale) => ['en', 'zh'].contains(locale.languageCode);
  19. @override
  20. Future<I18n> load(Locale locale) {
  21. return SynchronousFuture<I18n>(I18n(overriddenLocale));
  22. }
  23. @override
  24. bool shouldReload(AppLocalizationsDelegate old) => true;
  25. }