diff --git a/.gitignore b/.gitignore index 276d4d65..2ba98b49 100644 --- a/.gitignore +++ b/.gitignore @@ -266,3 +266,4 @@ __pycache__/ /AideDeJeu/AideDeJeuWeb/Properties/PublishProfiles/AideDeJeuWeb - Web Deploy.pubxml *.lock *.lock +*.lock diff --git a/aidedejeu_flutter/buildarb.bat b/aidedejeu_flutter/buildarb.bat new file mode 100644 index 00000000..1db74e32 --- /dev/null +++ b/aidedejeu_flutter/buildarb.bat @@ -0,0 +1 @@ +call C:\dev\flutter\bin\flutter.bat pub pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/localization.dart diff --git a/aidedejeu_flutter/buildarben.bat b/aidedejeu_flutter/buildarben.bat new file mode 100644 index 00000000..d6fc96d6 --- /dev/null +++ b/aidedejeu_flutter/buildarben.bat @@ -0,0 +1 @@ +call C:\dev\flutter\bin\flutter.bat pub pub run intl_translation:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/localization.dart lib/l10n/intl_en.arb diff --git a/aidedejeu_flutter/buildarbfr.bat b/aidedejeu_flutter/buildarbfr.bat new file mode 100644 index 00000000..7ad04e94 --- /dev/null +++ b/aidedejeu_flutter/buildarbfr.bat @@ -0,0 +1 @@ +call C:\dev\flutter\bin\flutter.bat pub pub run intl_translation:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/localization.dart lib/l10n/intl_fr.arb \ No newline at end of file diff --git a/aidedejeu_flutter/lib/l10n/intl_en.arb b/aidedejeu_flutter/lib/l10n/intl_en.arb new file mode 100644 index 00000000..4594f944 --- /dev/null +++ b/aidedejeu_flutter/lib/l10n/intl_en.arb @@ -0,0 +1,8 @@ +{ + "@@locale": "en", + "title": "Hello World", + "@title": { + "description": "Title for the Demo application", + "type": "text" + } +} \ No newline at end of file diff --git a/aidedejeu_flutter/lib/l10n/intl_fr.arb b/aidedejeu_flutter/lib/l10n/intl_fr.arb new file mode 100644 index 00000000..fa2778ac --- /dev/null +++ b/aidedejeu_flutter/lib/l10n/intl_fr.arb @@ -0,0 +1,8 @@ +{ + "@@locale": "fr", + "title": "Bonjour Monde", + "@title": { + "description": "Title for the Demo application", + "type": "text" + } +} \ No newline at end of file diff --git a/aidedejeu_flutter/lib/l10n/intl_messages.arb b/aidedejeu_flutter/lib/l10n/intl_messages.arb new file mode 100644 index 00000000..8a6cba86 --- /dev/null +++ b/aidedejeu_flutter/lib/l10n/intl_messages.arb @@ -0,0 +1,9 @@ +{ + "@@last_modified": "2020-03-02T17:18:13.928618", + "title": "Hello World", + "@title": { + "description": "Title for the Demo application", + "type": "text", + "placeholders": {} + } +} \ No newline at end of file diff --git a/aidedejeu_flutter/lib/l10n/messages_all.dart b/aidedejeu_flutter/lib/l10n/messages_all.dart new file mode 100644 index 00000000..3a5944b0 --- /dev/null +++ b/aidedejeu_flutter/lib/l10n/messages_all.dart @@ -0,0 +1,63 @@ +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that looks up messages for specific locales by +// delegating to the appropriate library. + +// Ignore issues from commonly used lints in this file. +// ignore_for_file:implementation_imports, file_names, unnecessary_new +// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering +// ignore_for_file:argument_type_not_assignable, invalid_assignment +// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases +// ignore_for_file:comment_references + +import 'dart:async'; + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; +import 'package:intl/src/intl_helpers.dart'; + +import 'messages_fr.dart' as messages_fr; + +typedef Future LibraryLoader(); +Map _deferredLibraries = { + 'fr': () => new Future.value(null), +}; + +MessageLookupByLibrary _findExact(String localeName) { + switch (localeName) { + case 'fr': + return messages_fr.messages; + default: + return null; + } +} + +/// User programs should call this before using [localeName] for messages. +Future initializeMessages(String localeName) async { + var availableLocale = Intl.verifiedLocale( + localeName, + (locale) => _deferredLibraries[locale] != null, + onFailure: (_) => null); + if (availableLocale == null) { + return new Future.value(false); + } + var lib = _deferredLibraries[availableLocale]; + await (lib == null ? new Future.value(false) : lib()); + initializeInternalMessageLookup(() => new CompositeMessageLookup()); + messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor); + return new Future.value(true); +} + +bool _messagesExistFor(String locale) { + try { + return _findExact(locale) != null; + } catch (e) { + return false; + } +} + +MessageLookupByLibrary _findGeneratedMessagesFor(String locale) { + var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, + onFailure: (_) => null); + if (actualLocale == null) return null; + return _findExact(actualLocale); +} diff --git a/aidedejeu_flutter/lib/l10n/messages_en.dart b/aidedejeu_flutter/lib/l10n/messages_en.dart new file mode 100644 index 00000000..9561adf2 --- /dev/null +++ b/aidedejeu_flutter/lib/l10n/messages_en.dart @@ -0,0 +1,26 @@ +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that provides messages for a en locale. All the +// messages from the main program should be duplicated here with the same +// function name. + +// Ignore issues from commonly used lints in this file. +// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new +// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering +// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases +// ignore_for_file:unused_import, file_names + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; + +final messages = new MessageLookup(); + +typedef String MessageIfAbsent(String messageStr, List args); + +class MessageLookup extends MessageLookupByLibrary { + String get localeName => 'en'; + + final messages = _notInlinedMessages(_notInlinedMessages); + static _notInlinedMessages(_) => { + "title" : MessageLookupByLibrary.simpleMessage("Hello World") + }; +} diff --git a/aidedejeu_flutter/lib/l10n/messages_fr.dart b/aidedejeu_flutter/lib/l10n/messages_fr.dart new file mode 100644 index 00000000..ca991755 --- /dev/null +++ b/aidedejeu_flutter/lib/l10n/messages_fr.dart @@ -0,0 +1,26 @@ +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that provides messages for a fr locale. All the +// messages from the main program should be duplicated here with the same +// function name. + +// Ignore issues from commonly used lints in this file. +// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new +// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering +// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases +// ignore_for_file:unused_import, file_names + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; + +final messages = new MessageLookup(); + +typedef String MessageIfAbsent(String messageStr, List args); + +class MessageLookup extends MessageLookupByLibrary { + String get localeName => 'fr'; + + final messages = _notInlinedMessages(_notInlinedMessages); + static _notInlinedMessages(_) => { + "title" : MessageLookupByLibrary.simpleMessage("Bonjour Monde") + }; +} diff --git a/aidedejeu_flutter/lib/localization.dart b/aidedejeu_flutter/lib/localization.dart new file mode 100644 index 00000000..cacf98fc --- /dev/null +++ b/aidedejeu_flutter/lib/localization.dart @@ -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 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(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 { + const AppLocalizationsDelegate(); + + @override + bool isSupported(Locale locale) => ['en', 'fr'].contains(locale.languageCode); + + @override + Future load(Locale locale) => AppLocalizations.load(locale); + + @override + bool shouldReload(AppLocalizationsDelegate old) => false; +} diff --git a/aidedejeu_flutter/lib/main.dart b/aidedejeu_flutter/lib/main.dart index 8bbb2344..ee1d8019 100644 --- a/aidedejeu_flutter/lib/main.dart +++ b/aidedejeu_flutter/lib/main.dart @@ -1,6 +1,8 @@ +import 'package:aidedejeu_flutter/localization.dart'; import 'package:aidedejeu_flutter/theme.dart'; import 'package:aidedejeu_flutter/widgets/homepage.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; void main() => runApp(MyApp()); @@ -8,9 +10,20 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Haches & Dés', + //title: 'Haches & Dés', + onGenerateTitle: (BuildContext context) => AppLocalizations.of(context).title, + localizationsDelegates: [ + const AppLocalizationsDelegate(), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + supportedLocales: [ + const Locale('en', ''), + const Locale('fr', ''), + ], theme: mainTheme(), home: HomePage(), ); } } + diff --git a/aidedejeu_flutter/lib/widgets/homepage.dart b/aidedejeu_flutter/lib/widgets/homepage.dart index d9d7a48a..658debce 100644 --- a/aidedejeu_flutter/lib/widgets/homepage.dart +++ b/aidedejeu_flutter/lib/widgets/homepage.dart @@ -1,12 +1,7 @@ -import 'package:aidedejeu_flutter/database.dart'; -import 'package:aidedejeu_flutter/models/filters.dart'; -import 'package:aidedejeu_flutter/widgets/filters.dart'; -import 'package:aidedejeu_flutter/models/items.dart'; +import 'package:aidedejeu_flutter/localization.dart'; import 'package:aidedejeu_flutter/widgets/library.dart'; import 'package:aidedejeu_flutter/widgets/pceditor.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'; class HomePage extends StatelessWidget { @@ -15,52 +10,67 @@ class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: Text("Haches & Dés"),), + appBar: AppBar( + title: Text( + AppLocalizations.of(context).title, + ), + ), body: Column( - children: [ - FlatButton.icon( - label: Text("Bibliothèque"), - icon: SvgPicture.asset( - "assets/spell-book.svg", - height: 100.0, - width: 100.0, - allowDrawingOutsideViewBox: true, - ), - onPressed: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => LibraryPage(id: 'index.md')), - ), - ), - FlatButton.icon( - label: Text("Personnages"), - icon: SvgPicture.asset( - "assets/swordman.svg", - height: 100.0, - width: 100.0, - allowDrawingOutsideViewBox: true, - ), - onPressed: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => PCEditorPage()), - ), - ), - FlatButton.icon( - label: Text("A propos de..."), - icon: SvgPicture.asset( - "assets/wooden-sign.svg", - height: 100.0, - width: 100.0, - allowDrawingOutsideViewBox: true, - ), - onPressed: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => LibraryPage(id: 'index.md')), - ), - ), - ], - )); + children: [ + FlatButton.icon( + label: Text("Bibliothèque"), + icon: SvgPicture.asset( + "assets/spell-book.svg", + height: 100.0, + width: 100.0, + allowDrawingOutsideViewBox: true, + ), + onPressed: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage( + id: 'index.md', + ), + ), + ), + ), + FlatButton.icon( + label: Text( + "Personnages", + ), + icon: SvgPicture.asset( + "assets/swordman.svg", + height: 100.0, + width: 100.0, + allowDrawingOutsideViewBox: true, + ), + onPressed: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PCEditorPage(), + ), + ), + ), + FlatButton.icon( + label: Text( + "A propos de...", + ), + icon: SvgPicture.asset( + "assets/wooden-sign.svg", + height: 100.0, + width: 100.0, + allowDrawingOutsideViewBox: true, + ), + onPressed: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage( + id: 'index.md', + ), + ), + ), + ), + ], + )); } } diff --git a/aidedejeu_flutter/pubspec.lock b/aidedejeu_flutter/pubspec.lock index 03ddf963..96841cb3 100644 --- a/aidedejeu_flutter/pubspec.lock +++ b/aidedejeu_flutter/pubspec.lock @@ -157,14 +157,14 @@ packages: source: hosted version: "2.1.4" intl: - dependency: transitive + dependency: "direct main" description: name: intl url: "https://pub.dartlang.org" source: hosted version: "0.16.1" intl_translation: - dependency: "direct dev" + dependency: "direct main" description: name: intl_translation url: "https://pub.dartlang.org" diff --git a/aidedejeu_flutter/pubspec.yaml b/aidedejeu_flutter/pubspec.yaml index 34665840..2d9d01df 100644 --- a/aidedejeu_flutter/pubspec.yaml +++ b/aidedejeu_flutter/pubspec.yaml @@ -21,6 +21,8 @@ dependencies: sdk: flutter flutter_localizations: sdk: flutter + intl: + intl_translation: flutter_markdown: ^0.3.3 sqflite: path: @@ -34,7 +36,6 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - intl_translation: # For information on the generic Dart part of this file, see the