Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. import 'dart:async';
  2.  
  3. import 'package:intl/intl.dart';
  4. import 'package:flutter/widgets.dart';
  5.  
  6. import 'messages_all.dart';
  7.  
  8. /// Callers can lookup localized strings with an instance of DemoLocalizations returned
  9. /// by `DemoLocalizations.of(context)`.
  10. ///
  11. /// Applications need to include `DemoLocalizations.delegate()` in their app's
  12. /// loclalizationDelegates list, and the locales they support in the app's
  13. /// supportedLocales list. For example:
  14. ///
  15. /// ```
  16. /// return MaterialApp(
  17. /// localizationsDelegates: <LocalizationsDelegate<dynamic>>[
  18. /// DemoLocalizations.delegate(),
  19. /// GlobalMaterialLocalizations.delegate,
  20. /// GlobalWidgetsLocalizations.delegate,
  21. /// ],
  22. /// supportedLocales: const <Locale>[
  23. /// Locale('en', 'US'),
  24. /// Locale('es', 'ES'),
  25. /// ],
  26. /// home: MyApplicationHome(),
  27. /// );
  28. /// ```
  29.  
  30. class DemoLocalizations {
  31. DemoLocalizations(Locale locale) : _localeName = locale.toString();
  32.  
  33. final String _localeName;
  34.  
  35. static Future<DemoLocalizations> load(Locale locale) {
  36. return initializeMessages(locale.toString())
  37. .then<DemoLocalizations>((void _) => DemoLocalizations(locale));
  38. }
  39.  
  40. static DemoLocalizations of(BuildContext context) {
  41. return Localizations.of<DemoLocalizations>(context, DemoLocalizations);
  42. }
  43.  
  44. static const LocalizationsDelegate<DemoLocalizations> delegate = _DemoLocalizationsDelegate();
  45.  
  46. String helloWorld() {
  47. return Intl.message(
  48. 'Hello World',
  49. locale: _localeName,
  50. name: 'helloWorld',
  51. desc: 'The conventional newborn programmer greeting'
  52. );
  53. }
  54.  
  55. String hello(Object world) {
  56. return Intl.message(
  57. 'Hello $world',
  58. locale: _localeName,
  59. name: 'hello',
  60. desc: 'A message with a single parameter',
  61. args: [world]
  62. );
  63. }
  64.  
  65. String greeting(Object hello, Object world) {
  66. return Intl.message(
  67. '$hello $world',
  68. locale: _localeName,
  69. name: 'greeting',
  70. desc: 'A message with a two parameters',
  71. args: [hello, world]
  72. );
  73. }
  74.  
  75. String helloWorlds(Object count) {
  76. return Intl.plural(
  77. count,
  78. locale: _localeName,
  79. name: 'helloWorlds',
  80. args: [count],
  81. zero: 'Hello',
  82. one: 'Hello World',
  83. two: 'Hello two worlds',
  84. few: 'Hello $count worlds',
  85. many: 'Hello all $count worlds',
  86. other: 'Hello other $count worlds'
  87. );
  88. }
  89.  
  90. }
  91.  
  92. class _DemoLocalizationsDelegate extends LocalizationsDelegate<DemoLocalizations> {
  93. const _DemoLocalizationsDelegate();
  94.  
  95. @override
  96. Future<DemoLocalizations> load(Locale locale) => DemoLocalizations.load(locale);
  97.  
  98. @override
  99. bool isSupported(Locale locale) => ['en', 'es', 'messages'].contains(locale.languageCode);
  100.  
  101. @override
  102. bool shouldReload(_DemoLocalizationsDelegate old) => false;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement