| 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 28 matching lines...) Expand all Loading... |
| 39 var thaiMessagesFuture = initializeMessages('th_TH'); | 39 var thaiMessagesFuture = initializeMessages('th_TH'); |
| 40 Future.wait([germanDatesFuture, thaiDatesFuture, germanMessagesFuture, | 40 Future.wait([germanDatesFuture, thaiDatesFuture, germanMessagesFuture, |
| 41 thaiMessagesFuture]).then(program); | 41 thaiMessagesFuture]).then(program); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Because the initialization messages return futures we split out the main | 44 // Because the initialization messages return futures we split out the main |
| 45 // part of our program into a separate function that runs once all the | 45 // part of our program into a separate function that runs once all the |
| 46 // futures have completed. We are passed the collection of futures, but we | 46 // futures have completed. We are passed the collection of futures, but we |
| 47 // don't need to use them, so ignore the parameter. | 47 // don't need to use them, so ignore the parameter. |
| 48 runProgram(List<Future> _) { | 48 runProgram(List<Future> _) { |
| 49 var aDate = new Date.fromMillisecondsSinceEpoch(0, isUtc: true); | 49 var aDate = new DateTime.fromMillisecondsSinceEpoch(0, isUtc: true); |
| 50 var de = new Intl('de_DE'); | 50 var de = new Intl('de_DE'); |
| 51 var th = new Intl('th_TH'); | 51 var th = new Intl('th_TH'); |
| 52 // This defines a message that can be internationalized. It is written as a | 52 // This defines a message that can be internationalized. It is written as a |
| 53 // function that returns the result of an Intl.message call. The primary | 53 // function that returns the result of an Intl.message call. The primary |
| 54 // parameter is a string that may use interpolation. | 54 // parameter is a string that may use interpolation. |
| 55 runAt(time, date) => | 55 runAt(time, date) => |
| 56 Intl.message('Ran at $time on $date', name: 'runAt', args: [time, date]); | 56 Intl.message('Ran at $time on $date', name: 'runAt', args: [time, date]); |
| 57 printForLocale(aDate, new Intl(), runAt); | 57 printForLocale(aDate, new Intl(), runAt); |
| 58 printForLocale(aDate, de, runAt); | 58 printForLocale(aDate, de, runAt); |
| 59 printForLocale(aDate, th, runAt); | 59 printForLocale(aDate, th, runAt); |
| 60 // Example making use of the return value from withLocale; | 60 // Example making use of the return value from withLocale; |
| 61 Intl.withLocale(th.locale, () => runAt('now', 'today')) | 61 Intl.withLocale(th.locale, () => runAt('now', 'today')) |
| 62 .then(doThisWithTheOutput); | 62 .then(doThisWithTheOutput); |
| 63 } | 63 } |
| 64 | 64 |
| 65 printForLocale(aDate, intl, operation) { | 65 printForLocale(aDate, intl, operation) { |
| 66 var hmsFormat = intl.date().add_Hms(); | 66 var hmsFormat = intl.date().add_Hms(); |
| 67 var dayFormat = intl.date().add_yMMMMEEEEd(); | 67 var dayFormat = intl.date().add_yMMMMEEEEd(); |
| 68 var time = hmsFormat.format(aDate); | 68 var time = hmsFormat.format(aDate); |
| 69 var day = dayFormat.format(aDate); | 69 var day = dayFormat.format(aDate); |
| 70 Intl.withLocale(intl.locale, () { | 70 Intl.withLocale(intl.locale, () { |
| 71 operation(time,day).then(doThisWithTheOutput); | 71 operation(time,day).then(doThisWithTheOutput); |
| 72 }); | 72 }); |
| 73 } | 73 } |
| OLD | NEW |