Add localizations system

This commit is contained in:
Christian Pauly 2020-01-20 09:50:49 +01:00
commit 1f230c0a63
12 changed files with 437 additions and 18 deletions

62
lib/i18n/i18n.dart Normal file
View file

@ -0,0 +1,62 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'messages_all.dart';
class I18n {
I18n(this.localeName);
static Future<I18n> load(Locale locale) {
final String name =
locale.countryCode.isEmpty ? locale.languageCode : locale.toString();
final String localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((_) {
return I18n(localeName);
});
}
static I18n of(BuildContext context) {
return Localizations.of<I18n>(context, I18n);
}
final String localeName;
/* <=============> Translations <=============> */
String get close => Intl.message("Close");
String get confirm => Intl.message("Confirm");
String get create => Intl.message("Create");
String get createNewGroup => Intl.message("Create new group");
String get enterAGroupName => Intl.message("Enter a group name");
String get enterAUsername => Intl.message("Enter a username");
String get groupIsPublic => Intl.message("Group is public");
String get makeSureTheIdentifierIsValid =>
Intl.message("Make sure the identifier is valid");
String get newPrivateChat => Intl.message("New private chat");
String get optionalGroupName => Intl.message("(Optional) Group name");
String get pleaseEnterAMatrixIdentifier =>
Intl.message('Please enter a matrix identifier');
String get title => Intl.message(
'FluffyChat',
name: 'title',
desc: 'Title for the application',
locale: localeName,
);
String get username => Intl.message("Username");
String get youCannotInviteYourself =>
Intl.message("You cannot invite yourself");
String get yourOwnUsername => Intl.message("Your own username");
}

9
lib/i18n/intl_de.arb Normal file
View file

@ -0,0 +1,9 @@
{
"@@last_modified": "2020-01-20T09:30:07.159333",
"title": "FluffyChat",
"@title": {
"description": "Title for the application",
"type": "text",
"placeholders": {}
}
}

View file

@ -0,0 +1,79 @@
{
"@@last_modified": "2020-01-20T09:50:21.386565",
"Close": "Close",
"@Close": {
"type": "text",
"placeholders": {}
},
"Confirm": "Confirm",
"@Confirm": {
"type": "text",
"placeholders": {}
},
"Create": "Create",
"@Create": {
"type": "text",
"placeholders": {}
},
"Create new group": "Create new group",
"@Create new group": {
"type": "text",
"placeholders": {}
},
"Enter a group name": "Enter a group name",
"@Enter a group name": {
"type": "text",
"placeholders": {}
},
"Enter a username": "Enter a username",
"@Enter a username": {
"type": "text",
"placeholders": {}
},
"Group is public": "Group is public",
"@Group is public": {
"type": "text",
"placeholders": {}
},
"Make sure the identifier is valid": "Make sure the identifier is valid",
"@Make sure the identifier is valid": {
"type": "text",
"placeholders": {}
},
"New private chat": "New private chat",
"@New private chat": {
"type": "text",
"placeholders": {}
},
"(Optional) Group name": "(Optional) Group name",
"@(Optional) Group name": {
"type": "text",
"placeholders": {}
},
"Please enter a matrix identifier": "Please enter a matrix identifier",
"@Please enter a matrix identifier": {
"type": "text",
"placeholders": {}
},
"title": "FluffyChat",
"@title": {
"description": "Title for the application",
"type": "text",
"placeholders": {}
},
"Username": "Username",
"@Username": {
"type": "text",
"placeholders": {}
},
"You cannot invite yourself": "You cannot invite yourself",
"@You cannot invite yourself": {
"type": "text",
"placeholders": {}
},
"Your own username": "Your own username",
"@Your own username": {
"type": "text",
"placeholders": {}
}
}

View file

@ -0,0 +1,67 @@
// 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_de.dart' as messages_de;
import 'messages_messages.dart' as messages_messages;
typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'de': () => new Future.value(null),
'messages': () => new Future.value(null),
};
MessageLookupByLibrary _findExact(String localeName) {
switch (localeName) {
case 'de':
return messages_de.messages;
case 'messages':
return messages_messages.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);
}

26
lib/i18n/messages_de.dart Normal file
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 de 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 => 'de';
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
};
}

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 messages 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 => 'messages';
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
};
}