localization_intl.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:e2ee_chat/common/global.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:intl/intl.dart';
  5. class GmLocalizations {
  6. static GmLocalizations of(BuildContext context) {
  7. return Localizations.of<GmLocalizations>(context, GmLocalizations) ?? GmLocalizations();
  8. }
  9. //TODO: Localizations
  10. String get title => Intl.message('MeChat', name: 'title');
  11. String get userName => Intl.message('Username', name: 'username');
  12. String get userNameOrEmail => Intl.message('Username or Email', name: 'username or email');
  13. String get userNameRequired => Intl.message('Username required', name: 'username required');
  14. String get password => Intl.message('Password', name: 'password');
  15. String get passwordRequired => Intl.message('PasswordRequired', name: 'password required');
  16. String get loading => Intl.message('Loading...', name: 'loading');
  17. String get userNameOrPasswordWrong => Intl.message('Username or password wrong', name: 'username or password wrong');
  18. String get home => Intl.message('Home', name: 'home');
  19. String get login => Intl.message('Login', name: 'login');
  20. String get logout => Intl.message('Logout', name: 'logout');
  21. String get language => Intl.message('Language', name: 'language');
  22. String get auto => Intl.message('Auto', name: 'auto');
  23. String get theme => Intl.message('Theme', name: 'theme');
  24. String get search => Intl.message('Search', name: 'search');
  25. String get searchUser => Intl.message('Find User', name: 'find user');
  26. String get addFriendFailed => Intl.message('Add friend failed', name: 'add friend failed');
  27. String get friendRequest => Intl.message('Friends Request', name: 'friend request');
  28. }
  29. //Locale代理类
  30. class GmLocalizationsDelegate extends LocalizationsDelegate<GmLocalizations> {
  31. const GmLocalizationsDelegate();
  32. //是否支持某个Local
  33. @override
  34. bool isSupported(Locale locale) => Global.locales.contains(locale.languageCode);
  35. // Flutter会调用此类加载相应的Locale资源类
  36. @override
  37. Future<GmLocalizations> load(Locale locale) {
  38. print("$locale");
  39. return SynchronousFuture<GmLocalizations>(
  40. GmLocalizations()
  41. );
  42. }
  43. // 当Localizations Widget重新build时,是否调用load重新加载Locale资源.
  44. @override
  45. bool shouldReload(GmLocalizationsDelegate old) => false;
  46. }