| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 output.write(mainPrologue); | 158 output.write(mainPrologue); |
| 159 for (var locale in allLocales) { | 159 for (var locale in allLocales) { |
| 160 var baseFile = '${generatedFilePrefix}messages_$locale.dart'; | 160 var baseFile = '${generatedFilePrefix}messages_$locale.dart'; |
| 161 var file = importForGeneratedFile(baseFile); | 161 var file = importForGeneratedFile(baseFile); |
| 162 // TODO(alanknight): Restore this once deferred loading works in dartj2s. | 162 // TODO(alanknight): Restore this once deferred loading works in dartj2s. |
| 163 // Issue 12824 | 163 // Issue 12824 |
| 164 // output.write("@${_deferredName(locale)}\n"); | 164 // output.write("@${_deferredName(locale)}\n"); |
| 165 output.write("import '$file' as ${_libraryName(locale)};\n"); | 165 output.write("import '$file' as ${_libraryName(locale)};\n"); |
| 166 } | 166 } |
| 167 output.write("\n"); | 167 output.write("\n"); |
| 168 for (var locale in allLocales) { | 168 // Issue 12824 |
| 169 output.write("const ${_deferredName(locale)} = const DeferredLibrary"); | 169 //for (var locale in allLocales) { |
| 170 output.write("('${_libraryName(locale)}');\n"); | 170 // output.write("const ${_deferredName(locale)} = const DeferredLibrary"); |
| 171 } | 171 // output.write("('${_libraryName(locale)}');\n"); |
| 172 output.write("\nconst deferredLibraries = const {\n"); | 172 //} |
| 173 for (var locale in allLocales) { | 173 //output.write("\nconst deferredLibraries = const {\n"); |
| 174 output.write(" '$locale' : ${_deferredName(locale)},\n"); | 174 //for (var locale in allLocales) { |
| 175 } | 175 // output.write(" '$locale' : ${_deferredName(locale)},\n"); |
| 176 output.write("};\n"); | 176 //} |
| 177 //output.write("};\n"); |
| 177 output.write( | 178 output.write( |
| 178 "\nMessageLookupByLibrary _findExact(localeName) {\n" | 179 "\nMessageLookupByLibrary _findExact(localeName) {\n" |
| 179 " switch (localeName) {\n"); | 180 " switch (localeName) {\n"); |
| 180 for (var locale in allLocales) { | 181 for (var locale in allLocales) { |
| 181 output.write( | 182 output.write( |
| 182 " case '$locale' : return ${_libraryName(locale)}.messages;\n"); | 183 " case '$locale' : return ${_libraryName(locale)}.messages;\n"); |
| 183 } | 184 } |
| 184 output.write(closing); | 185 output.write(closing); |
| 185 return output.toString(); | 186 return output.toString(); |
| 186 } | 187 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 210 */ | 211 */ |
| 211 const closing = """ | 212 const closing = """ |
| 212 default: return null; | 213 default: return null; |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 /** User programs should call this before using [localeName] for messages.*/ | 217 /** User programs should call this before using [localeName] for messages.*/ |
| 217 Future initializeMessages(String localeName) { | 218 Future initializeMessages(String localeName) { |
| 218 initializeInternalMessageLookup(() => new CompositeMessageLookup()); | 219 initializeInternalMessageLookup(() => new CompositeMessageLookup()); |
| 219 messageLookup.addLocale(localeName, _findGeneratedMessagesFor); | 220 messageLookup.addLocale(localeName, _findGeneratedMessagesFor); |
| 220 var lib = deferredLibraries[localeName]; | 221 // TODO(alanknight): Restore once Issue 12824 is fixed. |
| 221 // TODO(alanknight): Restore once Issue 12824 is fixed.
| 222 // var lib = deferredLibraries[localeName]; |
| 222 // return lib == null ? new Future.value(false) : lib.load(); | 223 // return lib == null ? new Future.value(false) : lib.load(); |
| 223 return new Future.value(true); | 224 return new Future.value(true); |
| 224 } | 225 } |
| 225 | 226 |
| 226 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { | 227 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { |
| 227 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); | 228 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null); |
| 228 if (actualLocale == null) return null; | 229 if (actualLocale == null) return null; |
| 229 return _findExact(actualLocale); | 230 return _findExact(actualLocale); |
| 230 } | 231 } |
| 231 """; | 232 """; |
| OLD | NEW |