Make deferred loading of message libraries optional

BUG=
R=efortuna@google.com

Review URL: https://codereview.chromium.org//414093003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@38553 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
alanknight@google.com 2014-07-24 21:16:49 +00:00
parent d76eccb931
commit a02aa0e2c7
7 changed files with 48 additions and 8 deletions

View file

@ -1,3 +1,8 @@
## 0.11.3
* Add a --[no]-use-deferred-loading flag to generate_from_arb.dart and
generally make the deferred loading of message libraries optional.
## 0.11.2
* Missed canonicalization of locales in one place in message library generation.

View file

@ -40,11 +40,14 @@ main(List<String> args) {
callback: (x) => targetDir = x);
parser.addOption("generated-file-prefix", defaultsTo: '',
callback: (x) => generatedFilePrefix = x);
parser.addFlag("use-deferred-loading", defaultsTo: true,
callback: (x) => useDeferredLoading = x);
parser.parse(args);
var dartFiles = args.where((x) => x.endsWith("dart")).toList();
var jsonFiles = args.where((x) => x.endsWith(".arb")).toList();
if (dartFiles.length == 0 || jsonFiles.length == 0) {
print('Usage: generate_from_arb [--output-dir=<dir>]'
' [--[no-]use-deferred-loading]'
' [--generated-file-prefix=<prefix>] file1.dart file2.dart ...'
' translation1_<languageTag>.arb translation2.arb ...');
exit(0);

View file

@ -52,6 +52,11 @@ List<String> allLocales = [];
*/
String generatedFilePrefix = '';
/**
* Should we use deferred loading for the generated libraries.
*/
bool useDeferredLoading = true;
/**
* This represents a message and its translation. We assume that the translation
* has some identifier that allows us to figure out the original message it
@ -179,13 +184,18 @@ String generateMainImportFile() {
for (var locale in allLocales) {
var baseFile = '${generatedFilePrefix}messages_$locale.dart';
var file = importForGeneratedFile(baseFile);
output.write("import '$file' deferred as ${_libraryName(locale)};\n");
output.write("import '$file' ");
if (useDeferredLoading) output.write("deferred ");
output.write("as ${_libraryName(locale)};\n");
}
output.write("\n");
output.write("\nMap<String, Function> _deferredLibraries = {\n");
for (var rawLocale in allLocales) {
var locale = Intl.canonicalizedLocale(rawLocale);
output.write(" '$locale' : () => ${_libraryName(locale)}.loadLibrary(),\n");
var loadOperation = (useDeferredLoading)
? " '$locale' : () => ${_libraryName(locale)}.loadLibrary(),\n"
: " '$locale' : () => new Future.value(null),\n";
output.write(loadOperation);
}
output.write("};\n");
output.write(

View file

@ -1,5 +1,5 @@
name: intl
version: 0.11.2
version: 0.11.3
author: Dart Team <misc@dartlang.org>
description: Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization issues.
homepage: http://www.dartlang.org

View file

@ -0,0 +1,16 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/**
* A test for message extraction and code generation not using deferred
* loading for the generated code.
*/
library message_extraction_no_deferred_test;
import 'message_extraction_test.dart' as mainTest;
main(arguments) {
mainTest.useDeferredLoading = false;
mainTest.main(arguments);
}

View file

@ -13,6 +13,13 @@ import '../data_directory.dart';
final dart = Platform.executable;
/** Should we use deferred loading. */
bool useDeferredLoading = true;
String get _deferredLoadPrefix => useDeferredLoading ? '' : 'no-';
String get deferredLoadArg => '--${_deferredLoadPrefix}use-deferred-loading';
/** The VM arguments we were given, most important package-root. */
final vmArgs = Platform.executableArguments;
@ -145,9 +152,9 @@ Future<ProcessResult> generateTranslationFiles(ProcessResult previousResult) =>
Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult)
=> run(previousResult, [asTestDirPath('../../bin/generate_from_arb.dart'),
'--generated-file-prefix=foo_', 'sample_with_messages.dart',
'part_of_sample_with_messages.dart', 'translation_fr.arb',
'translation_de_DE.arb']);
deferredLoadArg, '--generated-file-prefix=foo_',
'sample_with_messages.dart', 'part_of_sample_with_messages.dart',
'translation_fr.arb', 'translation_de_DE.arb']);
Future<ProcessResult> runAndVerify(ProcessResult previousResult) => run(
previousResult, [asTempDirPath('run_and_verify.dart')]);

View file

@ -227,8 +227,7 @@ main() {
// Verify that a translated message isn't initially present.
var messageInGerman = Intl.withLocale('de_DE', message1);
test("Locales don't work before they're initialized", ()
=> expect(messageInGerman, "This is a message"));
expect(messageInGerman, "This is a message");
var f1 = initializeMessages(fr.locale)
// Since English has the one message which is always translated, we