Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Unified Diff: pkg/intl/lib/generate_localized.dart

Issue 290073002: Use deferred loading for message catalogs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review fixes Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/intl/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/intl/lib/generate_localized.dart
diff --git a/pkg/intl/lib/generate_localized.dart b/pkg/intl/lib/generate_localized.dart
index 6289a60f8d5310506b341f21275a8d9d366b9d98..9b8051d2b95b5e8a9e1fa7ee59d0aa9a22aa1d12 100644
--- a/pkg/intl/lib/generate_localized.dart
+++ b/pkg/intl/lib/generate_localized.dart
@@ -179,22 +179,14 @@ String generateMainImportFile() {
for (var locale in allLocales) {
var baseFile = '${generatedFilePrefix}messages_$locale.dart';
var file = importForGeneratedFile(baseFile);
- // TODO(alanknight): Restore this once deferred loading works in dartj2s.
- // Issue 12824
- // output.write("@${_deferredName(locale)}\n");
- output.write("import '$file' as ${_libraryName(locale)};\n");
+ output.write("import '$file' deferred as ${_libraryName(locale)};\n");
}
output.write("\n");
- // Issue 12824
- //for (var locale in allLocales) {
- // output.write("const ${_deferredName(locale)} = const DeferredLibrary");
- // output.write("('${_libraryName(locale)}');\n");
- //}
- //output.write("\nconst deferredLibraries = const {\n");
- //for (var locale in allLocales) {
- // output.write(" '$locale' : ${_deferredName(locale)},\n");
- //}
- //output.write("};\n");
+ output.write("\nMap<String, Function> _deferredLibraries = {\n");
+ for (var locale in allLocales) {
+ output.write(" '$locale' : () => ${_libraryName(locale)}.loadLibrary(),\n");
+ }
+ output.write("};\n");
output.write(
"\nMessageLookupByLibrary _findExact(localeName) {\n"
" switch (localeName) {\n");
@@ -238,11 +230,10 @@ const closing = """
/** User programs should call this before using [localeName] for messages.*/
Future initializeMessages(String localeName) {
initializeInternalMessageLookup(() => new CompositeMessageLookup());
- messageLookup.addLocale(localeName, _findGeneratedMessagesFor);
- // TODO(alanknight): Restore once Issue 12824 is fixed.
- // var lib = deferredLibraries[localeName];
- // return lib == null ? new Future.value(false) : lib.load();
- return new Future.value(true);
+ var lib = _deferredLibraries[Intl.canonicalizedLocale(localeName)];
+ var load = lib == null ? new Future.value(false) : lib();
+ return load.then((_) =>
+ messageLookup.addLocale(localeName, _findGeneratedMessagesFor));
}
MessageLookupByLibrary _findGeneratedMessagesFor(locale) {
« no previous file with comments | « no previous file | pkg/intl/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698