1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-28 14:05:45 +00:00

Localization

This commit is contained in:
Yan Maniez 2020-03-02 17:20:06 +01:00
parent dece242a54
commit 6f3a87ac5e
15 changed files with 268 additions and 56 deletions

1
.gitignore vendored
View file

@ -266,3 +266,4 @@ __pycache__/
/AideDeJeu/AideDeJeuWeb/Properties/PublishProfiles/AideDeJeuWeb - Web Deploy.pubxml
*.lock
*.lock
*.lock

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,8 @@
{
"@@locale": "en",
"title": "Hello World",
"@title": {
"description": "Title for the Demo application",
"type": "text"
}
}

View file

@ -0,0 +1,8 @@
{
"@@locale": "fr",
"title": "Bonjour Monde",
"@title": {
"description": "Title for the Demo application",
"type": "text"
}
}

View file

@ -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": {}
}
}

View file

@ -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<dynamic> LibraryLoader();
Map<String, LibraryLoader> _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<bool> 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);
}

View file

@ -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<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"title" : MessageLookupByLibrary.simpleMessage("Hello World")
};
}

View file

@ -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<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'fr';
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"title" : MessageLookupByLibrary.simpleMessage("Bonjour Monde")
};
}

View 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;
}

View file

@ -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(),
);
}
}

View file

@ -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: <Widget>[
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: <Widget>[
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',
),
),
),
),
],
));
}
}

View file

@ -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"

View file

@ -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