mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 15:06:06 +00:00
Localization
This commit is contained in:
parent
dece242a54
commit
6f3a87ac5e
15 changed files with 268 additions and 56 deletions
44
aidedejeu_flutter/lib/localization.dart
Normal file
44
aidedejeu_flutter/lib/localization.dart
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'l10n/messages_all.dart';
|
||||
|
||||
class AppLocalizations {
|
||||
AppLocalizations(this.localeName);
|
||||
|
||||
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((_) {
|
||||
return AppLocalizations(localeName);
|
||||
});
|
||||
}
|
||||
|
||||
static AppLocalizations of(BuildContext context) {
|
||||
return Localizations.of<AppLocalizations>(context, AppLocalizations);
|
||||
}
|
||||
|
||||
final String localeName;
|
||||
|
||||
String get title {
|
||||
return Intl.message(
|
||||
'Hello World',
|
||||
name: 'title',
|
||||
desc: 'Title for the Demo application',
|
||||
locale: localeName,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
|
||||
const AppLocalizationsDelegate();
|
||||
|
||||
@override
|
||||
bool isSupported(Locale locale) => ['en', 'fr'].contains(locale.languageCode);
|
||||
|
||||
@override
|
||||
Future<AppLocalizations> load(Locale locale) => AppLocalizations.load(locale);
|
||||
|
||||
@override
|
||||
bool shouldReload(AppLocalizationsDelegate old) => false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue