OLD | NEW |
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 Intl([String aLocale]) { | 131 Intl([String aLocale]) { |
132 _locale = aLocale != null ? aLocale : getCurrentLocale(); | 132 _locale = aLocale != null ? aLocale : getCurrentLocale(); |
133 } | 133 } |
134 | 134 |
135 /** | 135 /** |
136 * Use this for a message that will be translated for different locales. The | 136 * Use this for a message that will be translated for different locales. The |
137 * expected usage is that this is inside an enclosing function that only | 137 * expected usage is that this is inside an enclosing function that only |
138 * returns the value of this call and provides a scope for the variables that | 138 * returns the value of this call and provides a scope for the variables that |
139 * will be substituted in the message. | 139 * will be substituted in the message. |
140 * | 140 * |
141 * The parameters are a | 141 * The [message_str] is the string to be translated, which may be interpolated |
142 * [message_str] to be translated, which may be interpolated | 142 * based on one or more variables. The [name] of the message must |
143 * based on one or more variables, the [name] of the message, which should | 143 * match the enclosing function name. For methods, it can also be |
144 * match the enclosing function name, the [args] of the enclosing | 144 * className_methodName. So for a method hello in class Simple, the name |
145 * function, a [desc] providing a description of usage | 145 * can be either "hello" or "Simple_hello". The name must also be globally |
146 * and a map of [examples] for each interpolated variable. For example | 146 * unique in the program, so the second form can make it easier to distinguish |
| 147 * messages with the same name but in different classes. |
| 148 * The [args] repeats the arguments of the enclosing |
| 149 * function, [desc] provides a description of usage, |
| 150 * [examples] is a Map of exmaples for each interpolated variable. For example |
147 * hello(yourName) => Intl.message( | 151 * hello(yourName) => Intl.message( |
148 * "Hello, $yourName", | 152 * "Hello, $yourName", |
149 * name: "hello", | 153 * name: "hello", |
150 * args: [yourName], | 154 * args: [yourName], |
151 * desc: "Say hello", | 155 * desc: "Say hello", |
152 * examples = {"yourName": "Sparky"}. | 156 * examples = {"yourName": "Sparky"}. |
153 * The source code will be processed via the analyzer to extract out the | 157 * The source code will be processed via the analyzer to extract out the |
154 * message data, so only a subset of valid Dart code is accepted. In | 158 * message data, so only a subset of valid Dart code is accepted. In |
155 * particular, everything must be literal and cannot refer to variables | 159 * particular, everything must be literal and cannot refer to variables |
156 * outside the scope of the enclosing function. The [examples] map must | 160 * outside the scope of the enclosing function. The [examples] map must |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 * unless for some reason this gets called inside a message that resets the | 396 * unless for some reason this gets called inside a message that resets the |
393 * locale. | 397 * locale. |
394 */ | 398 */ |
395 static String getCurrentLocale() { | 399 static String getCurrentLocale() { |
396 if (defaultLocale == null) defaultLocale = systemLocale; | 400 if (defaultLocale == null) defaultLocale = systemLocale; |
397 return defaultLocale; | 401 return defaultLocale; |
398 } | 402 } |
399 | 403 |
400 toString() => "Intl($locale)"; | 404 toString() => "Intl($locale)"; |
401 } | 405 } |
OLD | NEW |