Advertisement
Guest User

Untitled

a guest
May 21st, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import 'dart:async';
  2.  
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:intl/intl.dart';
  6.  
  7. class MyLocalizations {
  8. MyLocalizations(this.locale);
  9.  
  10. final Locale locale;
  11. Map<String, Map<String, String>> _localizedValues = {
  12. 'en': {
  13.  
  14. },
  15. 'uk': {
  16.  
  17. },
  18. 'ru': {
  19.  
  20. },
  21. 'pl': {
  22.  
  23. },
  24. "de": {
  25.  
  26. }
  27. };
  28.  
  29. String translate(key) {
  30. if ([locale.languageCode].contains(locale.languageCode))
  31. return _localizedValues[locale.languageCode][key];
  32. else
  33. return _localizedValues["en"][key];
  34. }
  35.  
  36. static String of(BuildContext context, String key) {
  37. return Localizations.of<MyLocalizations>(context, MyLocalizations)
  38. .translate(key);
  39. }
  40. }
  41.  
  42. class MyLocalizationsDelegate extends LocalizationsDelegate<MyLocalizations> {
  43. const MyLocalizationsDelegate();
  44.  
  45. @override
  46. bool isSupported(Locale locale) => true;
  47.  
  48. @override
  49. Future<MyLocalizations> load(Locale locale) {
  50. return SynchronousFuture<MyLocalizations>(MyLocalizations(locale));
  51. }
  52.  
  53. @override
  54. bool shouldReload(MyLocalizationsDelegate old) => false;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement