From 622b6a3196e147136d5f50bea14d6fb59192c407 Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Mon, 2 Mar 2020 17:46:30 +0100 Subject: [PATCH] Localization --- aidedejeu_flutter/lib/l10n/intl_en.arb | 39 +++++++++- aidedejeu_flutter/lib/l10n/intl_fr.arb | 39 +++++++++- aidedejeu_flutter/lib/l10n/intl_messages.arb | 38 +++++++++- aidedejeu_flutter/lib/l10n/messages_en.dart | 7 +- aidedejeu_flutter/lib/l10n/messages_fr.dart | 7 +- aidedejeu_flutter/lib/localization.dart | 54 ++++++++++++- aidedejeu_flutter/lib/main.dart | 4 +- aidedejeu_flutter/lib/widgets/homepage.dart | 10 ++- aidedejeu_flutter/lib/widgets/library.dart | 80 +++++++++++--------- 9 files changed, 218 insertions(+), 60 deletions(-) diff --git a/aidedejeu_flutter/lib/l10n/intl_en.arb b/aidedejeu_flutter/lib/l10n/intl_en.arb index 4594f944..90989880 100644 --- a/aidedejeu_flutter/lib/l10n/intl_en.arb +++ b/aidedejeu_flutter/lib/l10n/intl_en.arb @@ -1,8 +1,39 @@ { "@@locale": "en", - "title": "Hello World", - "@title": { - "description": "Title for the Demo application", - "type": "text" + "app_title": "Hello World", + "@app_title": { + "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", + "placeholders": {} } } \ No newline at end of file diff --git a/aidedejeu_flutter/lib/l10n/intl_fr.arb b/aidedejeu_flutter/lib/l10n/intl_fr.arb index fa2778ac..a84ed731 100644 --- a/aidedejeu_flutter/lib/l10n/intl_fr.arb +++ b/aidedejeu_flutter/lib/l10n/intl_fr.arb @@ -1,8 +1,39 @@ { "@@locale": "fr", - "title": "Bonjour Monde", - "@title": { - "description": "Title for the Demo application", - "type": "text" + "app_title": "Bonjour Monde", + "@app_title": { + "description": "Title for the application", + "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": {} } } \ No newline at end of file diff --git a/aidedejeu_flutter/lib/l10n/intl_messages.arb b/aidedejeu_flutter/lib/l10n/intl_messages.arb index 8a6cba86..37e8b114 100644 --- a/aidedejeu_flutter/lib/l10n/intl_messages.arb +++ b/aidedejeu_flutter/lib/l10n/intl_messages.arb @@ -1,8 +1,38 @@ { - "@@last_modified": "2020-03-02T17:18:13.928618", - "title": "Hello World", - "@title": { - "description": "Title for the Demo application", + "@@last_modified": "2020-03-02T17:41:08.588343", + "app_title": "Hello World", + "@app_title": { + "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", "placeholders": {} } diff --git a/aidedejeu_flutter/lib/l10n/messages_en.dart b/aidedejeu_flutter/lib/l10n/messages_en.dart index 9561adf2..b9446533 100644 --- a/aidedejeu_flutter/lib/l10n/messages_en.dart +++ b/aidedejeu_flutter/lib/l10n/messages_en.dart @@ -21,6 +21,11 @@ class MessageLookup extends MessageLookupByLibrary { final messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { - "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") }; } diff --git a/aidedejeu_flutter/lib/l10n/messages_fr.dart b/aidedejeu_flutter/lib/l10n/messages_fr.dart index ca991755..ee8ad916 100644 --- a/aidedejeu_flutter/lib/l10n/messages_fr.dart +++ b/aidedejeu_flutter/lib/l10n/messages_fr.dart @@ -21,6 +21,11 @@ class MessageLookup extends MessageLookupByLibrary { final messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { - "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") }; } diff --git a/aidedejeu_flutter/lib/localization.dart b/aidedejeu_flutter/lib/localization.dart index cacf98fc..fc4afcc9 100644 --- a/aidedejeu_flutter/lib/localization.dart +++ b/aidedejeu_flutter/lib/localization.dart @@ -6,7 +6,8 @@ class AppLocalizations { AppLocalizations(this.localeName); static Future 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); return initializeMessages(localeName).then((_) { @@ -20,11 +21,56 @@ class AppLocalizations { final String localeName; - String get title { + String get app_title { return Intl.message( 'Hello World', - name: 'title', - desc: 'Title for the Demo application', + name: 'app_title', + 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, ); } diff --git a/aidedejeu_flutter/lib/main.dart b/aidedejeu_flutter/lib/main.dart index ee1d8019..7a896b64 100644 --- a/aidedejeu_flutter/lib/main.dart +++ b/aidedejeu_flutter/lib/main.dart @@ -11,7 +11,8 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( //title: 'Haches & Dés', - onGenerateTitle: (BuildContext context) => AppLocalizations.of(context).title, + onGenerateTitle: (BuildContext context) => + AppLocalizations.of(context).app_title, localizationsDelegates: [ const AppLocalizationsDelegate(), GlobalMaterialLocalizations.delegate, @@ -26,4 +27,3 @@ class MyApp extends StatelessWidget { ); } } - diff --git a/aidedejeu_flutter/lib/widgets/homepage.dart b/aidedejeu_flutter/lib/widgets/homepage.dart index 658debce..ea54c2da 100644 --- a/aidedejeu_flutter/lib/widgets/homepage.dart +++ b/aidedejeu_flutter/lib/widgets/homepage.dart @@ -12,13 +12,15 @@ class HomePage extends StatelessWidget { return Scaffold( appBar: AppBar( title: Text( - AppLocalizations.of(context).title, + AppLocalizations.of(context).app_title, ), ), body: Column( children: [ FlatButton.icon( - label: Text("Bibliothèque"), + label: Text( + AppLocalizations.of(context).library_title, + ), icon: SvgPicture.asset( "assets/spell-book.svg", height: 100.0, @@ -36,7 +38,7 @@ class HomePage extends StatelessWidget { ), FlatButton.icon( label: Text( - "Personnages", + AppLocalizations.of(context).pceditor_title, ), icon: SvgPicture.asset( "assets/swordman.svg", @@ -53,7 +55,7 @@ class HomePage extends StatelessWidget { ), FlatButton.icon( label: Text( - "A propos de...", + AppLocalizations.of(context).about_title, ), icon: SvgPicture.asset( "assets/wooden-sign.svg", diff --git a/aidedejeu_flutter/lib/widgets/library.dart b/aidedejeu_flutter/lib/widgets/library.dart index 923e6368..14d2bb8f 100644 --- a/aidedejeu_flutter/lib/widgets/library.dart +++ b/aidedejeu_flutter/lib/widgets/library.dart @@ -1,9 +1,9 @@ import 'package:aidedejeu_flutter/database.dart'; +import 'package:aidedejeu_flutter/localization.dart'; import 'package:aidedejeu_flutter/models/filters.dart'; import 'package:aidedejeu_flutter/widgets/filters.dart'; import 'package:aidedejeu_flutter/models/items.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -29,8 +29,8 @@ class _LibraryPageState extends State { } this.markdown = item.markdown.replaceAllMapped(RegExp(r''), (match) { - return ''; - }); + return ''; + }); }); } @@ -43,7 +43,6 @@ class _LibraryPageState extends State { void initState() { super.initState(); - _loadItem().then((item) => setItem(item)); } @@ -139,9 +138,18 @@ class _LibraryPageState extends State { List _buildBottomNavigationBarItems() { return [ - _buildBottomNavigationBarItem("Bibliothèque", "assets/spell-book.svg"), - _buildBottomNavigationBarItem("Favoris", "assets/stars-stack.svg"), - _buildBottomNavigationBarItem("Recherche", "assets/crystal-ball.svg"), + _buildBottomNavigationBarItem( + AppLocalizations.of(context).library_title, + "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 { filter.selectedValues = choices; }); loadChildrenItems(item, filters).then((value) => { - setState(() { - this.item = item; - this.filters = filters; - }) - }); + setState(() { + this.item = item; + this.filters = filters; + }) + }); }, ); } @@ -172,11 +180,11 @@ class _LibraryPageState extends State { filter.rangeValues = values; }); loadChildrenItems(item, filters).then((value) => { - setState(() { - this.item = item; - this.filters = filters; - }) - }); + setState(() { + this.item = item; + this.filters = filters; + }) + }); }); } @@ -238,30 +246,30 @@ class _LibraryPageState extends State { ), endDrawer: filters != null ? Drawer( - child: ListView( - // Important: Remove any padding from the ListView. - padding: EdgeInsets.zero, - children: _buildFilterList()), - ) + child: ListView( + // Important: Remove any padding from the ListView. + padding: EdgeInsets.zero, + children: _buildFilterList()), + ) : null, appBar: AppBar( title: Text(widget.id), actions: filters != null ? [ - Builder( - builder: (context) => IconButton( - icon: SvgPicture.asset( - "assets/funnel.svg", - height: 30.0, - width: 30.0, - allowDrawingOutsideViewBox: true, - ), //Icon(Icons.filter), - onPressed: () => Scaffold.of(context).openEndDrawer(), - tooltip: - MaterialLocalizations.of(context).openAppDrawerTooltip, - ), - ), - ] + Builder( + builder: (context) => IconButton( + icon: SvgPicture.asset( + "assets/funnel.svg", + height: 30.0, + width: 30.0, + allowDrawingOutsideViewBox: true, + ), //Icon(Icons.filter), + onPressed: () => Scaffold.of(context).openEndDrawer(), + tooltip: + MaterialLocalizations.of(context).openAppDrawerTooltip, + ), + ), + ] : null, ), );