Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@puneetsethi25
Last active June 28, 2019 11:52
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 puneetsethi25/76ad804f036f69c00639a9b19e445539 to your computer and use it in GitHub Desktop.
Save puneetsethi25/76ad804f036f69c00639a9b19e445539 to your computer and use it in GitHub Desktop.
Custom AppLocalization class for localization
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class AppLocalization {
static Future<AppLocalization> load(Locale locale) {
final String name = locale.countryCode.isEmpty ? locale.languageCode : locale.toString();
final String localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((_) {
Intl.defaultLocale = localeName;
return AppLocalization();
});
}
static AppLocalization of(BuildContext context) {
return Localizations.of<AppLocalization>(context, AppLocalization);
}
// list of locales
String get heyWorld {
return Intl.message(
'Hey World',
name: 'heyWorld',
desc: 'Simpel word for greeting ',
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment