Skip to content

Instantly share code, notes, and snippets.

@tariqhamid
Created September 16, 2020 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tariqhamid/1419baa9da8710a1fe4dfc984e5bae19 to your computer and use it in GitHub Desktop.
Save tariqhamid/1419baa9da8710a1fe4dfc984e5bae19 to your computer and use it in GitHub Desktop.
multi lingual support file
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart' show SynchronousFuture;
class UnicomputeLocalizations {
UnicomputeLocalizations(this.locale);
final Locale locale;
static UnicomputeLocalizations of(BuildContext context) {
return Localizations.of<UnicomputeLocalizations>(context, UnicomputeLocalizations);
}
String operator [](String label) => _localizedValues[locale.languageCode][label];
static Map<String, Map<String, String>> get localizedValues => _localizedValues;
static Map<String, Map<String, String>> _localizedValues = {};
}
class UnicomputeLocalizationsDelegate extends LocalizationsDelegate<UnicomputeLocalizations> {
const UnicomputeLocalizationsDelegate();
@override
bool isSupported(Locale locale) => UnicomputeLocalizations._localizedValues.keys.contains(locale.languageCode);
@override
Future<UnicomputeLocalizations> load(Locale locale) {
return SynchronousFuture<UnicomputeLocalizations>(UnicomputeLocalizations(locale));
}
@override
bool shouldReload(UnicomputeLocalizationsDelegate old) => false;
Iterable<Locale> get supportedLocales => UnicomputeLocalizations.localizedValues.keys.map((lang) => Locale(lang));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment