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

Unified Diff: pkg/intl/lib/generate_localized.dart

Issue 12478010: Parameterize the import directories, fix test to behave correctly on an error (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: pkg/intl/lib/generate_localized.dart
diff --git a/pkg/intl/lib/generate_localized.dart b/pkg/intl/lib/generate_localized.dart
index 84ba5c9d944dcdddcf3e9081458c0d6c1b7ad4f4..0961d38151fa67ebec71b6a2fd9bc770105a95a7 100644
--- a/pkg/intl/lib/generate_localized.dart
+++ b/pkg/intl/lib/generate_localized.dart
@@ -19,6 +19,28 @@ import 'dart:io';
import 'package:pathos/path.dart' as path;
/**
+ * If the import path following package: is something else, modify the
+ * [intlImportPath] variable to change the import directives in the generated
+ * code.
+ */
+var intlImportPath = 'intl';
+
+/**
+ * If the path to the generated files is something other than the current
+ * directory, update the [generatedImportPath] variable to change the import
+ * directives in the generated code.
+ */
+var generatedImportPath = '';
+
+/**
+ * Given a base file, return the file prefixed with the path to import it.
+ * By default, that is in the current directory, but if [generatedImportPath]
+ * has been set, then use that as a prefix.
+ */
+String importForGeneratedFile(String file) =>
+ generatedImportPath.isEmpty ? file : "$generatedImportPath/$file";
+
+/**
* A list of all the locales for which we have translations. Code that does
* the reading of translations should add to this.
*/
@@ -96,8 +118,8 @@ String prologue(String locale) => """
*/
library messages_${locale.replaceAll('-','_')};
-import 'package:intl/intl.dart';
-import 'package:intl/message_lookup_by_library.dart';
+import 'package:$intlImportPath/intl.dart';
+import 'package:$intlImportPath/message_lookup_by_library.dart';
final messages = new MessageLookup();
@@ -114,7 +136,9 @@ String generateMainImportFile() {
var output = new StringBuffer();
output.write(mainPrologue);
for (var each in allLocales) {
- output.write("import 'messages_$each.dart' as ${asLibraryName(each)};\n");
+ var baseFile = 'messages_$each.dart';
+ var file = importForGeneratedFile(baseFile);
+ output.write("import '$file' as ${asLibraryName(each)};\n");
}
output.write(
"\nMessageLookupByLibrary _findExact(localeName) {\n"
@@ -131,7 +155,7 @@ String generateMainImportFile() {
* Constant string used in [generateMainImportFile] for the beginning of the
* file.
*/
-const mainPrologue = """
+var mainPrologue = """
/**
* DO NOT EDIT. This is code generated via pkg/intl/generate_localized.dart
* This is a library that looks up messages for specific locales by
@@ -141,9 +165,9 @@ const mainPrologue = """
library messages_all;
import 'dart:async';
-import 'package:intl/message_lookup_by_library.dart';
-import 'package:intl/src/intl_helpers.dart';
-import 'package:intl/intl.dart';
+import 'package:$intlImportPath/message_lookup_by_library.dart';
+import 'package:$intlImportPath/src/intl_helpers.dart';
+import 'package:$intlImportPath/intl.dart';
""";

Powered by Google App Engine
This is Rietveld 408576698