Last active
June 28, 2019 11:52
-
-
Save puneetsethi25/76ad804f036f69c00639a9b19e445539 to your computer and use it in GitHub Desktop.
Custom AppLocalization class for localization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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