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

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

Issue 182443003: Add 'meaning' to Intl.messages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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/message_lookup_by_library.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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 * be a valid const literal map. Similarly, the [desc] argument must 149 * be a valid const literal map. Similarly, the [desc] argument must
150 * be a single, simple string. These two arguments will not be used at runtime 150 * be a single, simple string. These two arguments will not be used at runtime
151 * but will be extracted from 151 * but will be extracted from
152 * the source code and used as additional data for translators. 152 * the source code and used as additional data for translators.
153 * 153 *
154 * The [name] and [args] arguments are required, and are used at runtime 154 * The [name] and [args] arguments are required, and are used at runtime
155 * to look up the localized version and pass the appropriate arguments to it. 155 * to look up the localized version and pass the appropriate arguments to it.
156 * We may in the future modify the code during compilation to make manually 156 * We may in the future modify the code during compilation to make manually
157 * passing those arguments unnecessary. 157 * passing those arguments unnecessary.
158 */ 158 */
159 static String message(String message_str, {final String desc: '', 159 static String message(String message_str, {String desc: '',
160 final Map examples: const {}, String locale, String name, 160 Map<String, String> examples: const {}, String locale, String name,
161 List<String> args}) { 161 List<String> args, String meaning}) {
162 return messageLookup.lookupMessage( 162 return messageLookup.lookupMessage(
163 message_str, desc, examples, locale, name, args); 163 message_str, desc, examples, locale, name, args, meaning);
164 } 164 }
165 165
166 /** 166 /**
167 * Return the locale for this instance. If none was set, the locale will 167 * Return the locale for this instance. If none was set, the locale will
168 * be the default. 168 * be the default.
169 */ 169 */
170 String get locale => _locale; 170 String get locale => _locale;
171 171
172 /** 172 /**
173 * Return true if the locale exists, or if it is null. The null case 173 * Return true if the locale exists, or if it is null. The null case
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 '${aLocale[4].toUpperCase()}$lastRegionLetter'; 244 '${aLocale[4].toUpperCase()}$lastRegionLetter';
245 } 245 }
246 246
247 /** 247 /**
248 * Format a message differently depending on [howMany]. Normally used 248 * Format a message differently depending on [howMany]. Normally used
249 * as part of an `Intl.message` text that is to be translated. 249 * as part of an `Intl.message` text that is to be translated.
250 * Selects the correct plural form from 250 * Selects the correct plural form from
251 * the provided alternatives. The [other] named argument is mandatory. 251 * the provided alternatives. The [other] named argument is mandatory.
252 */ 252 */
253 static String plural(int howMany, {zero, one, two, few, many, other, 253 static String plural(int howMany, {zero, one, two, few, many, other,
254 desc, examples, locale, name, args}) { 254 String desc, Map<String, String> examples, String locale, String name,
255 List<String> args, String meaning}) {
255 // If we are passed a name and arguments, then we are operating as a 256 // If we are passed a name and arguments, then we are operating as a
256 // top-level message, so look up our translation by calling Intl.message 257 // top-level message, so look up our translation by calling Intl.message
257 // with ourselves as an argument. 258 // with ourselves as an argument.
258 if (name != null) { 259 if (name != null) {
259 return message( 260 return message(
260 plural(howMany, 261 plural(howMany,
261 zero: zero, one: one, two: two, few: few, many: many, other: other), 262 zero: zero, one: one, two: two, few: few, many: many, other: other),
262 name: name, 263 name: name,
263 args: args, 264 args: args,
264 locale: locale); 265 locale: locale,
266 meaning: meaning);
265 } 267 }
266 if (other == null) { 268 if (other == null) {
267 throw new ArgumentError("The 'other' named argument must be provided"); 269 throw new ArgumentError("The 'other' named argument must be provided");
268 } 270 }
269 // TODO(alanknight): This algorithm needs to be locale-dependent. 271 // TODO(alanknight): This algorithm needs to be locale-dependent.
270 switch (howMany) { 272 switch (howMany) {
271 case 0 : return (zero == null) ? other : zero; 273 case 0 : return (zero == null) ? other : zero;
272 case 1 : return (one == null) ? other : one; 274 case 1 : return (one == null) ? other : one;
273 case 2: return (two == null) ? ((few == null) ? other : few) : two; 275 case 2: return (two == null) ? ((few == null) ? other : few) : two;
274 default: 276 default:
275 if ((howMany == 3 || howMany == 4) && few != null) return few; 277 if ((howMany == 3 || howMany == 4) && few != null) return few;
276 if (howMany > 10 && howMany < 100 && many != null) return many; 278 if (howMany > 10 && howMany < 100 && many != null) return many;
277 return other; 279 return other;
278 } 280 }
279 throw new ArgumentError("Invalid plural usage for $howMany"); 281 throw new ArgumentError("Invalid plural usage for $howMany");
280 } 282 }
281 283
282 /** 284 /**
283 * Format a message differently depending on [targetGender]. Normally used as 285 * Format a message differently depending on [targetGender]. Normally used as
284 * part of an Intl.message message that is to be translated. 286 * part of an Intl.message message that is to be translated.
285 */ 287 */
286 static String gender(String targetGender, 288 static String gender(String targetGender,
287 {String male, String female, String other, 289 {String male, String female, String other,
288 String desc, Map examples, String locale, String name, 290 String desc, Map<String, String> examples, String locale, String name,
289 List<String>args}) { 291 List<String>args, String meaning}) {
290 // If we are passed a name and arguments, then we are operating as a 292 // If we are passed a name and arguments, then we are operating as a
291 // top-level message, so look up our translation by calling Intl.message 293 // top-level message, so look up our translation by calling Intl.message
292 // with ourselves as an argument. 294 // with ourselves as an argument.
293 if (name != null) { 295 if (name != null) {
294 return message( 296 return message(
295 gender(targetGender, male: male, female: female, other: other), 297 gender(targetGender, male: male, female: female, other: other),
296 name: name, 298 name: name,
297 args: args, 299 args: args,
298 locale: locale); 300 locale: locale,
301 meaning: meaning);
299 } 302 }
300 303
301 if (other == null) { 304 if (other == null) {
302 throw new ArgumentError("The 'other' named argument must be specified"); 305 throw new ArgumentError("The 'other' named argument must be specified");
303 } 306 }
304 switch(targetGender) { 307 switch(targetGender) {
305 case "female" : return female == null ? other : female; 308 case "female" : return female == null ? other : female;
306 case "male" : return male == null ? other : male; 309 case "male" : return male == null ? other : male;
307 default: return other; 310 default: return other;
308 } 311 }
309 } 312 }
310 313
311 /** 314 /**
312 * Format a message differently depending on [choice]. We look up the value 315 * Format a message differently depending on [choice]. We look up the value
313 * of [choice] in [cases] and return the result, or an empty string if 316 * of [choice] in [cases] and return the result, or an empty string if
314 * it is not found. Normally used as part 317 * it is not found. Normally used as part
315 * of an Intl.message message that is to be translated. 318 * of an Intl.message message that is to be translated.
316 */ 319 */
317 static String select(String choice, Map<String, String> cases, 320 static String select(String choice, Map<String, String> cases,
318 {String desc, Map examples, String locale, String name, 321 {String desc, Map<String, String> examples, String locale, String name,
319 List<String>args}) { 322 List<String>args, String meaning}) {
320 // If we are passed a name and arguments, then we are operating as a 323 // If we are passed a name and arguments, then we are operating as a
321 // top-level message, so look up our translation by calling Intl.message 324 // top-level message, so look up our translation by calling Intl.message
322 // with ourselves as an argument. 325 // with ourselves as an argument.
323 if (name != null) { 326 if (name != null) {
324 return message( 327 return message(
325 select(choice, cases), 328 select(choice, cases),
326 name: name, 329 name: name,
327 args: args, 330 args: args,
328 locale: locale); 331 locale: locale);
329 } 332 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 * unless for some reason this gets called inside a message that resets the 366 * unless for some reason this gets called inside a message that resets the
364 * locale. 367 * locale.
365 */ 368 */
366 static String getCurrentLocale() { 369 static String getCurrentLocale() {
367 if (defaultLocale == null) defaultLocale = systemLocale; 370 if (defaultLocale == null) defaultLocale = systemLocale;
368 return defaultLocale; 371 return defaultLocale;
369 } 372 }
370 373
371 toString() => "Intl($locale)"; 374 toString() => "Intl($locale)";
372 } 375 }
OLDNEW
« no previous file with comments | « pkg/intl/lib/extract_messages.dart ('k') | pkg/intl/lib/message_lookup_by_library.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698