flutter_localization_tut
import 'package:flutter/material.dart'; | |
import 'dart:async'; | |
import 'package:intl/intl.dart'; | |
import 'l10n/messages_all.dart'; | |
class AppLocalizations { | |
static Future<AppLocalizations> 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 AppLocalizations(); | |
}); | |
} | |
static AppLocalizations of(BuildContext context) { | |
return Localizations.of<AppLocalizations>(context, AppLocalizations); | |
} | |
title() => Intl.message( | |
'Counter Tutorial', | |
name: "title", | |
desc: "Name of the tutorial", | |
); | |
text(counter) => Intl.message( | |
'You have pushed the button $counter times:', | |
name: "text", | |
args: [counter], | |
desc: "Our Text to localize", | |
); | |
} | |
class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> { | |
const AppLocalizationsDelegate(); | |
@override | |
bool isSupported(Locale locale) => ['en', 'de', 'ru'].contains(locale.languageCode); | |
@override | |
Future<AppLocalizations> load(Locale locale) => AppLocalizations.load(locale); | |
@override | |
bool shouldReload(AppLocalizationsDelegate old) => false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment