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

Side by Side Diff: pkg/intl/lib/message_lookup_by_library.dart

Issue 182443003: Add 'meaning' to Intl.messages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/intl/lib/intl.dart ('k') | pkg/intl/lib/src/intl_helpers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Message/plural format library with locale support. This can have different 6 * Message/plural format library with locale support. This can have different
7 * implementations based on the mechanism for finding the localized versions 7 * implementations based on the mechanism for finding the localized versions
8 * of messages. This version expects them to be in a library named e.g. 8 * of messages. This version expects them to be in a library named e.g.
9 * 'messages_en_US'. The prefix is set in the "initializeMessages" call, which 9 * 'messages_en_US'. The prefix is set in the "initializeMessages" call, which
10 * must be made for a locale before any lookups can be done. 10 * must be made for a locale before any lookups can be done.
(...skipping 16 matching lines...) Expand all
27 bool localeExists(localeName) => availableMessages.containsKey(localeName); 27 bool localeExists(localeName) => availableMessages.containsKey(localeName);
28 28
29 /** 29 /**
30 * Look up the message with the given [name] and [locale] and return 30 * Look up the message with the given [name] and [locale] and return
31 * the translated version with the values in [args] interpolated. 31 * the translated version with the values in [args] interpolated.
32 * If nothing is found, return [message_str]. The [desc] and [examples] 32 * If nothing is found, return [message_str]. The [desc] and [examples]
33 * parameters are ignored 33 * parameters are ignored
34 */ 34 */
35 String lookupMessage(String message_str, [final String desc='', 35 String lookupMessage(String message_str, [final String desc='',
36 final Map examples=const {}, String locale, 36 final Map examples=const {}, String locale,
37 String name, List<String> args]) { 37 String name, List<String> args, String meaning]) {
38 var actualLocale = (locale == null) ? Intl.getCurrentLocale() : locale; 38 var actualLocale = (locale == null) ? Intl.getCurrentLocale() : locale;
39 // For this usage, if the locale doesn't exist for messages, just return 39 // For this usage, if the locale doesn't exist for messages, just return
40 // it and we'll fall back to the original version. 40 // it and we'll fall back to the original version.
41 var verifiedLocale = 41 var verifiedLocale =
42 Intl.verifiedLocale( 42 Intl.verifiedLocale(
43 actualLocale, 43 actualLocale,
44 localeExists, 44 localeExists,
45 onFailure: (locale)=>locale); 45 onFailure: (locale)=>locale);
46 var messages = availableMessages[verifiedLocale]; 46 var messages = availableMessages[verifiedLocale];
47 if (messages == null) return message_str; 47 if (messages == null) return message_str;
48 return messages. 48 return messages.
49 lookupMessage(message_str, desc, examples, locale, name, args); 49 lookupMessage(message_str, desc, examples, locale, name, args, meaning);
50 } 50 }
51 51
52 /** 52 /**
53 * If we do not already have a locale for [localeName] then 53 * If we do not already have a locale for [localeName] then
54 * [findLocale] will be called and the result stored as the lookup 54 * [findLocale] will be called and the result stored as the lookup
55 * mechanism for that locale. 55 * mechanism for that locale.
56 */ 56 */
57 addLocale(String localeName, Function findLocale) { 57 addLocale(String localeName, Function findLocale) {
58 if (localeExists(localeName)) return; 58 if (localeExists(localeName)) return;
59 var newLocale = findLocale(localeName); 59 var newLocale = findLocale(localeName);
(...skipping 29 matching lines...) Expand all
89 * at compile time: no String interpolation or concatenation. 89 * at compile time: no String interpolation or concatenation.
90 * The expected usage of this is inside a function that takes as parameters 90 * The expected usage of this is inside a function that takes as parameters
91 * the variables used in the interpolated string. 91 * the variables used in the interpolated string.
92 * 92 *
93 * Ultimately, the information about the enclosing function and its arguments 93 * Ultimately, the information about the enclosing function and its arguments
94 * will be extracted automatically but for the time being it must be passed 94 * will be extracted automatically but for the time being it must be passed
95 * explicitly in the [name] and [args] arguments. 95 * explicitly in the [name] and [args] arguments.
96 */ 96 */
97 String lookupMessage(String message_str, [final String desc='', 97 String lookupMessage(String message_str, [final String desc='',
98 final Map examples=const {}, String locale, 98 final Map examples=const {}, String locale,
99 String name, List<String> args]) { 99 String name, List<String> args, String meaning]) {
100 if (name == null) return message_str; 100 if (name == null) return message_str;
101 var function = this[name]; 101 var function = this[name];
102 return function == null ? message_str : Function.apply(function, args); 102 return function == null ? message_str : Function.apply(function, args);
103 } 103 }
104 104
105 /** Return our message with the given name */ 105 /** Return our message with the given name */
106 operator [](String messageName) => messages[messageName]; 106 operator [](String messageName) => messages[messageName];
107 107
108 /** 108 /**
109 * Subclasses should override this to return a list of their message 109 * Subclasses should override this to return a list of their message
110 * functions. 110 * functions.
111 */ 111 */
112 Map<String, Function> get messages; 112 Map<String, Function> get messages;
113 113
114 /** Subclasses should override this to return their locale, e.g. 'en_US' */ 114 /** Subclasses should override this to return their locale, e.g. 'en_US' */
115 String get localeName; 115 String get localeName;
116 116
117 toString() => localeName; 117 toString() => localeName;
118 } 118 }
OLDNEW
« no previous file with comments | « pkg/intl/lib/intl.dart ('k') | pkg/intl/lib/src/intl_helpers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698