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

Unified Diff: pkg/intl/example/basic/messages_all.dart

Issue 12733003: Adds facilities for extracting Intl.message calls and generating code from translations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes from review comments, also made tests more robust, removed scheduled_test dependency Created 7 years, 9 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
Index: pkg/intl/example/basic/messages_all.dart
diff --git a/pkg/intl/example/basic/messages_all.dart b/pkg/intl/example/basic/messages_all.dart
index 43629f23a478fb72d458d35164dd3ace2cc675d8..e722f6c6cc7335f77baf8b80c04ad651e329e66c 100644
--- a/pkg/intl/example/basic/messages_all.dart
+++ b/pkg/intl/example/basic/messages_all.dart
@@ -3,12 +3,36 @@
// BSD-style license that can be found in the LICENSE file.
/**
- * In order to avoid needing to import the libraries for each locale
- * individually in each program file, we make a separate library that imports
- * all of them. In this example there's only one program file, so it doesn't
- * make very much difference.
+ * This imports all of the different message libraries and provides an
+ * [initializeMessages] function that sets up the lookup for a particular
+ * library.
*/
library messages_all;
+import 'dart:async';
+import 'package:intl/message_lookup_by_library.dart';
+import 'package:intl/src/intl_helpers.dart';
import 'messages_th_th.dart' as th_TH;
import 'messages_de.dart' as de;
+import 'package:intl/intl.dart';
+
+// TODO(alanknight): Use lazy loading of the requested library.
+MessageLookupByLibrary _findExact(localeName) {
+ switch (localeName) {
+ case 'th_TH' : return th_TH.messages;
+ case 'de' : return de.messages;
+ default: return null;
+ }
+}
+
+initializeMessages(localeName) {
+ initializeInternalMessageLookup(() => new CompositeMessageLookup());
+ messageLookup.addLocale(localeName, _findGeneratedMessagesFor);
+ return new Future.immediate(null);
+}
+
+MessageLookupByLibrary _findGeneratedMessagesFor(locale) {
+ var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null);
+ if (actualLocale == null) return null;
+ return _findExact(actualLocale);
+}

Powered by Google App Engine
This is Rietveld 408576698