| OLD | NEW |
| 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 * Internationalization object providing access to message formatting objects, | 6 * Internationalization object providing access to message formatting objects, |
| 7 * date formatting, parsing, bidirectional text relative to a specific locale. | 7 * date formatting, parsing, bidirectional text relative to a specific locale. |
| 8 */ | 8 */ |
| 9 #library('intl'); | 9 #library('intl'); |
| 10 | 10 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * Return a locale name turned into xx_YY where it might possibly be | 137 * Return a locale name turned into xx_YY where it might possibly be |
| 138 * in the wrong case or with a hyphen instead of an underscore. | 138 * in the wrong case or with a hyphen instead of an underscore. |
| 139 */ | 139 */ |
| 140 static String canonicalizedLocale(String aLocale) { | 140 static String canonicalizedLocale(String aLocale) { |
| 141 // Locales of length < 5 are presumably two-letter forms, or else malformed. | 141 // Locales of length < 5 are presumably two-letter forms, or else malformed. |
| 142 // Locales of length > 6 are likely to be malformed. In either case we | 142 // Locales of length > 6 are likely to be malformed. In either case we |
| 143 // return them unmodified and if correct they will be found. | 143 // return them unmodified and if correct they will be found. |
| 144 // We treat C as a special case, and assume it wants en_ISO for formatting. |
| 145 // TODO(alanknight): en_ISO is probably not quite right for the C/Posix |
| 146 // locale for formatting. Consider adding C to the formats database. |
| 147 if (aLocale == "C") return "en_ISO"; |
| 144 if ((aLocale.length < 5) || (aLocale.length > 6)) return aLocale; | 148 if ((aLocale.length < 5) || (aLocale.length > 6)) return aLocale; |
| 145 if (aLocale[2] != '-' && (aLocale[2] != '_')) return aLocale; | 149 if (aLocale[2] != '-' && (aLocale[2] != '_')) return aLocale; |
| 150 var lastRegionLetter = aLocale.length == 5 ? "" : aLocale[5].toUpperCase(); |
| 146 return '${aLocale[0]}${aLocale[1]}_${aLocale[3].toUpperCase()}' | 151 return '${aLocale[0]}${aLocale[1]}_${aLocale[3].toUpperCase()}' |
| 147 '${aLocale[4].toUpperCase()}'; | 152 '${aLocale[4].toUpperCase()}$lastRegionLetter'; |
| 148 } | 153 } |
| 149 | 154 |
| 150 /** | 155 /** |
| 151 * Support method for message formatting. Select the correct plural form from | 156 * Support method for message formatting. Select the correct plural form from |
| 152 * [cases] given [howMany]. | 157 * [cases] given [howMany]. |
| 153 */ | 158 */ |
| 154 static String plural(var howMany, Map cases, [num offset=0]) { | 159 static String plural(var howMany, Map cases, [num offset=0]) { |
| 155 // TODO(efortuna): Deal with "few" and "many" cases, offset, and others! | 160 // TODO(efortuna): Deal with "few" and "many" cases, offset, and others! |
| 156 return select(howMany.toString(), cases); | 161 return select(howMany.toString(), cases); |
| 157 } | 162 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 /** | 214 /** |
| 210 * Initialize the message lookup mechanism. This is for internal use only. | 215 * Initialize the message lookup mechanism. This is for internal use only. |
| 211 * User applications should import message_lookup_local.dart and call | 216 * User applications should import message_lookup_local.dart and call |
| 212 * initializeMessages | 217 * initializeMessages |
| 213 */ | 218 */ |
| 214 void initializeInternalMessageLookup(Function lookupFunction) { | 219 void initializeInternalMessageLookup(Function lookupFunction) { |
| 215 if (_messageLookup is UninitializedLocaleData) { | 220 if (_messageLookup is UninitializedLocaleData) { |
| 216 _messageLookup = lookupFunction(); | 221 _messageLookup = lookupFunction(); |
| 217 } | 222 } |
| 218 } | 223 } |
| OLD | NEW |