Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: pkg/intl/lib/generate_localized.dart

Issue 140843002: [Intl] Cleanup some code (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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..write(" ")
Alan Knight 2014/01/28 01:33:46 I think the cascades should all line up and this o
vicb 2014/01/28 07:52:45 fixed
110 result.write(translation.originalMessage.toCodeForLocale(locale)); 110 ..write(translation.originalMessage.toCodeForLocale(locale))
111 result.write("\n\n"); 111 ..write("\n\n");
112 } 112 }
113 result.write("\n final messages = const {\n"); 113 result.write("\n final messages = const {\n");
114 var entries = usableTranslations 114 var entries = usableTranslations
115 .map((translation) => translation.originalMessage.name) 115 .map((translation) => translation.originalMessage.name)
116 .map((name) => " \"$name\" : $name"); 116 .map((name) => " \"$name\" : $name");
117 result.write(entries.join(",\n")); 117 result.writeAll([entries.join(",\n"), "\n };\n}"]);
Alan Knight 2014/01/28 01:33:46 This to me seems less clear than having it as two
vicb 2014/01/28 07:52:45 I've changed because I (personal preferences) find
Alan Knight 2014/01/29 01:27:58 Method calls should not be expensive at all in Dar
vicb 2014/01/29 08:15:14 reverted
118 result.write("\n };\n}");
119 118
120 var output = new File(path.join(targetDir, 119 var output = new File(path.join(targetDir,
121 "${generatedFilePrefix}messages_$locale.dart")); 120 "${generatedFilePrefix}messages_$locale.dart"));
122 output.writeAsStringSync(result.toString()); 121 output.writeAsStringSync(result.toString());
123 } 122 }
124 123
125 /** 124 /**
126 * This returns the mostly constant string used in 125 * This returns the mostly constant string used in
127 * [generateIndividualMessageFile] for the beginning of the file, 126 * [generateIndividualMessageFile] for the beginning of the file,
128 * parameterized by [locale]. 127 * parameterized by [locale].
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // return lib == null ? new Future.value(false) : lib.load(); 222 // return lib == null ? new Future.value(false) : lib.load();
224 return new Future.value(true); 223 return new Future.value(true);
225 } 224 }
226 225
227 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { 226 MessageLookupByLibrary _findGeneratedMessagesFor(locale) {
228 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); 227 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null);
229 if (actualLocale == null) return null; 228 if (actualLocale == null) return null;
230 return _findExact(actualLocale); 229 return _findExact(actualLocale);
231 } 230 }
232 """; 231 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698