| 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 16 matching lines...) Expand all Loading... |
| 27 * 'This is plural (', a VariableSubstitution for `num`. amd a LiteralString | 27 * 'This is plural (', a VariableSubstitution for `num`. amd a LiteralString |
| 28 * for '.)'. | 28 * for '.)'. |
| 29 * | 29 * |
| 30 * This representation isn't used at runtime. Rather, we read some format | 30 * This representation isn't used at runtime. Rather, we read some format |
| 31 * from a translation file, parse it into these objects, and they are then | 31 * from a translation file, parse it into these objects, and they are then |
| 32 * used to generate the code representation above. | 32 * used to generate the code representation above. |
| 33 */ | 33 */ |
| 34 library intl_message; | 34 library intl_message; |
| 35 | 35 |
| 36 import 'package:analyzer/analyzer.dart'; | 36 import 'package:analyzer/analyzer.dart'; |
| 37 import 'package:json/json.dart' as json; |
| 37 | 38 |
| 38 /** A default function for the [Message.expanded] method. */ | 39 /** A default function for the [Message.expanded] method. */ |
| 39 _nullTransform(msg, chunk) => chunk; | 40 _nullTransform(msg, chunk) => chunk; |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * An abstract superclass for Intl.message/plural/gender calls in the | 43 * An abstract superclass for Intl.message/plural/gender calls in the |
| 43 * program's source text. We | 44 * program's source text. We |
| 44 * assemble these into objects that can be used to write out some translation | 45 * assemble these into objects that can be used to write out some translation |
| 45 * format and can also print themselves into code. | 46 * format and can also print themselves into code. |
| 46 */ | 47 */ |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 void addPieces(List<Message> messages) { | 309 void addPieces(List<Message> messages) { |
| 309 for (var each in messages) { | 310 for (var each in messages) { |
| 310 messagePieces.add(Message.from(each, this)); | 311 messagePieces.add(Message.from(each, this)); |
| 311 } | 312 } |
| 312 } | 313 } |
| 313 | 314 |
| 314 /** The description provided in the Intl.message call. */ | 315 /** The description provided in the Intl.message call. */ |
| 315 String description; | 316 String description; |
| 316 | 317 |
| 317 /** The examples from the Intl.message call */ | 318 /** The examples from the Intl.message call */ |
| 318 String examples; | 319 Map<String, dynamic> get examples => _examples; |
| 320 void set examples(x) { |
| 321 var map = json.parse(x); |
| 322 for (var key in map.keys.toList()) { |
| 323 map[key.toUpperCase()] = map[key]; |
| 324 } |
| 325 } |
| 326 |
| 327 Map<String, dynamic> _examples = const {}; |
| 319 | 328 |
| 320 /** | 329 /** |
| 321 * The name, which may come from the function name, from the arguments | 330 * The name, which may come from the function name, from the arguments |
| 322 * to Intl.message, or we may just re-use the message. | 331 * to Intl.message, or we may just re-use the message. |
| 323 */ | 332 */ |
| 324 String _name; | 333 String _name; |
| 325 | 334 |
| 326 /** | 335 /** |
| 327 * A placeholder for any other identifier that the translation format | 336 * A placeholder for any other identifier that the translation format |
| 328 * may want to use. | 337 * may want to use. |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 out.write('('); | 670 out.write('('); |
| 662 out.write(mainArgument); | 671 out.write(mainArgument); |
| 663 var args = codeAttributeNames; | 672 var args = codeAttributeNames; |
| 664 out.write(", {"); | 673 out.write(", {"); |
| 665 args.fold(out, (buffer, arg) => buffer..write( | 674 args.fold(out, (buffer, arg) => buffer..write( |
| 666 "'$arg': '${this[arg].toCode()}', ")); | 675 "'$arg': '${this[arg].toCode()}', ")); |
| 667 out.write("})}"); | 676 out.write("})}"); |
| 668 return out.toString(); | 677 return out.toString(); |
| 669 } | 678 } |
| 670 } | 679 } |
| OLD | NEW |