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

Side by Side Diff: pkg/intl/lib/intl.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: 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/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 * This is part of the [intl package] 10 * This is part of the [intl package]
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 */ 122 */
123 Intl([String aLocale]) { 123 Intl([String aLocale]) {
124 if (aLocale != null) { 124 if (aLocale != null) {
125 _locale = aLocale; 125 _locale = aLocale;
126 } else { 126 } else {
127 _locale = getCurrentLocale(); 127 _locale = getCurrentLocale();
128 } 128 }
129 } 129 }
130 130
131 /** 131 /**
132 * Returns a message that can be internationalized. It takes a 132 * Returns a message that can be internationalized. It is expected
Emily Fortuna 2014/01/10 01:40:56 while you're changing this comment, let's make it
133 * [message_str] that will be translated, which may be interpolated 133 * to be used inside an enclosing function that just returns its value
134 * and provides a scope for the variables to be substituted in the
135 * message. The parameters are a
136 * [message_str] to be translated, which may be interpolated
134 * based on one or more variables, a [desc] providing a description of usage 137 * based on one or more variables, a [desc] providing a description of usage
135 * for the [message_str], and a map of [examples] for each data element to be 138 * and a map of [examples] for each interpolated variable. For example
136 * substituted into the message. For example, if message="Hello, $name", then 139 * hello(yourName) => Intl.message("Hello, $yourName",
137 * examples = {'name': 'Sparky'}. If not using the user's default locale, or 140 * name: "hello",
138 * if the locale is not easily detectable, explicitly pass [locale]. 141 * args: [name],
139 * The values of [desc] and [examples] are not used at run-time but are only 142 * desc: "Say hello",
140 * made available to the translators, so they MUST be simple Strings available 143 * examples = {"yourName": "Sparky"}.
141 * at compile time: no String interpolation or concatenation. 144 * The source code will be processed via the analyzer to extract out the
145 * message data, so only a subset of valid Dart code is accepted. In
146 * particular, everything must be literal and cannot refer to variables
147 * outside the scope of the enclosing function. The [examples] map must
148 * be valid JSON, which in addition to requiring only simple literals means
149 * that strings must use double-quotes exclusively and cannot use features
150 * like raw strings or concatenation. Similarly, the [desc] argument must
151 * be a single, simple string.
152 *
142 * The expected usage of this is inside a function that takes as parameters 153 * The expected usage of this is inside a function that takes as parameters
143 * the variables used in the interpolated string, and additionally also a 154 * the variables used in the interpolated string, and an optional
144 * locale (optional). 155 * locale.
145 * Ultimately, the information about the enclosing function and its arguments 156 *
146 * will be extracted automatically but for the time being it must be passed 157 * The [name] and [args] arguments are required, and are used at runtime
147 * explicitly in the [name] and [args] arguments. 158 * to look up the localized version and pass the appropriate arguments to it.
159 * We may in the future modify the code during compilation to make manually
160 * passing those arguments unnecessary.
148 */ 161 */
149 static String message(String message_str, {final String desc: '', 162 static String message(String message_str, {final String desc: '',
150 final Map examples: const {}, String locale, String name, 163 final Map examples: const {}, String locale, String name,
151 List<String> args}) { 164 List<String> args}) {
152 return messageLookup.lookupMessage( 165 return messageLookup.lookupMessage(
153 message_str, desc, examples, locale, name, args); 166 message_str, desc, examples, locale, name, args);
154 } 167 }
155 168
156 /** 169 /**
157 * Return the locale for this instance. If none was set, the locale will 170 * Return the locale for this instance. If none was set, the locale will
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 * unless for some reason this gets called inside a message that resets the 365 * unless for some reason this gets called inside a message that resets the
353 * locale. 366 * locale.
354 */ 367 */
355 static String getCurrentLocale() { 368 static String getCurrentLocale() {
356 if (defaultLocale == null) defaultLocale = systemLocale; 369 if (defaultLocale == null) defaultLocale = systemLocale;
357 return defaultLocale; 370 return defaultLocale;
358 } 371 }
359 372
360 toString() => "Intl($locale)"; 373 toString() => "Intl($locale)";
361 } 374 }
OLDNEW
« no previous file with comments | « no previous file | pkg/intl/lib/src/intl_message.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698