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

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

Issue 17113002: Allow translated messages that have no matching original message (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix a typo in help text Created 7 years, 6 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 /** 80 /**
81 * Generate a file messages_<locale>.dart for the [translations] in 81 * Generate a file messages_<locale>.dart for the [translations] in
82 * [locale]. 82 * [locale].
83 */ 83 */
84 void generateIndividualMessageFile(String locale, 84 void generateIndividualMessageFile(String locale,
85 Iterable<TranslatedMessage> translations, String targetDir) { 85 Iterable<TranslatedMessage> translations, String targetDir) {
86 var result = new StringBuffer(); 86 var result = new StringBuffer();
87 locale = new IntlMessage().escapeAndValidate(locale, locale); 87 locale = new IntlMessage().escapeAndValidate(locale, locale);
88 result.write(prologue(locale)); 88 result.write(prologue(locale));
89 for (var each in translations) { 89 // Exclude messages with no translation and translations with no matching
90 var message = each.originalMessage; 90 // original message (e.g. if we're using some messages from a larger catalog)
91 if (each.message != null) { 91 var usableTranslations = translations.where(
92 message.addTranslation(locale, each.message); 92 (each) => each.originalMessage != null && each.message != null).toList();
93 } 93 for (var each in usableTranslations) {
94 each.originalMessage.addTranslation(locale, each.message);
94 } 95 }
95 var sorted = translations.where((each) => each.message != null).toList(); 96 usableTranslations.sort((a, b) =>
96 sorted.sort((a, b) =>
97 a.originalMessage.name.compareTo(b.originalMessage.name)); 97 a.originalMessage.name.compareTo(b.originalMessage.name));
98 for (var each in sorted) { 98 for (var each in usableTranslations) {
99 result.write(" "); 99 result.write(" ");
100 result.write(each.originalMessage.toCode(locale)); 100 result.write(each.originalMessage.toCode(locale));
101 result.write("\n\n"); 101 result.write("\n\n");
102 } 102 }
103 result.write("\n final messages = const {\n"); 103 result.write("\n final messages = const {\n");
104 var entries = sorted 104 var entries = usableTranslations
105 .map((translation) => translation.originalMessage.name) 105 .map((translation) => translation.originalMessage.name)
106 .map((name) => " \"$name\" : $name"); 106 .map((name) => " \"$name\" : $name");
107 result.write(entries.join(",\n")); 107 result.write(entries.join(",\n"));
108 result.write("\n };\n}"); 108 result.write("\n };\n}");
109 109
110 var output = new File(path.join(targetDir, 110 var output = new File(path.join(targetDir,
111 "${generatedFilePrefix}messages_$locale.dart")); 111 "${generatedFilePrefix}messages_$locale.dart"));
112 output.writeAsStringSync(result.toString()); 112 output.writeAsStringSync(result.toString());
113 } 113 }
114 114
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 messageLookup.addLocale(localeName, _findGeneratedMessagesFor); 193 messageLookup.addLocale(localeName, _findGeneratedMessagesFor);
194 return new Future.value(); 194 return new Future.value();
195 } 195 }
196 196
197 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { 197 MessageLookupByLibrary _findGeneratedMessagesFor(locale) {
198 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); 198 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null);
199 if (actualLocale == null) return null; 199 if (actualLocale == null) return null;
200 return _findExact(actualLocale); 200 return _findExact(actualLocale);
201 } 201 }
202 """; 202 """;
OLDNEW
« no previous file with comments | « pkg/intl/lib/extract_messages.dart ('k') | pkg/intl/test/message_extraction/extract_to_json.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698