|
|
|
@ -11,6 +11,7 @@
|
|
|
|
|
|
|
|
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
|
|
import 'package:flutter/foundation.dart'; |
|
|
|
|
import 'package:intl/intl.dart'; |
|
|
|
|
import 'package:intl/message_lookup_by_library.dart'; |
|
|
|
|
import 'package:intl/src/intl_helpers.dart'; |
|
|
|
@ -24,12 +25,12 @@ import 'messages_zh_TW.dart' as messages_zh_tw;
|
|
|
|
|
|
|
|
|
|
typedef Future<dynamic> LibraryLoader(); |
|
|
|
|
Map<String, LibraryLoader> _deferredLibraries = { |
|
|
|
|
'en': () => new Future.value(null), |
|
|
|
|
'en_US': () => new Future.value(null), |
|
|
|
|
'zh_CN': () => new Future.value(null), |
|
|
|
|
'zh_Hans_CN': () => new Future.value(null), |
|
|
|
|
'zh_Hant_CN': () => new Future.value(null), |
|
|
|
|
'zh_TW': () => new Future.value(null), |
|
|
|
|
'en': () => new SynchronousFuture(null), |
|
|
|
|
'en_US': () => new SynchronousFuture(null), |
|
|
|
|
'zh_CN': () => new SynchronousFuture(null), |
|
|
|
|
'zh_Hans_CN': () => new SynchronousFuture(null), |
|
|
|
|
'zh_Hant_CN': () => new SynchronousFuture(null), |
|
|
|
|
'zh_TW': () => new SynchronousFuture(null), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
MessageLookupByLibrary _findExact(String localeName) { |
|
|
|
@ -52,19 +53,18 @@ MessageLookupByLibrary _findExact(String localeName) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// User programs should call this before using [localeName] for messages. |
|
|
|
|
Future<bool> initializeMessages(String localeName) async { |
|
|
|
|
Future<bool> initializeMessages(String localeName) { |
|
|
|
|
var availableLocale = Intl.verifiedLocale( |
|
|
|
|
localeName, |
|
|
|
|
(locale) => _deferredLibraries[locale] != null, |
|
|
|
|
localeName, (locale) => _deferredLibraries[locale] != null, |
|
|
|
|
onFailure: (_) => null); |
|
|
|
|
if (availableLocale == null) { |
|
|
|
|
return new Future.value(false); |
|
|
|
|
return new SynchronousFuture(false); |
|
|
|
|
} |
|
|
|
|
var lib = _deferredLibraries[availableLocale]; |
|
|
|
|
await (lib == null ? new Future.value(false) : lib()); |
|
|
|
|
lib == null ? new SynchronousFuture(false) : lib(); |
|
|
|
|
initializeInternalMessageLookup(() => new CompositeMessageLookup()); |
|
|
|
|
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor); |
|
|
|
|
return new Future.value(true); |
|
|
|
|
return new SynchronousFuture(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool _messagesExistFor(String locale) { |
|
|
|
@ -76,8 +76,8 @@ bool _messagesExistFor(String locale) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MessageLookupByLibrary _findGeneratedMessagesFor(String locale) { |
|
|
|
|
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, |
|
|
|
|
onFailure: (_) => null); |
|
|
|
|
var actualLocale = |
|
|
|
|
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null); |
|
|
|
|
if (actualLocale == null) return null; |
|
|
|
|
return _findExact(actualLocale); |
|
|
|
|
} |
|
|
|
|