Chromium Code Reviews| 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) => 'lib_' + x.replaceAll('-', '_'); |
|
Emily Fortuna
2013/09/11 19:47:43
just as an alternative, consider prefixing it as "
| |
| 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 124 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 |