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

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

Issue 10535087: Changes to the i18n messages so that they are invoked as (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | lib/i18n/intl_message.dart » ('j') | lib/i18n/intl_message.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 * for details. All rights reserved. Use of this source code is governed by a 3 * for details. All rights reserved. Use of this source code is governed by a
4 * BSD-style license that can be found in the LICENSE file. 4 * BSD-style license that can be found in the LICENSE file.
5 * 5 *
6 * Internationalization object providing access to message formatting objects, 6 * Internationalization object providing access to message formatting objects,
7 * date formatting, parsing, bidirectional text relative to a specific locale. 7 * date formatting, parsing, bidirectional text relative to a specific locale.
8 */ 8 */
9 9
10 #library('Intl'); 10 #library('Intl');
11 11
12 #import('intl_message.dart'); 12 #import('intl_message.dart');
13 #import('date_format.dart');
13 14
14 class Intl { 15 class Intl {
15 16
16 /** 17 /**
17 * String indicating the locale code with which the message is to be 18 * String indicating the locale code with which the message is to be
18 * formatted (such as en-CA). 19 * formatted (such as en-CA).
19 */ 20 */
20 String _locale; 21 String _locale;
21 22
22 IntlMessage intlMsg; 23 IntlMessage intlMsg;
23 24
24 DateFormat date; 25 DateFormat date;
25 26
26 /** 27 /**
27 * Constructor optionally [_locale] for specifics of the language 28 * Constructor optionally [_locale] for specifics of the language
28 * locale to be used, otherwise, we will attempt to infer it (acceptable if 29 * locale to be used, otherwise, we will attempt to infer it (acceptable if
29 * Dart is running on the client, we can infer from the browser/client 30 * Dart is running on the client, we can infer from the browser/client
30 * preferences). 31 * preferences).
31 */ 32 */
32 Intl([this._locale]) : intlMsg = new IntlMessage(_locale), 33 Intl([this._locale]) {
33 date = new DateFormat(_locale); 34 intlMsg = new IntlMessage(_locale);
35 date = new DateFormat(_locale);
36 }
34 37
35 /** 38 /**
36 * Create a message that can be internationalized. It contains a [message_str] 39 * Create a message that can be internationalized. It takes a
37 * that will be translated, a [desc] providing a description of the use case 40 * [message_str] which is string to be translated, which may be interpolated
Emily Fortuna 2012/06/08 21:50:37 "which is string to be" => "that will be" (we don'
Alan Knight 2012/06/08 22:04:53 Yes, too many rewrites in a row... Done.
41 * based on one or more variables, a [desc] providing a description of usage
38 * for the [message_str], and a map of [examples] for each data element to be 42 * for the [message_str], and a map of [examples] for each data element to be
39 * substituted into the message. For example, if message="Hello, $name", then 43 * substituted into the message. For example, if message="Hello, $name", then
40 * examples = {'name': 'Sparky'}. The values of [desc] and [examples] MUST be 44 * examples = {'name': 'Sparky'}. The values of [desc] and [examples] are
41 * simple Strings available at compile time: no String interpolation or 45 * not used at run-time but are only made available to the translators, so
42 * concatenation. 46 * they MUST be simple Strings available at compile time: no String
47 * interpolation or concatenation.
48 * The expected usage of this is inside a function that takes as parameters
49 * the variables used in the interpolated string.
43 */ 50 */
44 String message(String message_str, [final String desc='', 51 String message(String message_str, [final String desc='',
45 final Map examples=const {}]) { 52 final Map examples=const {}]) {
46 // TODO(efortuna): implement. 53 return message_str;
47 return message_str;
48 } 54 }
49 55
50 /** 56 /**
51 * Support method for message formatting. Select the correct plural form from 57 * Support method for message formatting. Select the correct plural form from
52 * [cases] given [howMany]. 58 * [cases] given [howMany].
53 */ 59 */
54 static String plural(var howMany, Map cases, [num offset=0]) { 60 static String plural(var howMany, Map cases, [num offset=0]) {
55 // TODO(efortuna): Deal with "few" and "many" cases, offset, and others! 61 // TODO(efortuna): Deal with "few" and "many" cases, offset, and others!
56 select(howMany.toString(), cases); 62 // TODO(alanknight): Should we have instance methods instead/as well?
63 // Or have the others as statics?
64 return select(howMany.toString(), cases);
57 } 65 }
58 66
59 /** 67 /**
60 * Support method for message formatting. Select the correct exact (gender, 68 * Support method for message formatting. Select the correct exact (gender,
61 * usually) form from [cases] given the user [choice]. 69 * usually) form from [cases] given the user [choice].
62 */ 70 */
63 static String select(String choice, Map cases) { 71 static String select(String choice, Map cases) {
64 if (cases.getKeys().some((elem) => elem == choice)) { 72 if (cases.containsKey(choice)) {
65 return cases[choice]; 73 return cases[choice];
66 } else if (cases.containsKey('other')){ 74 } else if (cases.containsKey('other')){
67 return cases['other']; 75 return cases['other'];
68 } else { 76 } else {
69 return ''; 77 return '';
70 } 78 }
71 } 79 }
72 } 80 }
OLDNEW
« no previous file with comments | « no previous file | lib/i18n/intl_message.dart » ('j') | lib/i18n/intl_message.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698