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

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

Issue 11265028: Tolerate null from finding browser locale, re-enable tests (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | pkg/pkg.status » ('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 * 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 throw new ArgumentError("Invalid locale '$localeName'"); 186 throw new ArgumentError("Invalid locale '$localeName'");
187 } 187 }
188 188
189 /** Return the short version of a locale name, e.g. 'en_US' => 'en' */ 189 /** Return the short version of a locale name, e.g. 'en_US' => 'en' */
190 static String _shortLocale(String aLocale) { 190 static String _shortLocale(String aLocale) {
191 if (aLocale.length < 2) return aLocale; 191 if (aLocale.length < 2) return aLocale;
192 return aLocale.substring(0, 2).toLowerCase(); 192 return aLocale.substring(0, 2).toLowerCase();
193 } 193 }
194 194
195 /** 195 /**
196 * Return a locale name turned into xx_YY where it might possibly be 196 * Return the name [aLocale] turned into xx_YY where it might possibly be
197 * in the wrong case or with a hyphen instead of an underscore. 197 * in the wrong case or with a hyphen instead of an underscore. If
198 * [aLocale] is null, for example, if you tried to get it from IE,
199 * return the current system locale.
198 */ 200 */
199 static String canonicalizedLocale(String aLocale) { 201 static String canonicalizedLocale(String aLocale) {
200 // Locales of length < 5 are presumably two-letter forms, or else malformed. 202 // Locales of length < 5 are presumably two-letter forms, or else malformed.
201 // Locales of length > 6 are likely to be malformed. In either case we 203 // Locales of length > 6 are likely to be malformed. In either case we
202 // return them unmodified and if correct they will be found. 204 // return them unmodified and if correct they will be found.
203 // We treat C as a special case, and assume it wants en_ISO for formatting. 205 // We treat C as a special case, and assume it wants en_ISO for formatting.
204 // TODO(alanknight): en_ISO is probably not quite right for the C/Posix 206 // TODO(alanknight): en_ISO is probably not quite right for the C/Posix
205 // locale for formatting. Consider adding C to the formats database. 207 // locale for formatting. Consider adding C to the formats database.
208 if (aLocale == null) return systemLocale;
206 if (aLocale == "C") return "en_ISO"; 209 if (aLocale == "C") return "en_ISO";
207 if ((aLocale.length < 5) || (aLocale.length > 6)) return aLocale; 210 if ((aLocale.length < 5) || (aLocale.length > 6)) return aLocale;
208 if (aLocale[2] != '-' && (aLocale[2] != '_')) return aLocale; 211 if (aLocale[2] != '-' && (aLocale[2] != '_')) return aLocale;
209 var lastRegionLetter = aLocale.length == 5 ? "" : aLocale[5].toUpperCase(); 212 var lastRegionLetter = aLocale.length == 5 ? "" : aLocale[5].toUpperCase();
210 return '${aLocale[0]}${aLocale[1]}_${aLocale[3].toUpperCase()}' 213 return '${aLocale[0]}${aLocale[1]}_${aLocale[3].toUpperCase()}'
211 '${aLocale[4].toUpperCase()}$lastRegionLetter'; 214 '${aLocale[4].toUpperCase()}$lastRegionLetter';
212 } 215 }
213 216
214 /** 217 /**
215 * Support method for message formatting. Select the correct plural form from 218 * Support method for message formatting. Select the correct plural form from
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 /** 264 /**
262 * Accessor for the current locale. This should always == the default locale, 265 * 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 266 * unless for some reason this gets called inside a message that resets the
264 * locale. 267 * locale.
265 */ 268 */
266 static String getCurrentLocale() { 269 static String getCurrentLocale() {
267 if (_defaultLocale == null) _defaultLocale = systemLocale; 270 if (_defaultLocale == null) _defaultLocale = systemLocale;
268 return _defaultLocale; 271 return _defaultLocale;
269 } 272 }
270 } 273 }
OLDNEW
« no previous file with comments | « no previous file | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698