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

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

Issue 11066099: Remove function types from intl, as they appear to break the vm (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 | « no previous file | no next file » | 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 * This library provides internationalization and localization. This includes 6 * This library provides internationalization and localization. This includes
7 * message formatting and replacement, date and number formatting and parsing, 7 * message formatting and replacement, date and number formatting and parsing,
8 * and utilities for working with Bidirectional text. 8 * and utilities for working with Bidirectional text.
9 * 9 *
10 * For things that require locale or other data, there are multiple different 10 * For things that require locale or other data, there are multiple different
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 /** 151 /**
152 * Given [newLocale] return a locale that we have data for that is similar 152 * Given [newLocale] return a locale that we have data for that is similar
153 * to it, if possible. 153 * to it, if possible.
154 * If [newLocale] is found directly, return it. If it can't be found, look up 154 * If [newLocale] is found directly, return it. If it can't be found, look up
155 * based on just the language (e.g. 'en_CA' -> 'en'). Also accepts '-' 155 * based on just the language (e.g. 'en_CA' -> 'en'). Also accepts '-'
156 * as a separator and changes it into '_' for lookup, and changes the 156 * as a separator and changes it into '_' for lookup, and changes the
157 * country to uppercase. 157 * country to uppercase.
158 * Note that null is interpreted as meaning the default locale, so if 158 * Note that null is interpreted as meaning the default locale, so if
159 * [newLocale] is null it will be returned. 159 * [newLocale] is null it will be returned.
160 */ 160 */
161 static String verifiedLocale(String newLocale, bool localeExists(String), 161 static String verifiedLocale(String newLocale, Function localeExists,
162 [Function onFailure = _throwLocaleError]) { 162 [Function onFailure = _throwLocaleError]) {
163 // TODO(alanknight): Previously we kept a single verified locale on the Intl 163 // TODO(alanknight): Previously we kept a single verified locale on the Intl
164 // object, but with different verification for different uses, that's more 164 // object, but with different verification for different uses, that's more
165 // difficult. As a result, we call this more often. Consider keeping 165 // difficult. As a result, we call this more often. Consider keeping
166 // verified locales for each purpose if it turns out to be a performance 166 // verified locales for each purpose if it turns out to be a performance
167 // issue. 167 // issue.
168 if (newLocale == null) return systemLocale; 168 if (newLocale == null) return systemLocale;
169 if (localeExists(newLocale)) { 169 if (localeExists(newLocale)) {
170 return newLocale; 170 return newLocale;
171 } 171 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 * [message_function] that takes no parameters. The [message_function] can be 225 * [message_function] that takes no parameters. The [message_function] can be
226 * a simple message function that just returns the result of `Intl.message()` 226 * a simple message function that just returns the result of `Intl.message()`
227 * it can be a wrapper around a message function that takes arguments, or it 227 * it can be a wrapper around a message function that takes arguments, or it
228 * can be something more complex that manipulates multiple message 228 * can be something more complex that manipulates multiple message
229 * functions. 229 * functions.
230 * 230 *
231 * In either case, the purpose of this is to delay calling [message_function] 231 * In either case, the purpose of this is to delay calling [message_function]
232 * until the proper locale has been set. This returns the result of calling 232 * until the proper locale has been set. This returns the result of calling
233 * [msg_function], which could be of an arbitrary type. 233 * [msg_function], which could be of an arbitrary type.
234 */ 234 */
235 static dynamic withLocale(String locale, message_function()) { 235 static dynamic withLocale(String locale, Function message_function) {
Emily Fortuna 2012/10/10 17:44:48 hmm bummer. So neither the VM nor dart2js recogniz
Alan Knight 2012/10/10 17:49:05 Looks like the problem was probably the explicit u
Emily Fortuna 2012/10/10 18:11:07 sgtm. I support the more specific syntax
Ivan Posva 2012/10/10 19:01:55 The problem here is that "dynamic" is not a known
236 // We have to do this silliness because Locale is not known at compile time, 236 // We have to do this silliness because Locale is not known at compile time,
237 // but must be a static variable in order to be visible to the Intl.message 237 // but must be a static variable in order to be visible to the Intl.message
238 // invocation. 238 // invocation.
239 if (_defaultLocale == null) _defaultLocale = systemLocale; 239 if (_defaultLocale == null) _defaultLocale = systemLocale;
240 var oldLocale = _defaultLocale; 240 var oldLocale = _defaultLocale;
241 _defaultLocale = locale; 241 _defaultLocale = locale;
242 var result = message_function(); 242 var result = message_function();
243 _defaultLocale = oldLocale; 243 _defaultLocale = oldLocale;
244 return result; 244 return result;
245 } 245 }
(...skipping 15 matching lines...) Expand all
261 /** 261 /**
262 * Accessor for the current locale. This should always == the default locale, 262 * Accessor for the current locale. This should always == the default locale,
263 * unless for some reason this gets called inside a message that resets the 263 * unless for some reason this gets called inside a message that resets the
264 * locale. 264 * locale.
265 */ 265 */
266 static String getCurrentLocale() { 266 static String getCurrentLocale() {
267 if (_defaultLocale == null) _defaultLocale = systemLocale; 267 if (_defaultLocale == null) _defaultLocale = systemLocale;
268 return _defaultLocale; 268 return _defaultLocale;
269 } 269 }
270 } 270 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698