| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 utilities for generating localized versions of | 6 * This provides utilities for generating localized versions of |
| 7 * messages. It does not stand alone, but expects to be given | 7 * messages. It does not stand alone, but expects to be given |
| 8 * TranslatedMessage objects and generate code for a particular locale | 8 * TranslatedMessage objects and generate code for a particular locale |
| 9 * based on them. | 9 * based on them. |
| 10 * | 10 * |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 Message get message => translated; | 79 Message get message => translated; |
| 80 | 80 |
| 81 toString() => id.toString(); | 81 toString() => id.toString(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * We can't use a hyphen in a Dart library name, so convert the locale | 85 * We can't use a hyphen in a Dart library name, so convert the locale |
| 86 * separator to an underscore. | 86 * separator to an underscore. |
| 87 */ | 87 */ |
| 88 String _libraryName(String x) => x.replaceAll('-', '_'); | 88 String _libraryName(String x) => 'messages_' + x.replaceAll('-', '_'); |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Generate a file <[generated_file_prefix]>_messages_<[locale]>.dart | 91 * Generate a file <[generated_file_prefix]>_messages_<[locale]>.dart |
| 92 * for the [translations] in [locale] and put it in [targetDir]. | 92 * for the [translations] in [locale] and put it in [targetDir]. |
| 93 */ | 93 */ |
| 94 void generateIndividualMessageFile(String locale, | 94 void generateIndividualMessageFile(String locale, |
| 95 Iterable<TranslatedMessage> translations, String targetDir) { | 95 Iterable<TranslatedMessage> translations, String targetDir) { |
| 96 var result = new StringBuffer(); | 96 var result = new StringBuffer(); |
| 97 locale = new MainMessage().escapeAndValidateString(locale); | 97 locale = new MainMessage().escapeAndValidateString(locale); |
| 98 result.write(prologue(locale)); | 98 result.write(prologue(locale)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 128 * parameterized by [locale]. | 128 * parameterized by [locale]. |
| 129 */ | 129 */ |
| 130 String prologue(String locale) => """ | 130 String prologue(String locale) => """ |
| 131 /** | 131 /** |
| 132 * DO NOT EDIT. This is code generated via pkg/intl/generate_localized.dart | 132 * DO NOT EDIT. This is code generated via pkg/intl/generate_localized.dart |
| 133 * This is a library that provides messages for a $locale locale. All the | 133 * This is a library that provides messages for a $locale locale. All the |
| 134 * messages from the main program should be duplicated here with the same | 134 * messages from the main program should be duplicated here with the same |
| 135 * function name. | 135 * function name. |
| 136 */ | 136 */ |
| 137 | 137 |
| 138 library messages_${locale.replaceAll('-','_')}; | 138 library ${_libraryName(locale)}; |
| 139 import 'package:$intlImportPath/intl.dart'; | 139 import 'package:$intlImportPath/intl.dart'; |
| 140 import 'package:$intlImportPath/message_lookup_by_library.dart'; | 140 import 'package:$intlImportPath/message_lookup_by_library.dart'; |
| 141 | 141 |
| 142 final messages = new MessageLookup(); | 142 final messages = new MessageLookup(); |
| 143 | 143 |
| 144 class MessageLookup extends MessageLookupByLibrary { | 144 class MessageLookup extends MessageLookupByLibrary { |
| 145 | 145 |
| 146 get localeName => '$locale'; | 146 get localeName => '$locale'; |
| 147 """; | 147 """; |
| 148 | 148 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // return lib == null ? new Future.value(false) : lib.load(); | 223 // return lib == null ? new Future.value(false) : lib.load(); |
| 224 return new Future.value(true); | 224 return new Future.value(true); |
| 225 } | 225 } |
| 226 | 226 |
| 227 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { | 227 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { |
| 228 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); | 228 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); |
| 229 if (actualLocale == null) return null; | 229 if (actualLocale == null) return null; |
| 230 return _findExact(actualLocale); | 230 return _findExact(actualLocale); |
| 231 } | 231 } |
| 232 """; | 232 """; |
| OLD | NEW |