| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 * into a Dart string interpolation. Specific translation | 59 * into a Dart string interpolation. Specific translation |
| 60 * mechanisms are expected to subclass this. | 60 * mechanisms are expected to subclass this. |
| 61 */ | 61 */ |
| 62 abstract class TranslatedMessage { | 62 abstract class TranslatedMessage { |
| 63 /** | 63 /** |
| 64 * The identifier for this message. In the simplest case, this is the name | 64 * The identifier for this message. In the simplest case, this is the name |
| 65 * parameter from the Intl.message call, | 65 * parameter from the Intl.message call, |
| 66 * but it can be any identifier that this program and the output of the | 66 * but it can be any identifier that this program and the output of the |
| 67 * translation can agree on as identifying a message. | 67 * translation can agree on as identifying a message. |
| 68 */ | 68 */ |
| 69 String id; | 69 final String id; |
| 70 | 70 |
| 71 /** Our translated version of [originalMessage]. */ | 71 /** Our translated version of [originalMessage]. */ |
| 72 Message translated; | 72 final Message translated; |
| 73 | 73 |
| 74 /** The original message that we are a translation of. */ | 74 /** The original message that we are a translation of. */ |
| 75 MainMessage originalMessage; | 75 MainMessage originalMessage; |
| 76 | 76 |
| 77 TranslatedMessage(this.id, this.translated); | 77 TranslatedMessage(this.id, this.translated); |
| 78 | 78 |
| 79 Message get message => translated; | 79 Message get message => translated; |
| 80 | 80 |
| 81 toString() => id.toString(); | 81 toString() => id.toString(); |
| 82 } | 82 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 99 // Exclude messages with no translation and translations with no matching | 99 // Exclude messages with no translation and translations with no matching |
| 100 // original message (e.g. if we're using some messages from a larger catalog) | 100 // original message (e.g. if we're using some messages from a larger catalog) |
| 101 var usableTranslations = translations.where( | 101 var usableTranslations = translations.where( |
| 102 (each) => each.originalMessage != null && each.message != null).toList(); | 102 (each) => each.originalMessage != null && each.message != null).toList(); |
| 103 for (var each in usableTranslations) { | 103 for (var each in usableTranslations) { |
| 104 each.originalMessage.addTranslation(locale, each.message); | 104 each.originalMessage.addTranslation(locale, each.message); |
| 105 } | 105 } |
| 106 usableTranslations.sort((a, b) => | 106 usableTranslations.sort((a, b) => |
| 107 a.originalMessage.name.compareTo(b.originalMessage.name)); | 107 a.originalMessage.name.compareTo(b.originalMessage.name)); |
| 108 for (var translation in usableTranslations) { | 108 for (var translation in usableTranslations) { |
| 109 result.write(" "); | 109 result |
| 110 result.write(translation.originalMessage.toCodeForLocale(locale)); | 110 .write(" ") |
| 111 result.write("\n\n"); | 111 ..write(translation.originalMessage.toCodeForLocale(locale)) |
| 112 ..write("\n\n"); |
| 112 } | 113 } |
| 113 result.write("\n final messages = const {\n"); | 114 result.write("\n final messages = const {\n"); |
| 114 var entries = usableTranslations | 115 var entries = usableTranslations |
| 115 .map((translation) => translation.originalMessage.name) | 116 .map((translation) => translation.originalMessage.name) |
| 116 .map((name) => " \"$name\" : $name"); | 117 .map((name) => " \"$name\" : $name"); |
| 117 result.write(entries.join(",\n")); | 118 result |
| 118 result.write("\n };\n}"); | 119 ..write(entries.join(",\n")) |
| 120 ..write("\n };\n}"); |
| 119 | 121 |
| 120 var output = new File(path.join(targetDir, | 122 new File(path.join(targetDir,"${generatedFilePrefix}messages_$locale.dart")) |
| 121 "${generatedFilePrefix}messages_$locale.dart")); | 123 ..writeAsStringSync(result.toString()); |
| 122 output.writeAsStringSync(result.toString()); | |
| 123 } | 124 } |
| 124 | 125 |
| 125 /** | 126 /** |
| 126 * This returns the mostly constant string used in | 127 * This returns the mostly constant string used in |
| 127 * [generateIndividualMessageFile] for the beginning of the file, | 128 * [generateIndividualMessageFile] for the beginning of the file, |
| 128 * parameterized by [locale]. | 129 * parameterized by [locale]. |
| 129 */ | 130 */ |
| 130 String prologue(String locale) => """ | 131 String prologue(String locale) => """ |
| 131 /** | 132 /** |
| 132 * DO NOT EDIT. This is code generated via pkg/intl/generate_localized.dart | 133 * DO NOT EDIT. This is code generated via pkg/intl/generate_localized.dart |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // return lib == null ? new Future.value(false) : lib.load(); | 224 // return lib == null ? new Future.value(false) : lib.load(); |
| 224 return new Future.value(true); | 225 return new Future.value(true); |
| 225 } | 226 } |
| 226 | 227 |
| 227 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { | 228 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { |
| 228 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); | 229 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); |
| 229 if (actualLocale == null) return null; | 230 if (actualLocale == null) return null; |
| 230 return _findExact(actualLocale); | 231 return _findExact(actualLocale); |
| 231 } | 232 } |
| 232 """; | 233 """; |
| OLD | NEW |