1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-29 22:45:44 +00:00

Localization

This commit is contained in:
Yan Maniez 2020-03-02 17:46:30 +01:00
parent 6f3a87ac5e
commit 622b6a3196
9 changed files with 218 additions and 60 deletions

View file

@ -1,8 +1,39 @@
{ {
"@@locale": "en", "@@locale": "en",
"title": "Hello World", "app_title": "Hello World",
"@title": { "@app_title": {
"description": "Title for the Demo application", "description": "Title for the application",
"type": "text" "type": "text",
"placeholders": {}
},
"library_title": "Library",
"@library_title": {
"description": "Title for the Library page",
"type": "text",
"placeholders": {}
},
"pceditor_title": "Player Characters",
"@pceditor_title": {
"description": "Title for the Player Characters page",
"type": "text",
"placeholders": {}
},
"about_title": "About...",
"@about_title": {
"description": "Title for the About page",
"type": "text",
"placeholders": {}
},
"bookmarks_title": "Bookmarks",
"@bookmarks_title": {
"description": "Title for the Bookmarks page",
"type": "text",
"placeholders": {}
},
"search_title": "Search",
"@search_title": {
"description": "Title for the Search page",
"type": "text",
"placeholders": {}
} }
} }

View file

@ -1,8 +1,39 @@
{ {
"@@locale": "fr", "@@locale": "fr",
"title": "Bonjour Monde", "app_title": "Bonjour Monde",
"@title": { "@app_title": {
"description": "Title for the Demo application", "description": "Title for the application",
"type": "text" "type": "text",
"placeholders": {}
},
"library_title": "Bibliothèque",
"@library_title": {
"description": "Title for the Library page",
"type": "text",
"placeholders": {}
},
"pceditor_title": "Personnages",
"@pceditor_title": {
"description": "Title for the Player Characters page",
"type": "text",
"placeholders": {}
},
"about_title": "A propos de...",
"@about_title": {
"description": "Title for the About page",
"type": "text",
"placeholders": {}
},
"bookmarks_title": "Favoris",
"@bookmarks_title": {
"description": "Title for the Bookmarks page",
"type": "text",
"placeholders": {}
},
"search_title": "Recherche",
"@search_title": {
"description": "Title for the Search page",
"type": "text",
"placeholders": {}
} }
} }

View file

@ -1,8 +1,38 @@
{ {
"@@last_modified": "2020-03-02T17:18:13.928618", "@@last_modified": "2020-03-02T17:41:08.588343",
"title": "Hello World", "app_title": "Hello World",
"@title": { "@app_title": {
"description": "Title for the Demo application", "description": "Title for the application",
"type": "text",
"placeholders": {}
},
"library_title": "Library",
"@library_title": {
"description": "Title for the Library page",
"type": "text",
"placeholders": {}
},
"pceditor_title": "Player Characters",
"@pceditor_title": {
"description": "Title for the Player Characters page",
"type": "text",
"placeholders": {}
},
"about_title": "About...",
"@about_title": {
"description": "Title for the About page",
"type": "text",
"placeholders": {}
},
"bookmarks_title": "Bookmarks",
"@bookmarks_title": {
"description": "Title for the Bookmarks page",
"type": "text",
"placeholders": {}
},
"search_title": "Search",
"@search_title": {
"description": "Title for the Search page",
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
} }

View file

@ -21,6 +21,11 @@ class MessageLookup extends MessageLookupByLibrary {
final messages = _notInlinedMessages(_notInlinedMessages); final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> { static _notInlinedMessages(_) => <String, Function> {
"title" : MessageLookupByLibrary.simpleMessage("Hello World") "about_title" : MessageLookupByLibrary.simpleMessage("About..."),
"app_title" : MessageLookupByLibrary.simpleMessage("Hello World"),
"bookmarks_title" : MessageLookupByLibrary.simpleMessage("Bookmarks"),
"library_title" : MessageLookupByLibrary.simpleMessage("Library"),
"pceditor_title" : MessageLookupByLibrary.simpleMessage("Player Characters"),
"search_title" : MessageLookupByLibrary.simpleMessage("Search")
}; };
} }

View file

@ -21,6 +21,11 @@ class MessageLookup extends MessageLookupByLibrary {
final messages = _notInlinedMessages(_notInlinedMessages); final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> { static _notInlinedMessages(_) => <String, Function> {
"title" : MessageLookupByLibrary.simpleMessage("Bonjour Monde") "about_title" : MessageLookupByLibrary.simpleMessage("A propos de..."),
"app_title" : MessageLookupByLibrary.simpleMessage("Bonjour Monde"),
"bookmarks_title" : MessageLookupByLibrary.simpleMessage("Favoris"),
"library_title" : MessageLookupByLibrary.simpleMessage("Bibliothèque"),
"pceditor_title" : MessageLookupByLibrary.simpleMessage("Personnages"),
"search_title" : MessageLookupByLibrary.simpleMessage("Recherche")
}; };
} }

View file

@ -6,7 +6,8 @@ class AppLocalizations {
AppLocalizations(this.localeName); AppLocalizations(this.localeName);
static Future<AppLocalizations> load(Locale locale) { static Future<AppLocalizations> load(Locale locale) {
final String name = locale.countryCode.isEmpty ? locale.languageCode : locale.toString(); final String name =
locale.countryCode.isEmpty ? locale.languageCode : locale.toString();
final String localeName = Intl.canonicalizedLocale(name); final String localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((_) { return initializeMessages(localeName).then((_) {
@ -20,11 +21,56 @@ class AppLocalizations {
final String localeName; final String localeName;
String get title { String get app_title {
return Intl.message( return Intl.message(
'Hello World', 'Hello World',
name: 'title', name: 'app_title',
desc: 'Title for the Demo application', desc: 'Title for the application',
locale: localeName,
);
}
String get library_title {
return Intl.message(
'Library',
name: 'library_title',
desc: 'Title for the Library page',
locale: localeName,
);
}
String get pceditor_title {
return Intl.message(
'Player Characters',
name: 'pceditor_title',
desc: 'Title for the Player Characters page',
locale: localeName,
);
}
String get about_title {
return Intl.message(
'About...',
name: 'about_title',
desc: 'Title for the About page',
locale: localeName,
);
}
String get bookmarks_title {
return Intl.message(
'Bookmarks',
name: 'bookmarks_title',
desc: 'Title for the Bookmarks page',
locale: localeName,
);
}
String get search_title {
return Intl.message(
'Search',
name: 'search_title',
desc: 'Title for the Search page',
locale: localeName, locale: localeName,
); );
} }

View file

@ -11,7 +11,8 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
//title: 'Haches & Dés', //title: 'Haches & Dés',
onGenerateTitle: (BuildContext context) => AppLocalizations.of(context).title, onGenerateTitle: (BuildContext context) =>
AppLocalizations.of(context).app_title,
localizationsDelegates: [ localizationsDelegates: [
const AppLocalizationsDelegate(), const AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate, GlobalMaterialLocalizations.delegate,
@ -26,4 +27,3 @@ class MyApp extends StatelessWidget {
); );
} }
} }

View file

@ -12,13 +12,15 @@ class HomePage extends StatelessWidget {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
AppLocalizations.of(context).title, AppLocalizations.of(context).app_title,
), ),
), ),
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
FlatButton.icon( FlatButton.icon(
label: Text("Bibliothèque"), label: Text(
AppLocalizations.of(context).library_title,
),
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/spell-book.svg", "assets/spell-book.svg",
height: 100.0, height: 100.0,
@ -36,7 +38,7 @@ class HomePage extends StatelessWidget {
), ),
FlatButton.icon( FlatButton.icon(
label: Text( label: Text(
"Personnages", AppLocalizations.of(context).pceditor_title,
), ),
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/swordman.svg", "assets/swordman.svg",
@ -53,7 +55,7 @@ class HomePage extends StatelessWidget {
), ),
FlatButton.icon( FlatButton.icon(
label: Text( label: Text(
"A propos de...", AppLocalizations.of(context).about_title,
), ),
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/wooden-sign.svg", "assets/wooden-sign.svg",

View file

@ -1,9 +1,9 @@
import 'package:aidedejeu_flutter/database.dart'; import 'package:aidedejeu_flutter/database.dart';
import 'package:aidedejeu_flutter/localization.dart';
import 'package:aidedejeu_flutter/models/filters.dart'; import 'package:aidedejeu_flutter/models/filters.dart';
import 'package:aidedejeu_flutter/widgets/filters.dart'; import 'package:aidedejeu_flutter/widgets/filters.dart';
import 'package:aidedejeu_flutter/models/items.dart'; import 'package:aidedejeu_flutter/models/items.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
@ -29,8 +29,8 @@ class _LibraryPageState extends State<LibraryPage> {
} }
this.markdown = this.markdown =
item.markdown.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) { item.markdown.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) {
return ''; return '';
}); });
}); });
} }
@ -43,7 +43,6 @@ class _LibraryPageState extends State<LibraryPage> {
void initState() { void initState() {
super.initState(); super.initState();
_loadItem().then((item) => setItem(item)); _loadItem().then((item) => setItem(item));
} }
@ -139,9 +138,18 @@ class _LibraryPageState extends State<LibraryPage> {
List _buildBottomNavigationBarItems() { List _buildBottomNavigationBarItems() {
return <BottomNavigationBarItem>[ return <BottomNavigationBarItem>[
_buildBottomNavigationBarItem("Bibliothèque", "assets/spell-book.svg"), _buildBottomNavigationBarItem(
_buildBottomNavigationBarItem("Favoris", "assets/stars-stack.svg"), AppLocalizations.of(context).library_title,
_buildBottomNavigationBarItem("Recherche", "assets/crystal-ball.svg"), "assets/spell-book.svg",
),
_buildBottomNavigationBarItem(
AppLocalizations.of(context).bookmarks_title,
"assets/stars-stack.svg",
),
_buildBottomNavigationBarItem(
AppLocalizations.of(context).search_title,
"assets/crystal-ball.svg",
),
]; ];
} }
@ -154,11 +162,11 @@ class _LibraryPageState extends State<LibraryPage> {
filter.selectedValues = choices; filter.selectedValues = choices;
}); });
loadChildrenItems(item, filters).then((value) => { loadChildrenItems(item, filters).then((value) => {
setState(() { setState(() {
this.item = item; this.item = item;
this.filters = filters; this.filters = filters;
}) })
}); });
}, },
); );
} }
@ -172,11 +180,11 @@ class _LibraryPageState extends State<LibraryPage> {
filter.rangeValues = values; filter.rangeValues = values;
}); });
loadChildrenItems(item, filters).then((value) => { loadChildrenItems(item, filters).then((value) => {
setState(() { setState(() {
this.item = item; this.item = item;
this.filters = filters; this.filters = filters;
}) })
}); });
}); });
} }
@ -238,30 +246,30 @@ class _LibraryPageState extends State<LibraryPage> {
), ),
endDrawer: filters != null endDrawer: filters != null
? Drawer( ? Drawer(
child: ListView( child: ListView(
// Important: Remove any padding from the ListView. // Important: Remove any padding from the ListView.
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
children: _buildFilterList()), children: _buildFilterList()),
) )
: null, : null,
appBar: AppBar( appBar: AppBar(
title: Text(widget.id), title: Text(widget.id),
actions: filters != null actions: filters != null
? [ ? [
Builder( Builder(
builder: (context) => IconButton( builder: (context) => IconButton(
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/funnel.svg", "assets/funnel.svg",
height: 30.0, height: 30.0,
width: 30.0, width: 30.0,
allowDrawingOutsideViewBox: true, allowDrawingOutsideViewBox: true,
), //Icon(Icons.filter), ), //Icon(Icons.filter),
onPressed: () => Scaffold.of(context).openEndDrawer(), onPressed: () => Scaffold.of(context).openEndDrawer(),
tooltip: tooltip:
MaterialLocalizations.of(context).openAppDrawerTooltip, MaterialLocalizations.of(context).openAppDrawerTooltip,
), ),
), ),
] ]
: null, : null,
), ),
); );