-
-
Save ijoschek/98b0d81dbbd88d132a4136a1d423e9f5 to your computer and use it in GitHub Desktop.
flutter_localization_tut
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 '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