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

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

Issue 132963002: Read Intl.message examples argument as a map, not a string (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks for the test framework Created 6 years, 11 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 | « no previous file | pkg/intl/lib/intl.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) 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 is for use in extracting messages from a Dart program 6 * This is for use in extracting messages from a Dart program
7 * using the Intl.message() mechanism and writing them to a file for 7 * using the Intl.message() mechanism and writing them to a file for
8 * translation. This provides only the stub of a mechanism, because it 8 * translation. This provides only the stub of a mechanism, because it
9 * doesn't define how the file should be written. It provides an 9 * doesn't define how the file should be written. It provides an
10 * [IntlMessage] class that holds the extracted data and [parseString] 10 * [IntlMessage] class that holds the extracted data and [parseString]
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 var message = new MainMessage(); 222 var message = new MainMessage();
223 message.name = name; 223 message.name = name;
224 message.arguments = parameters.parameters.map( 224 message.arguments = parameters.parameters.map(
225 (x) => x.identifier.name).toList(); 225 (x) => x.identifier.name).toList();
226 var arguments = node.argumentList.arguments; 226 var arguments = node.argumentList.arguments;
227 extract(message, arguments); 227 extract(message, arguments);
228 228
229 for (var namedArgument in arguments.where((x) => x is NamedExpression)) { 229 for (var namedArgument in arguments.where((x) => x is NamedExpression)) {
230 var name = namedArgument.name.label.name; 230 var name = namedArgument.name.label.name;
231 var exp = namedArgument.expression; 231 var exp = namedArgument.expression;
232 var string = exp is SimpleStringLiteral ? exp.value : exp.toString(); 232 var evaluator = new ConstantEvaluator();
233 setAttribute(message, name, string); 233 var basicValue = exp.accept(evaluator);
234 var value = basicValue == ConstantEvaluator.NOT_A_CONSTANT ?
235 exp.toString() : basicValue;
236 setAttribute(message, name, value);
234 } 237 }
235 return message; 238 return message;
236 } 239 }
237 240
238 /** 241 /**
239 * Create a MainMessage from [node] using the name and 242 * Create a MainMessage from [node] using the name and
240 * parameters of the last function/method declaration we encountered 243 * parameters of the last function/method declaration we encountered
241 * and the parameters to the Intl.message call. 244 * and the parameters to the Intl.message call.
242 */ 245 */
243 MainMessage messageFromIntlMessageCall(MethodInvocation node) { 246 MainMessage messageFromIntlMessageCall(MethodInvocation node) {
244 247
245 void extractFromIntlCall(MainMessage message, List arguments) { 248 void extractFromIntlCall(MainMessage message, List arguments) {
246 try { 249 try {
247 var interpolation = new InterpolationVisitor(message); 250 var interpolation = new InterpolationVisitor(message);
248 arguments.first.accept(interpolation); 251 arguments.first.accept(interpolation);
249 message.messagePieces.addAll(interpolation.pieces); 252 message.messagePieces.addAll(interpolation.pieces);
250 } on IntlMessageExtractionException catch (e) { 253 } on IntlMessageExtractionException catch (e) {
251 message = null; 254 message = null;
252 var err = new StringBuffer(); 255 var err = new StringBuffer();
253 err.write("Error $e\n"); 256 err.write("Error $e\n");
254 err.write("Processing <$node>\n"); 257 err.write("Processing <$node>\n");
255 err.write(_reportErrorLocation(node)); 258 err.write(_reportErrorLocation(node));
256 print(err); 259 print(err);
257 warnings.add(err); 260 warnings.add(err);
258 } 261 }
259 } 262 }
260 263
261 void setValue(MainMessage message, String fieldName, String fieldValue) { 264 void setValue(MainMessage message, String fieldName, Object fieldValue) {
262 message[fieldName] = fieldValue; 265 message[fieldName] = fieldValue;
263 } 266 }
264 267
265 return _messageFromNode(node, extractFromIntlCall, setValue); 268 return _messageFromNode(node, extractFromIntlCall, setValue);
266 } 269 }
267 270
268 /** 271 /**
269 * Create a MainMessage from [node] using the name and 272 * Create a MainMessage from [node] using the name and
270 * parameters of the last function/method declaration we encountered 273 * parameters of the last function/method declaration we encountered
271 * and the parameters to the Intl.plural or Intl.gender call. 274 * and the parameters to the Intl.plural or Intl.gender call.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 */ 473 */
471 final String message; 474 final String message;
472 475
473 /** 476 /**
474 * Creates a new exception with an optional error [message]. 477 * Creates a new exception with an optional error [message].
475 */ 478 */
476 const IntlMessageExtractionException([this.message = ""]); 479 const IntlMessageExtractionException([this.message = ""]);
477 480
478 String toString() => "IntlMessageExtractionException: $message"; 481 String toString() => "IntlMessageExtractionException: $message";
479 } 482 }
OLDNEW
« no previous file with comments | « no previous file | pkg/intl/lib/intl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698