Skip to content

Instantly share code, notes, and snippets.

@ijoschek
Last active December 29, 2018 12:48
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 ijoschek/98b0d81dbbd88d132a4136a1d423e9f5 to your computer and use it in GitHub Desktop.
Save ijoschek/98b0d81dbbd88d132a4136a1d423e9f5 to your computer and use it in GitHub Desktop.
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