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

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

Issue 20072002: Allow Intl.plural/gender as the top-level, omitting the Intl.message wrapper and the first layer of… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changes from review Created 7 years, 5 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/extract_messages.dart ('k') | pkg/intl/lib/src/intl_message.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 * 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 * ## Installing ## 10 * ## Installing ##
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return '${aLocale[0]}${aLocale[1]}_${aLocale[3].toUpperCase()}' 236 return '${aLocale[0]}${aLocale[1]}_${aLocale[3].toUpperCase()}'
237 '${aLocale[4].toUpperCase()}$lastRegionLetter'; 237 '${aLocale[4].toUpperCase()}$lastRegionLetter';
238 } 238 }
239 239
240 /** 240 /**
241 * Format a message differently depending on [howMany]. Normally used 241 * Format a message differently depending on [howMany]. Normally used
242 * as part of an `Intl.message` text that is to be translated. 242 * as part of an `Intl.message` text that is to be translated.
243 * Selects the correct plural form from 243 * Selects the correct plural form from
244 * the provided alternatives. The [other] named argument is mandatory. 244 * the provided alternatives. The [other] named argument is mandatory.
245 */ 245 */
246 static String plural(int howMany, {zero, one, two, few, many, other}) { 246 static String plural(int howMany, {zero, one, two, few, many, other,
247 desc, examples, locale, name, args}) {
248 // If we are passed a name and arguments, then we are operating as a
249 // top-level message, so look up our translation by calling Intl.message
250 // with ourselves as an argument.
251 if (name != null) {
252 return Intl.message(
253 Intl.plural(howMany,
254 zero: zero, one: one, two: two, few: few, many: many, other: other),
255 name: name,
256 args: args,
257 locale: locale);
258 }
247 if (other == null) { 259 if (other == null) {
248 throw new ArgumentError("The 'other' named argument must be provided"); 260 throw new ArgumentError("The 'other' named argument must be provided");
249 } 261 }
250 // TODO(alanknight): This algorithm needs to be locale-dependent. 262 // TODO(alanknight): This algorithm needs to be locale-dependent.
251 switch (howMany) { 263 switch (howMany) {
252 case 0 : return (zero == null) ? other : zero; 264 case 0 : return (zero == null) ? other : zero;
253 case 1 : return (one == null) ? other : one; 265 case 1 : return (one == null) ? other : one;
254 case 2: return (two == null) ? ((few == null) ? other : few) : two; 266 case 2: return (two == null) ? ((few == null) ? other : few) : two;
255 default: 267 default:
256 if (howMany == 3 || howMany == 4 && few != null) return few; 268 if (howMany == 3 || howMany == 4 && few != null) return few;
257 if (howMany > 10 && howMany < 100 && many != null) return many; 269 if (howMany > 10 && howMany < 100 && many != null) return many;
258 return other; 270 return other;
259 } 271 }
260 throw new ArgumentError("Invalid plural usage for $howMany"); 272 throw new ArgumentError("Invalid plural usage for $howMany");
261 } 273 }
262 274
263 /** 275 /**
264 * Format a message differently depending on [gender]. Normally used as part 276 * Format a message differently depending on [gender]. Normally used as part
265 * of an Intl.message message that is to be translated. 277 * of an Intl.message message that is to be translated.
266 */ 278 */
267 static String gender(String gender, 279 static String gender(String gender,
268 {String male, String female, String other}) { 280 {String male, String female, String other,
281 String desc, Map examples, String locale, String name,
282 List<String>args}) {
283 // If we are passed a name and arguments, then we are operating as a
284 // top-level message, so look up our translation by calling Intl.message
285 // with ourselves as an argument.
286 if (name != null) {
287 return Intl.message(
288 Intl.gender(gender, male: male, female: female, other: other),
289 name: name,
290 args: args,
291 locale: locale);
292 }
293
269 if (other == null) { 294 if (other == null) {
270 throw new ArgumentError("The 'other' named argument must be specified"); 295 throw new ArgumentError("The 'other' named argument must be specified");
271 } 296 }
272 switch(gender) { 297 switch(gender) {
273 case "female" : return female == null ? other : female; 298 case "female" : return female == null ? other : female;
274 case "male" : return male == null ? other : male; 299 case "male" : return male == null ? other : male;
275 default: return other; 300 default: return other;
276 } 301 }
277 } 302 }
278 303
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 * unless for some reason this gets called inside a message that resets the 340 * unless for some reason this gets called inside a message that resets the
316 * locale. 341 * locale.
317 */ 342 */
318 static String getCurrentLocale() { 343 static String getCurrentLocale() {
319 if (_defaultLocale == null) _defaultLocale = systemLocale; 344 if (_defaultLocale == null) _defaultLocale = systemLocale;
320 return _defaultLocale; 345 return _defaultLocale;
321 } 346 }
322 347
323 toString() => "Intl($locale)"; 348 toString() => "Intl($locale)";
324 } 349 }
OLDNEW
« no previous file with comments | « pkg/intl/lib/extract_messages.dart ('k') | pkg/intl/lib/src/intl_message.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698