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

Side by Side Diff: pkg/intl/lib/src/intl_helpers.dart

Issue 11669013: Document date format initialization better and make it possible to use en_US dates without it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * A library for general helper code associated with the intl library 6 * A library for general helper code associated with the intl library
7 * rather than confined to specific parts of it. 7 * rather than confined to specific parts of it.
8 */ 8 */
9 9
10 library intl_helpers; 10 library intl_helpers;
11 import '../date_symbols.dart';
11 12
12 /** 13 /**
13 * This is used as a marker for a locale data map that hasn't been initialized, 14 * This is used as a marker for a locale data map that hasn't been initialized,
14 * and will throw an exception on any usage. 15 * and will throw an exception on any usage that isn't the fallback
16 * patterns/symbols provided.
15 */ 17 */
16 class UninitializedLocaleData { 18 class UninitializedLocaleData<F> {
17 final String message; 19 final String message;
18 const UninitializedLocaleData(this.message); 20 final F fallbackData;
21 const UninitializedLocaleData(this.message, this.fallbackData);
19 22
20 operator [](String key) { 23 operator [](String key) =>
21 _throwException(); 24 (key == 'en_US') ? fallbackData : _throwException();
22 }
23 List get keys => _throwException(); 25 List get keys => _throwException();
24 bool containsKey(String key) => _throwException(); 26 bool containsKey(String key) => (key == 'en_US') ? true : _throwException();
25 27
26 _throwException() { 28 _throwException() {
27 throw new LocaleDataException("Locale data has not been initialized" 29 throw new LocaleDataException("Locale data has not been initialized"
28 ", call $message."); 30 ", call $message.");
29 } 31 }
30 } 32 }
31 33
32 class LocaleDataException implements Exception { 34 class LocaleDataException implements Exception {
33 final String message; 35 final String message;
34 LocaleDataException(this.message); 36 LocaleDataException(this.message);
35 toString() => "LocaleDataException: $message"; 37 toString() => "LocaleDataException: $message";
36 } 38 }
37 39
38 /** 40 /**
39 * An abstract superclass for data readers to keep the type system happy. 41 * An abstract superclass for data readers to keep the type system happy.
40 */ 42 */
41 abstract class LocaleDataReader { 43 abstract class LocaleDataReader {
42 Future read(String locale); 44 Future read(String locale);
43 } 45 }
44 46
45 /** 47 /**
46 * The internal mechanism for looking up messages. We expect this to be set 48 * The internal mechanism for looking up messages. We expect this to be set
47 * by the implementing package so that we're not dependent on its 49 * by the implementing package so that we're not dependent on its
48 * implementation. 50 * implementation.
49 */ 51 */
50 var messageLookup = const 52 var messageLookup = const
51 UninitializedLocaleData('initializeMessages(<locale>)'); 53 UninitializedLocaleData('initializeMessages(<locale>)', null);
52 54
53 /** 55 /**
54 * Initialize the message lookup mechanism. This is for internal use only. 56 * Initialize the message lookup mechanism. This is for internal use only.
55 * User applications should import `message_lookup_local.dart` and call 57 * User applications should import `message_lookup_local.dart` and call
56 * `initializeMessages` 58 * `initializeMessages`
57 */ 59 */
58 void initializeInternalMessageLookup(Function lookupFunction) { 60 void initializeInternalMessageLookup(Function lookupFunction) {
59 if (messageLookup is UninitializedLocaleData) { 61 if (messageLookup is UninitializedLocaleData) {
60 messageLookup = lookupFunction(); 62 messageLookup = lookupFunction();
61 } 63 }
62 } 64 }
OLDNEW
« no previous file with comments | « pkg/intl/lib/src/date_format_internal.dart ('k') | pkg/intl/test/date_time_format_test_core.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698