| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 provides classes to represent the internal structure of the | 6 * This provides classes to represent the internal structure of the |
| 7 * arguments to `Intl.message`. It is used when parsing sources to extract | 7 * arguments to `Intl.message`. It is used when parsing sources to extract |
| 8 * messages or to generate code for message substitution. Normal programs | 8 * messages or to generate code for message substitution. Normal programs |
| 9 * using Intl would not import this library. | 9 * using Intl would not import this library. |
| 10 * | 10 * |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 /** The description provided in the Intl.message call. */ | 328 /** The description provided in the Intl.message call. */ |
| 329 String description; | 329 String description; |
| 330 | 330 |
| 331 /** The examples from the Intl.message call */ | 331 /** The examples from the Intl.message call */ |
| 332 Map<String, dynamic> examples; | 332 Map<String, dynamic> examples; |
| 333 | 333 |
| 334 /** | 334 /** |
| 335 * A field to disambiguate two messages that might have exactly the |
| 336 * same text. The two messages will also need different names, but |
| 337 * this can be used by machine translation tools to distinguish them. |
| 338 */ |
| 339 String meaning; |
| 340 |
| 341 /** |
| 335 * The name, which may come from the function name, from the arguments | 342 * The name, which may come from the function name, from the arguments |
| 336 * to Intl.message, or we may just re-use the message. | 343 * to Intl.message, or we may just re-use the message. |
| 337 */ | 344 */ |
| 338 String _name; | 345 String _name; |
| 339 | 346 |
| 340 /** | 347 /** |
| 341 * A placeholder for any other identifier that the translation format | 348 * A placeholder for any other identifier that the translation format |
| 342 * may want to use. | 349 * may want to use. |
| 343 */ | 350 */ |
| 344 String id; | 351 String id; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 * between those and the fields of the class. | 409 * between those and the fields of the class. |
| 403 */ | 410 */ |
| 404 void operator []=(attributeName, value) { | 411 void operator []=(attributeName, value) { |
| 405 switch (attributeName) { | 412 switch (attributeName) { |
| 406 case "desc" : description = value; return; | 413 case "desc" : description = value; return; |
| 407 case "examples" : examples = value; return; | 414 case "examples" : examples = value; return; |
| 408 case "name" : name = value; return; | 415 case "name" : name = value; return; |
| 409 // We use the actual args from the parser rather than what's given in the | 416 // We use the actual args from the parser rather than what's given in the |
| 410 // arguments to Intl.message. | 417 // arguments to Intl.message. |
| 411 case "args" : return; | 418 case "args" : return; |
| 419 case "meaning" : meaning = value; return; |
| 412 default: return; | 420 default: return; |
| 413 } | 421 } |
| 414 } | 422 } |
| 415 | 423 |
| 416 /** | 424 /** |
| 417 * The AST node will have the attribute names as strings, so we translate | 425 * The AST node will have the attribute names as strings, so we translate |
| 418 * between those and the fields of the class. | 426 * between those and the fields of the class. |
| 419 */ | 427 */ |
| 420 operator [](attributeName) { | 428 operator [](attributeName) { |
| 421 switch (attributeName) { | 429 switch (attributeName) { |
| 422 case "desc" : return description; | 430 case "desc" : return description; |
| 423 case "examples" : return examples; | 431 case "examples" : return examples; |
| 424 case "name" : return name; | 432 case "name" : return name; |
| 425 // We use the actual args from the parser rather than what's given in the | 433 // We use the actual args from the parser rather than what's given in the |
| 426 // arguments to Intl.message. | 434 // arguments to Intl.message. |
| 427 case "args" : return []; | 435 case "args" : return []; |
| 436 case "meaning" : return meaning; |
| 428 default: return null; | 437 default: return null; |
| 429 } | 438 } |
| 430 } | 439 } |
| 431 | 440 |
| 432 // This is the top-level construct, so there's no meaningful ICU name. | 441 // This is the top-level construct, so there's no meaningful ICU name. |
| 433 get icuMessageName => ''; | 442 get icuMessageName => ''; |
| 434 | 443 |
| 435 get dartMessageName => "message"; | 444 get dartMessageName => "message"; |
| 436 | 445 |
| 437 /** The parameters that the Intl.message call may provide. */ | 446 /** The parameters that the Intl.message call may provide. */ |
| 438 get attributeNames => const ["name", "desc", "examples", "args"]; | 447 get attributeNames => const ["name", "desc", "examples", "args", "meaning"]; |
| 439 | 448 |
| 440 String toString() => | 449 String toString() => |
| 441 "Intl.message(${expanded()}, $name, $description, $examples, $arguments)"; | 450 "Intl.message(${expanded()}, $name, $description, $examples, $arguments)"; |
| 442 } | 451 } |
| 443 | 452 |
| 444 /** | 453 /** |
| 445 * An abstract class to represent sub-sections of a message, primarily | 454 * An abstract class to represent sub-sections of a message, primarily |
| 446 * plurals and genders. | 455 * plurals and genders. |
| 447 */ | 456 */ |
| 448 abstract class SubMessage extends ComplexMessage { | 457 abstract class SubMessage extends ComplexMessage { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 out.write('('); | 684 out.write('('); |
| 676 out.write(mainArgument); | 685 out.write(mainArgument); |
| 677 var args = codeAttributeNames; | 686 var args = codeAttributeNames; |
| 678 out.write(", {"); | 687 out.write(", {"); |
| 679 args.fold(out, (buffer, arg) => buffer..write( | 688 args.fold(out, (buffer, arg) => buffer..write( |
| 680 "'$arg': '${this[arg].toCode()}', ")); | 689 "'$arg': '${this[arg].toCode()}', ")); |
| 681 out.write("})}"); | 690 out.write("})}"); |
| 682 return out.toString(); | 691 return out.toString(); |
| 683 } | 692 } |
| 684 } | 693 } |
| OLD | NEW |