i18n.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import 'dart:async';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. // ignore_for_file: non_constant_identifier_names
  5. // ignore_for_file: camel_case_types
  6. // ignore_for_file: prefer_single_quotes
  7. // This file is automatically generated. DO NOT EDIT, all your changes would be lost.
  8. class S implements WidgetsLocalizations {
  9. const S();
  10. static S current;
  11. static const GeneratedLocalizationsDelegate delegate =
  12. GeneratedLocalizationsDelegate();
  13. static S of(BuildContext context) => Localizations.of<S>(context, S);
  14. @override
  15. TextDirection get textDirection => TextDirection.ltr;
  16. }
  17. class $en extends S {
  18. const $en();
  19. }
  20. class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
  21. const GeneratedLocalizationsDelegate();
  22. List<Locale> get supportedLocales {
  23. return const <Locale>[
  24. Locale("en", ""),
  25. ];
  26. }
  27. LocaleListResolutionCallback listResolution({Locale fallback, bool withCountry = true}) {
  28. return (List<Locale> locales, Iterable<Locale> supported) {
  29. if (locales == null || locales.isEmpty) {
  30. return fallback ?? supported.first;
  31. } else {
  32. return _resolve(locales.first, fallback, supported, withCountry);
  33. }
  34. };
  35. }
  36. LocaleResolutionCallback resolution({Locale fallback, bool withCountry = true}) {
  37. return (Locale locale, Iterable<Locale> supported) {
  38. return _resolve(locale, fallback, supported, withCountry);
  39. };
  40. }
  41. @override
  42. Future<S> load(Locale locale) {
  43. final String lang = getLang(locale);
  44. if (lang != null) {
  45. switch (lang) {
  46. case "en":
  47. S.current = const $en();
  48. return SynchronousFuture<S>(S.current);
  49. default:
  50. // NO-OP.
  51. }
  52. }
  53. S.current = const S();
  54. return SynchronousFuture<S>(S.current);
  55. }
  56. @override
  57. bool isSupported(Locale locale) => _isSupported(locale, true);
  58. @override
  59. bool shouldReload(GeneratedLocalizationsDelegate old) => false;
  60. ///
  61. /// Internal method to resolve a locale from a list of locales.
  62. ///
  63. Locale _resolve(Locale locale, Locale fallback, Iterable<Locale> supported, bool withCountry) {
  64. if (locale == null || !_isSupported(locale, withCountry)) {
  65. return fallback ?? supported.first;
  66. }
  67. final Locale languageLocale = Locale(locale.languageCode, "");
  68. if (supported.contains(locale)) {
  69. return locale;
  70. } else if (supported.contains(languageLocale)) {
  71. return languageLocale;
  72. } else {
  73. final Locale fallbackLocale = fallback ?? supported.first;
  74. return fallbackLocale;
  75. }
  76. }
  77. ///
  78. /// Returns true if the specified locale is supported, false otherwise.
  79. ///
  80. bool _isSupported(Locale locale, bool withCountry) {
  81. if (locale != null) {
  82. for (Locale supportedLocale in supportedLocales) {
  83. // Language must always match both locales.
  84. if (supportedLocale.languageCode != locale.languageCode) {
  85. continue;
  86. }
  87. // If country code matches, return this locale.
  88. if (supportedLocale.countryCode == locale.countryCode) {
  89. return true;
  90. }
  91. // If no country requirement is requested, check if this locale has no country.
  92. if (true != withCountry && (supportedLocale.countryCode == null || supportedLocale.countryCode.isEmpty)) {
  93. return true;
  94. }
  95. }
  96. }
  97. return false;
  98. }
  99. }
  100. String getLang(Locale l) => l == null
  101. ? null
  102. : l.countryCode != null && l.countryCode.isEmpty
  103. ? l.languageCode
  104. : l.toString();