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

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

Issue 11194025: Second round of cleanups for new optional parameter semantics. (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
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 * The values of [desc] and [examples] are not used at run-time but are only 120 * The values of [desc] and [examples] are not used at run-time but are only
121 * made available to the translators, so they MUST be simple Strings available 121 * made available to the translators, so they MUST be simple Strings available
122 * at compile time: no String interpolation or concatenation. 122 * at compile time: no String interpolation or concatenation.
123 * The expected usage of this is inside a function that takes as parameters 123 * The expected usage of this is inside a function that takes as parameters
124 * the variables used in the interpolated string, and additionally also a 124 * the variables used in the interpolated string, and additionally also a
125 * locale (optional). 125 * locale (optional).
126 * Ultimately, the information about the enclosing function and its arguments 126 * Ultimately, the information about the enclosing function and its arguments
127 * will be extracted automatically but for the time being it must be passed 127 * will be extracted automatically but for the time being it must be passed
128 * explicitly in the [name] and [args] arguments. 128 * explicitly in the [name] and [args] arguments.
129 */ 129 */
130 static String message(String message_str, [final String desc='', 130 static String message(String message_str, {final String desc: '',
131 final Map examples=const {}, String locale, String name, 131 final Map examples: const {}, String locale, String name,
132 List<String> args]) { 132 List<String> args}) {
133 return messageLookup.lookupMessage( 133 return messageLookup.lookupMessage(
134 message_str, desc, examples, locale, name, args); 134 message_str, desc, examples, locale, name, args);
135 } 135 }
136 136
137 /** 137 /**
138 * Return the locale for this instance. If none was set, the locale will 138 * Return the locale for this instance. If none was set, the locale will
139 * be the default. 139 * be the default.
140 */ 140 */
141 String get locale => _locale; 141 String get locale => _locale;
142 142
143 /** 143 /**
144 * Return true if the locale exists, or if it is null. The null case 144 * Return true if the locale exists, or if it is null. The null case
145 * is interpreted to mean that we use the default locale. 145 * is interpreted to mean that we use the default locale.
146 */ 146 */
147 static bool _localeExists(localeName) { 147 static bool _localeExists(localeName) {
148 return DateFormat.localeExists(localeName); 148 return DateFormat.localeExists(localeName);
149 } 149 }
150 150
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, Function localeExists, 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 }
172 for (var each in 172 for (var each in
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
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

Powered by Google App Engine
This is Rietveld 408576698