| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 /** | 172 /** |
| 173 * This section generates the messages_all.dart file based on the list of | 173 * This section generates the messages_all.dart file based on the list of |
| 174 * [allLocales]. | 174 * [allLocales]. |
| 175 */ | 175 */ |
| 176 String generateMainImportFile() { | 176 String generateMainImportFile() { |
| 177 var output = new StringBuffer(); | 177 var output = new StringBuffer(); |
| 178 output.write(mainPrologue); | 178 output.write(mainPrologue); |
| 179 for (var locale in allLocales) { | 179 for (var locale in allLocales) { |
| 180 var baseFile = '${generatedFilePrefix}messages_$locale.dart'; | 180 var baseFile = '${generatedFilePrefix}messages_$locale.dart'; |
| 181 var file = importForGeneratedFile(baseFile); | 181 var file = importForGeneratedFile(baseFile); |
| 182 // TODO(alanknight): Restore this once deferred loading works in dartj2s. | 182 output.write("import '$file' deferred as ${_libraryName(locale)};\n"); |
| 183 // Issue 12824 | |
| 184 // output.write("@${_deferredName(locale)}\n"); | |
| 185 output.write("import '$file' as ${_libraryName(locale)};\n"); | |
| 186 } | 183 } |
| 187 output.write("\n"); | 184 output.write("\n"); |
| 188 // Issue 12824 | 185 output.write("\nMap<String, Function> _deferredLibraries = {\n"); |
| 189 //for (var locale in allLocales) { | 186 for (var locale in allLocales) { |
| 190 // output.write("const ${_deferredName(locale)} = const DeferredLibrary"); | 187 output.write(" '$locale' : () => ${_libraryName(locale)}.loadLibrary(),\n")
; |
| 191 // output.write("('${_libraryName(locale)}');\n"); | 188 } |
| 192 //} | 189 output.write("};\n"); |
| 193 //output.write("\nconst deferredLibraries = const {\n"); | |
| 194 //for (var locale in allLocales) { | |
| 195 // output.write(" '$locale' : ${_deferredName(locale)},\n"); | |
| 196 //} | |
| 197 //output.write("};\n"); | |
| 198 output.write( | 190 output.write( |
| 199 "\nMessageLookupByLibrary _findExact(localeName) {\n" | 191 "\nMessageLookupByLibrary _findExact(localeName) {\n" |
| 200 " switch (localeName) {\n"); | 192 " switch (localeName) {\n"); |
| 201 for (var rawLocale in allLocales) { | 193 for (var rawLocale in allLocales) { |
| 202 var locale = Intl.canonicalizedLocale(rawLocale); | 194 var locale = Intl.canonicalizedLocale(rawLocale); |
| 203 output.write( | 195 output.write( |
| 204 " case '$locale' : return ${_libraryName(locale)}.messages;\n"); | 196 " case '$locale' : return ${_libraryName(locale)}.messages;\n"); |
| 205 } | 197 } |
| 206 output.write(closing); | 198 output.write(closing); |
| 207 return output.toString(); | 199 return output.toString(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 231 * Constant string used in [generateMainImportFile] as the end of the file. | 223 * Constant string used in [generateMainImportFile] as the end of the file. |
| 232 */ | 224 */ |
| 233 const closing = """ | 225 const closing = """ |
| 234 default: return null; | 226 default: return null; |
| 235 } | 227 } |
| 236 } | 228 } |
| 237 | 229 |
| 238 /** User programs should call this before using [localeName] for messages.*/ | 230 /** User programs should call this before using [localeName] for messages.*/ |
| 239 Future initializeMessages(String localeName) { | 231 Future initializeMessages(String localeName) { |
| 240 initializeInternalMessageLookup(() => new CompositeMessageLookup()); | 232 initializeInternalMessageLookup(() => new CompositeMessageLookup()); |
| 241 messageLookup.addLocale(localeName, _findGeneratedMessagesFor); | 233 var lib = _deferredLibraries[Intl.canonicalizedLocale(localeName)]; |
| 242 // TODO(alanknight): Restore once Issue 12824 is fixed. | 234 var load = lib == null ? new Future.value(false) : lib(); |
| 243 // var lib = deferredLibraries[localeName]; | 235 return load.then((_) => |
| 244 // return lib == null ? new Future.value(false) : lib.load(); | 236 messageLookup.addLocale(localeName, _findGeneratedMessagesFor)); |
| 245 return new Future.value(true); | |
| 246 } | 237 } |
| 247 | 238 |
| 248 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { | 239 MessageLookupByLibrary _findGeneratedMessagesFor(locale) { |
| 249 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null, | 240 var actualLocale = Intl.verifiedLocale(locale, (x) => _findExact(x) != null, |
| 250 onFailure: (_) => null); | 241 onFailure: (_) => null); |
| 251 if (actualLocale == null) return null; | 242 if (actualLocale == null) return null; |
| 252 return _findExact(actualLocale); | 243 return _findExact(actualLocale); |
| 253 } | 244 } |
| 254 """; | 245 """; |
| OLD | NEW |