| 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 provides a basic example of internationalization usage. It uses the | 6 * This provides a basic example of internationalization usage. It uses the |
| 7 * local variant of all the facilities, meaning that libraries with the | 7 * local variant of all the facilities, meaning that libraries with the |
| 8 * data for all the locales are directly imported by the program. More realistic | 8 * data for all the locales are directly imported by the program. More realistic |
| 9 * examples might read the data from files or over the web, which uses the | 9 * examples might read the data from files or over the web, which uses the |
| 10 * same APIs but requires different imports. | 10 * same APIs but requires different imports. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 var de = new Intl('de_DE'); | 49 var de = new Intl('de_DE'); |
| 50 var th = new Intl('th_TH'); | 50 var th = new Intl('th_TH'); |
| 51 // This defines a message that can be internationalized. It is written as a | 51 // This defines a message that can be internationalized. It is written as a |
| 52 // function that returns the result of an Intl.message call. The primary | 52 // function that returns the result of an Intl.message call. The primary |
| 53 // parameter is a string that may use interpolation. | 53 // parameter is a string that may use interpolation. |
| 54 runAt(time, date) => | 54 runAt(time, date) => |
| 55 Intl.message('Ran at $time on $date', name: 'runAt', args: [time, date]); | 55 Intl.message('Ran at $time on $date', name: 'runAt', args: [time, date]); |
| 56 printForLocale(aDate, new Intl(), runAt); | 56 printForLocale(aDate, new Intl(), runAt); |
| 57 printForLocale(aDate, de, runAt); | 57 printForLocale(aDate, de, runAt); |
| 58 printForLocale(aDate, th, runAt); | 58 printForLocale(aDate, th, runAt); |
| 59 // Example making use of the return value from withLocale; |
| 60 var useReturnValue = Intl.withLocale(th.locale, () => runAt('now', 'today')); |
| 61 doThisWithTheOutput(useReturnValue); |
| 59 } | 62 } |
| 60 | 63 |
| 61 printForLocale(aDate, intl, operation) { | 64 printForLocale(aDate, intl, operation) { |
| 62 var hmsFormat = intl.date().add_Hms(); | 65 var hmsFormat = intl.date().add_Hms(); |
| 63 var dayFormat = intl.date().add_yMMMMEEEEd(); | 66 var dayFormat = intl.date().add_yMMMMEEEEd(); |
| 64 var time = hmsFormat.format(aDate); | 67 var time = hmsFormat.format(aDate); |
| 65 var day = dayFormat.format(aDate); | 68 var day = dayFormat.format(aDate); |
| 66 Intl.withLocale(intl.locale, () { doThisWithTheOutput(operation(time,day));}); | 69 Intl.withLocale(intl.locale, () { doThisWithTheOutput(operation(time,day));}); |
| 67 } | 70 } |
| OLD | NEW |